@@ -46,14 +46,14 @@ class OrderHelper
4646 public function __construct (
4747 ModelManager $ modelManager ,
4848 DocumentHelper $ documentHelper ,
49- Logger $ logger ,
5049 ConfigService $ configService ,
5150 CartHelper $ cartHelper ,
5251 CustomerHelper $ customerHelper
5352 ) {
5453 $ this ->modelManager = $ modelManager ;
5554 $ this ->documentHelper = $ documentHelper ;
56- $ this ->logger = $ logger ;
55+
56+ $ this ->logger = Shopware ()->Container ()->get ('mond1_s_w_r5.logger ' );
5757 $ this ->configService = $ configService ;
5858 $ this ->cartHelper = $ cartHelper ;
5959 $ this ->customerHelper = $ customerHelper ;
@@ -163,13 +163,13 @@ public function updateOrder($order) {
163163 return $ newOrder ;
164164 }
165165
166- public function updateExternalInfoOrder ($ order ) {
166+ public function updateExternalInfoOrder ($ order, $ orderNumber = '' ) {
167167 /**
168168 * @var MonduClient
169169 */
170170 $ client = Shopware ()->Container ()->get (MonduClient::class);
171171 $ updateOrderData = [
172- 'external_reference_id ' => $ order ->getNumber ()
172+ 'external_reference_id ' => $ orderNumber ?: $ order ->getNumber ()
173173 ];
174174
175175 return $ client ->updateExternalInfoOrder ($ order ->getTransactionId (), $ updateOrderData );
@@ -179,7 +179,6 @@ public function getOrderFromOrderVariables($orderVariables) {
179179 $ userData = $ orderVariables ['sUserData ' ];
180180 $ basket = $ orderVariables ['sBasket ' ];
181181 $ content = $ basket ['content ' ];
182-
183182 $ totalAmount = $ this ->cartHelper ->getTotalAmount ($ orderVariables ['sBasket ' ], $ orderVariables ['sUserData ' ]);
184183 $ shippingAmount = $ this ->cartHelper ->getShippingAmount ($ orderVariables ['sBasket ' ], $ orderVariables ['sUserData ' ]);
185184 $ chargeVat = $ this ->customerHelper ->chargeVat ($ orderVariables ['sUserData ' ]);
@@ -211,7 +210,9 @@ public function getOrderAdjustment($order) {
211210 if ($ detail ->getPrice () > 0 ) {
212211 $ lineitems = $ this ->getLineItemsFromDetail ($ detail , $ order , $ lineitems );
213212 } else {
214- [$ total , $ net ] = $ this ->getAmountsFromDetail ($ detail , $ detail ->getQuantity (), $ order ->getNet ());
213+ $ amounts = $ this ->getAmountsFromDetail ($ detail , $ detail ->getQuantity (), $ order ->getNet ());
214+ $ total = $ amounts [0 ];
215+ $ net = $ amounts [1 ];
215216 $ totalDiscount += round (abs ($ net ) * 100 );
216217 $ totalDiscountGross += round (abs ($ total ) * 100 );
217218 }
@@ -249,7 +250,8 @@ public function getLineItems($content, $chargeVat): array
249250 {
250251 $ lineItems = [];
251252 foreach ($ content as $ item ) {
252- if ($ item ['amountNumeric ' ] <= 0 ) {
253+ $ amountNumeric = (float ) $ item ['price ' ];
254+ if ($ amountNumeric <= 0 ) {
253255 continue ;
254256 }
255257
@@ -261,23 +263,25 @@ public function getLineItems($content, $chargeVat): array
261263 public function getTotalDiscount ($ content , $ chargeVat ) {
262264 $ discount = 0 ;
263265 foreach ($ content as $ item ) {
264- if ($ item ['amountNumeric ' ] > 0 ) {
266+ $ amountNumeric = (float ) $ item ['priceNumeric ' ];
267+ if ($ amountNumeric > 0 ) {
265268 continue ;
266269 }
270+
267271 if ($ chargeVat ) {
268- $ amountNumeric = abs ($ item [ ' amountWithTax ' ] ?? $ item [ ' amountNumeric ' ] );
272+ $ amountNumeric = abs ($ amountNumeric );
269273 } else {
270- $ amountNumeric = abs ($ item ['amountnetNumeric ' ]);
274+ $ amountNumeric = abs (( float ) $ item ['netprice ' ]);
271275 }
272276 $ discount += round ($ amountNumeric * 100 );
273277 }
274278 return $ discount ;
275279 }
276280
277281 public function getLineItem ($ item , $ chargeVat ) {
278- $ itemAmountNet = $ item ['netprice ' ];
279- $ totalAmountNet = $ item ['amountnetNumeric ' ] ;
280- $ taxAmount = str_replace (', ' , '. ' , $ item ['tax ' ]);
282+ $ itemAmountNet = ( float ) $ item ['netprice ' ];
283+ $ totalAmountNet = ( float ) str_replace ( ' , ' , ' . ' , $ item ['amountnet ' ]) ;
284+ $ taxAmount = ( float ) str_replace (', ' , '. ' , $ item ['tax ' ]);
281285
282286 return [
283287 'external_reference_id ' => $ item ['ordernumber ' ],
@@ -407,7 +411,7 @@ private function getAmountsFromDetail($detail, $quantity, $net) {
407411 }
408412
409413 if ($ net ) {
410- $ amountGross = Shopware ()-> Container ()-> get ( ' shopware.cart.net_rounding ' ) ->round ($ price , $ taxValue , $ quantity );
414+ $ amountGross = $ this ->round ($ price , $ taxValue , $ quantity );
411415 return [$ amountGross , $ amount ];
412416 } else {
413417 $ amountNet = round (($ price * $ quantity ) / (100 + $ taxValue ) * 100 , 2 );
@@ -423,8 +427,13 @@ private function getAmountsFromDetail($detail, $quantity, $net) {
423427 */
424428 private function getLineItemsFromDetail ($ detail , $ order , array $ lineItems ): array
425429 {
426- [$ totalAmount , $ totalAmountNet ] = $ this ->getAmountsFromDetail ($ detail , $ detail ->getQuantity (), $ order ->getNet ());
427- [$ itemAmount , $ itemAmountNet ] = $ this ->getAmountsFromDetail ($ detail , 1 , $ order ->getNet ());
430+ $ totalAmounts = $ this ->getAmountsFromDetail ($ detail , $ detail ->getQuantity (), $ order ->getNet ());
431+ $ totalAmount = $ totalAmounts [0 ];
432+ $ totalAmountNet = $ totalAmounts [1 ];
433+
434+ $ itemAmounts = $ this ->getAmountsFromDetail ($ detail , 1 , $ order ->getNet ());
435+ $ itemAmount = $ itemAmounts [0 ];
436+ $ itemAmountNet = $ itemAmounts [1 ];
428437 $ chargeVat = !$ order ->getTaxFree ();
429438 $ lineItems [] = [
430439 'external_reference_id ' => $ detail ->getArticleNumber (),
@@ -470,4 +479,16 @@ private function removeDuplicateSwReferenceIds(array $lineItems): array
470479 }
471480 return $ newLineItems ;
472481 }
482+
483+ private function round (float $ netPrice , float $ tax , int $ quantity = null ): float
484+ {
485+ if ($ quantity === 0 ) {
486+ return 0.0 ;
487+ }
488+
489+ $ netPrice = round (round ($ netPrice , 2 ) / 100 * (100 + $ tax ), 2 );
490+ $ netPrice = (\is_int ($ quantity ) && $ quantity !== 1 ) ? round ($ netPrice * $ quantity , 2 ) : $ netPrice ;
491+
492+ return $ netPrice ;
493+ }
473494}
0 commit comments