magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.54k stars 9.32k forks source link

Customizable Options in Cart Incorrectly Update All Instances of a Product #39114

Open Hurrpadurr opened 2 months ago

Hurrpadurr commented 2 months ago

Preconditions and environment

2.4.7-p2

Steps to reproduce

  1. Create a simple product with at least 2 customizable options (both as dropdowns).
  2. Add the product to the cart with the following selections:
    • Dropdown 1: Value A
    • Dropdown 2: Value C
  3. Add the same product to the cart again but with different selections:
    • Dropdown 1: Value B
    • Dropdown 2: Value D

Note that both products are correctly added as separate items in the cart.

  1. Go to the cart view.
  2. Edit the customizable options of one of the products in the cart.

Expected result

Only the selected product in the cart should update its customizable options according to the changes made.

Actual result

Both products in the cart are updated to reflect the same customizable options as the product being edited, regardless of their previous settings.

Additional information

A workaround is to remove the affected product and re-add it with the correct options, but this is not an ideal solution.

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 months ago

Hi @Hurrpadurr. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

m2-assistant[bot] commented 2 months ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 2 months ago

Hi @Hurrpadurr,

Thanks for your reporting and collaboration.

We have verified the issue in Latest 2.4-develop instance and the issue is reproducible.Kindly refer the attached video.

https://github.com/user-attachments/assets/38cdb4d4-5b48-4140-91ad-a529bbdbb191

Both products in the cart are updated to reflect the same customizable options as the product being edited, regardless of their previous settings.

Hence Confirming the issue.

Thanks.

github-jira-sync-bot commented 2 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12846 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 months ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

Silarn commented 1 month ago

From what I can tell, the \Magento\Quote\Model\Quote\Item\Compare::compare() function was modified to add a SKU check to the beginning of the function.

        if ($target->getSku() !== null && $target->getSku() === $compared->getSku()) {
            return true;
        }

This causes the function to return before the checks for custom options and such which should differentiate the quote items and not simply merge them.

I have no idea what this check was added to solve, but I'm going to test simply removing it in an override.

Silarn commented 1 month ago

I think the only situation I could see the above code being necessary is if somehow products sharing a SKU from different storefronts were added to the cart such that they would have different product IDs. I'm not sure what scenario would result in this.

I guess if you reworked it to run the compareOptions() checks IF the product IDs are identical. Then do the SKU check. But even in that case I think you'd want to check the custom options and not necessarily just merge the same-sku-different-id product. I think you'd only want to do that if the product(s) in question had no custom options.

As far as I know it shouldn't be possible for multiple products in one storefront to have the same SKU though, so this check does still seem unnecessary. Maybe I'm wrong.