mollie / magento2

Mollie Payments for Magento 2
https://www.mollie.com
Other
101 stars 52 forks source link

Can't create partial shipment #563

Closed Quazz closed 1 year ago

Quazz commented 1 year ago

Describe the bug When trying to create a partial shipment you are returned to "Source selection" page for shipment.

Used versions

To Reproduce Steps to reproduce the behavior: When Mollie Order API is used for payment methods and multiple items are ordered each of which has their own sources related to them, it is impossible to create a partial shipment for them.

edit: Now that I'm fairly certain I found the cause, I should clarify it only happens if additional Mollie Order Lines are generated in the table, still don't know why or how this happens, but the error won't happen without it.

Example: item1 - sources: source1, source2 item2 - sources: source4

Partial shipments must be created in order to close the order, but it brings you back to source selection instead.

So steps:

  1. Set payment method to Mollie Order API
  2. Assign a source to a product
  3. Assign a different source to a different product
  4. Create an order with both products that share no sources
  5. Wait 1h+ and verify additional lines are generated without line_id in mollie_order_lines
  6. Try to create a shipment for the order

Expected behavior The shipment is created successfully

Actual behavior You are brought back to the source selection. After some debugging by logging exceptions, the exception logged is: Mollie API: [2022-09-27T11:22:38+0000] Error executing API call (422: Unprocessable Entity): Line 0 contains invalid data. The 'id' field is missing. Field: lines.0.id. Documentation: https://docs.mollie.com/overview/handling-errors

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

Quazz commented 1 year ago

It looks the problem is caused because of line_id not having NULL as default value (or otherwise the filter not accounting for empty string)

https://github.com/mollie/magento2/blob/b0481ce0e68b6f5954f4c53fd5d9a9ccf7a2e5bc/Model/OrderLines.php#L260

Relevant method.

https://github.com/mollie/magento2/blob/b0481ce0e68b6f5954f4c53fd5d9a9ccf7a2e5bc/etc/db_schema.xml#L11

line_id is not allowed to be NULL as per the db_schema. Therefore the best fix would be to change the filter in order item retrieval.

In addition to following method also needs to filter out empty line_id items (and all other methods similar to this one I guess)

https://github.com/mollie/magento2/blob/b0481ce0e68b6f5954f4c53fd5d9a9ccf7a2e5bc/Model/OrderLines.php#L240

Quazz commented 1 year ago

Secondary question would be why near duplicate lines get added to the table? (only difference being no line_id and qty_paid 0 instead of 1)

They get added AFTER the order already exists and is paid for; but I don't know why or how.

Frank-Magmodules commented 1 year ago

Hello @Quazz,

Thank you for opening this issue and for the additional comments. We’ve checked this but it seems to be working fine on a plain Magento 2.4.5 install with only Mollie installed. Could it be that you have some modules installed that invoke the creation of the shipment that collides? 

Especially step 5 is something we don’t recognize: As soon as the Mollie webhook marks the order as paid all order lines should be present. Next to that, a line_id with a value of NULL is something that shouldn’t happen in a regular installation.

Quazz commented 1 year ago

Hello @Quazz,

Thank you for opening this issue and for the additional comments. We’ve checked this but it seems to be working fine on a plain Magento 2.4.5 install with only Mollie installed. Could it be that you have some modules installed that invoke the creation of the shipment that collides? 

Especially step 5 is something we don’t recognize: As soon as the Mollie webhook marks the order as paid all order lines should be present. Next to that, a line_id with a value of NULL is something that shouldn’t happen in a regular installation.

The correct lines are correctly generated.

I have found the problem in the mean time, 3rd party extension that's calling https://github.com/mollie/magento2/blob/master/Service/Order/Lines/Order.php#L87

Not Mollie's fault, closing.