Skip to content

Incorrect quote_item_id saved on order items during multiple address checkout #18349

Closed
@zaximus84

Description

@zaximus84

Preconditions

  1. Magento 2.2.6
  2. Multiple address checkout enabled
  3. quote_item.item_id and quote_address_item.address_item_id auto increments are different. (If they are the same, the values are correct on order placement due to sheer luck)

Steps to reproduce

  1. Add an item to cart, log in (or create an account), and proceed to multiple address checkout.
  2. Complete all steps of checkout and place order

Expected result

  1. All resulting order_item records in the database have a quote_item_id value that matches the item_id value of the original quote_item record. In other words, the order_item should point at the quote_item.

Actual result

  1. All resulting order_item records in the database have a quote_item_id value that matches the address_item_id value of the original quote_address_item record. In other words, the order item points at the quote_address_item instead of the quote_item.

Additional Information

Magento\Multishipping\Model\Checkout\Type\Multishipping::_prepareOrder calls \Magento\Quote\Model\Quote\Item\ToOrderItem::convert for each quote address item. The convert method relies on mapping from fieldset.xml to determine which values to copy from the quote item. This is the relevant id field:

<fieldset id="quote_convert_item"> ... <field name="id"> <aspect name="to_order_item" targetField="quote_item_id" /> </field>

Because the field name is "id", the object copy service (utilized in the convert method) calls getId() on $item. This is fine during a regular checkout when $item is an instance of quote item, but it's a problem during multiple address checkout when $item is an instance of quote address item. In that case, it returns the primary key from the quote_address_item table instead of the quote_item table, and ultimately produces an order item where quote_item_id points at the quote address item id. That will mean one of the following:

  1. The referenced quote_item record will be from an unrelated quote.
  2. The referenced quote_item record will not exist.
  3. The referenced quote_item record will be correct by sheer luck because the quote_item and quote_item_address auto increments happened to be the same during the checkout process. This is unlikely with anything other than a fresh Magento installation.

The solution would be to handle quote address item instances differently and ensure that the quote_address_item.quote_item_id is mapped to sales_order_item.quote_item_id.

Metadata

Metadata

Assignees

Labels

Component: SalesIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions