mollie / Shopware6

MIT License
51 stars 53 forks source link

Critical Bug: Static quantity in buildShippingLineItems #553

Closed davidlange closed 1 year ago

davidlange commented 1 year ago

Hi

Currently, all orders are rejected if a shipping method is charged more than once. Here is an example: Bildschirmfoto 2023-03-30 um 10 38 22 --> 2x Zuschlag (1x = 2,50€)

We noticed that in the function "buildShippingLineItems" a static 1 is given. If e.g. 2x 2.50 € comes from Shopware, the Mollie API expects 2.50€, but gets a total of 5.00€ and runs into an error: https://github.com/mollie/Shopware6/blob/master/src/Service/MollieApi/Builder/MollieShippingLineItemBuilder.php

  $mollieLineItem = new MollieLineItem(
          OrderLineType::TYPE_SHIPPING_FEE,
          sprintf('Delivery costs %s', $i),
          1,
          $price,
          $delivery->getId(),
          sprintf('mol-delivery-%s', $i),
          '',
          ''
      );

This should be fixed as soon as possible. It's really critical. We have a lot of cancellations and the customer cannot order with any Mollie payment method.

We are losing a lot of big orders here right now.

I would appreciate a quick feedback!

davidlange commented 1 year ago

Here some error logs:

[2023-03-30T03:17:38.698283+00:00] Mollie.ERROR: Error when starting Mollie payment: Could not create Mollie order (Session: ...) {"function":"order-prepare","exception":"[object] (RuntimeException(code: 422): Could not create Mollie order at ..../vendor/store.shopware.com/molliepayments/src/Service/MollieApi/Order.php:176)\n[previous exception] [object] (Mollie\Api\Exceptions\ApiException(code: 422): [2023-03-30T03:17:38+0000] Error executing API call (422: Unprocessable Entity): Order line 3 is invalid. Total amount is off. Expected total amount to be €1.00 (1 × €1.00), got €3.00. Documentation: https://docs.mollie.com/overview/handling-errors. Field: lines.3.totalAmount at .../vendor/store.shopware.com/molliepayments/src/Service/MollieApi/Client/MollieHttpClient.php:150)","

[2023-03-30T05:04:51.641672+00:00] Mollie.CRITICAL: Could not create Mollie order (Session: ...) {"function":"finalize-payment","exception":"[object] (Mollie\Api\Exceptions\ApiException(code: 422): [2023-03-30T05:04:51+0000] Error executing API call (422: Unprocessable Entity): Order line 3 is invalid. Total amount is off. Expected total amount to be €2.50 (1 × €2.50), got €5.00. Documentation: https://docs.mollie.com/overview/handling-errors. Field: lines.3.totalAmount at .../vendor/store.shopware.com/molliepayments/src/Service/MollieApi/Client/MollieHttpClient.php:150)","

boxblinkracer commented 1 year ago

Hi

thank you for this Not that familiar with that part of the code but I'll check it out as soon as possible

we are usually pretty fast on fixes, so shouldnt be a big deal :)

thank you for your help

boxblinkracer commented 1 year ago

Hi

I just checked out what is happening, and figured out its no global critical bug (more edge case), but related to your specific use case with additional delivery quantities (so critical for you of course) I would still give you the rest of the budget to provide a fast fix, but to ensure that its really working I would please need your configuration on the shipping setup, thank you

I would appreciate quick feedback to fix this for you, thank you

davidlange commented 1 year ago

Hi @boxblinkracer

Thanks for the quick help! It is an edge case for customers with multiple delivery methods. That's right.

There is no easy setting for this. I can give you access to the client's development environment. I can provide you the data by email. Contact me at: d.lange@one-dot.de

Thanks!

boxblinkracer commented 1 year ago

to everyone who follows this at the moment only a single delivery-position is supported. thats what shopware also does. but the data structure allows it that a single delivery has multiple positions with individual quantity and prices in here. so like multiple deliveries, only an additional level below.

This is not yet supported in the Mollie plugin, and only leads to problems on custom implementations.

We will of course support this with an update :)

JanMue-dot commented 1 year ago

Hi @boxblinkracer ,

i've created an PR for this issue, our solution from earlier today was way overcomplicated. The Shipping Cost of the Delivery Item itself should contain the quantity already for it to work with the Shopware Price calculation.