magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Quote Item - Duplicate sku in same quote

Open vlauria opened this issue 10 years ago • 23 comments

Preconditions (*)

  1. Magento 2.4-develop branch

Steps to reproduce (*)

  1. Create an account on frontend and log in to this account on frontent
  2. Go to category page, click "♥" icon for product1 (just simple product) to add it to wishlist
  3. On the wishlist page click "Add to cart" button on the product (NOTE: use button add to cart for single item. NOT ADD ALL TO CART).
  4. Open developer console and remove "PHPSESSID" cookie (to emulate that session cookie already expired)
  5. Go to the same category as in step 2, add to cart product 1
  6. Click "Log In" and login to the same account as in step 1

Expected result (*)

You should see in cart one product with qty 2: image

Actual result (*)

You see in cart two exactly the same products in cart, each with qty 1: image

Additional info:

@princeantil90 provided video for reproducing this issue https://nimb.ws/wcJX67

vlauria avatar Dec 05 '16 12:12 vlauria

Please provide more concrete steps for reproducing because I got a merged quantity in my cart.

wert2all avatar Dec 13 '16 14:12 wert2all

Precondition: Magento CE 2.1 without sample data is installed. Wishlist is set up

Steps to reproduce: Logged user on frontend. Add one product to wishlist and from wishlist page add to cart. (NOTE: use button add to cart for single item. NOT ADD ALL TO CART). Clear cookie or session id (SO LOGOUT USER ON FRONTENT) after logout go to category page and add same product to cart. Login on frontend.

Expected result: One row in quote_item table with merge quantity Actual result: In quote_item I have two row with same sku.

vlauria avatar Dec 13 '16 17:12 vlauria

Can you upgrade to 2.1.3 and try to reproduce?

wert2all avatar Dec 16 '16 10:12 wert2all

I tested it with 1.2.3 and 1.2.4, it does not work

vlauria avatar Feb 09 '17 08:02 vlauria

Hey guys,

we have this bug in our System (Magento 2.1.2, PHP 7) too. So i tried to figure out why this happens and stepped into the Magento Core.

During \Magento\Quote\Model\Quote->merge() Magento compares the quote items (to merge guest and customer quote) against each other. The comparison between the two items happens on different steps:

  1. Compare ProductIds against each other
  2. Grep the options of each item and make an array_diff_key() against.
  3. Compare every option value against each other.

In this case, the problem comes in step 3, because in here we have the option key "info_buyRequest" with different values. In the item, which was added by wishlist:

$targetOptions['info_buyRequest'] = [
        "item": "someItemId",
        "product": "theproductid",
        "originQty": "someOriginQty" // This is filled in \Magento\Wishlist\Model\Item->getBuyRequest()
];

In the item, which was added by default from category or detail page:

$comparedOptions['info_buyRequest'] = [
        "product": "theproductid"
];

auswahl_021

As you can see, the values differ and added the same quote items twice. As far as i know, these options are for special cases like:

  • Adding a configurable product from wishlist to cart
  • May have a superspecialproduct with super unique options which would

A really crappy solution to this problem is to comment out or remove the 3rd step of the compare function, but I don't know what is going to happen. This is probably a Bug in Magento Wishlist.

ulftietze avatar May 17 '17 12:05 ulftietze

@vlauria, thank you for your report. We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue. We tested the issue on 2.1.9

magento-engcom-team avatar Sep 25 '17 22:09 magento-engcom-team

@vlauria, thank you for your report. We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.

magento-engcom-team avatar Sep 26 '17 22:09 magento-engcom-team

I'm seeing this in 2.1.7.

Jimgitsit avatar Nov 30 '17 16:11 Jimgitsit

@magento-engcom-team : Can we have a commit reference for the fix applied ?

Because on my side, if I add the same product to the cart multiple times in a very short delay, I get 2 same quote item row even if the stock quantity is 1.

Many thanks.

franckgarnier21 avatar Mar 08 '18 07:03 franckgarnier21

I have the same issue.

  • Magento 2.2.5
  • PHP 7.1

In a custom carrier class I am using the getAllItems method from the \Magento\Quote\Model\Quote\Address\RateRequest class and it returns duplicate items in the quote. Both items have the same sku and share almost the same proprieties but only one of them has the correct price info and the other the correct stock information.

This is :100: a bug and the ticked should be reopened and fixed.

Here are some screenshots:

screen shot 2018-07-16 at 5 48 34 p m screen shot 2018-07-16 at 5 46 47 p m screen shot 2018-07-16 at 5 47 00 p m

Update If you look in the Flatrate shipping class (line 108) this code skips the items that don't belong

if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
    continue;
}

I guess this can be used as a fix, but in my opinion items should not be added twice to the quote, the proprieties should be merged and only one should exist.

drew7721 avatar Jul 16 '18 21:07 drew7721

Seems like we have fix for this issue that was closed as can’t reproduce, also I see that there was added additional info that could help reproduce the issue. Reopening this issue for confirmation that it still valid

ihor-sviziev avatar Apr 03 '20 20:04 ihor-sviziev

I have the same issue.

  • Magento 2.2.5
  • PHP 7.1

In a custom carrier class I am using the getAllItems method from the \Magento\Quote\Model\Quote\Address\RateRequest class and it returns duplicate items in the quote. Both items have the same sku and share almost the same proprieties but only one of them has the correct price info and the other the correct stock information.

This is 💯 a bug and the ticked should be reopened and fixed.

Here are some screenshots:

screen shot 2018-07-16 at 5 48 34 p m screen shot 2018-07-16 at 5 46 47 p m screen shot 2018-07-16 at 5 47 00 p m

Update If you look in the Flatrate shipping class (line 108) this code skips the items that don't belong

if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
    continue;
}

I guess this can be used as a fix, but in my opinion items should not be added twice to the quote, the proprieties should be merged and only one should exist.

Hi @drew7721, I just reviewed your screenshots and it looks like expected behavior.

When you have configurable product - you’re having in cart actually two products, one relates to “configurable” product, while other relates to “simple”. That’s needed for association that you bought this product from configurable. Also you could add the same product as a simple, in this case you’ll have only one. You could see that on your screenshots you have different product_id values for those 2 products.

ihor-sviziev avatar Apr 03 '20 20:04 ihor-sviziev

Hi, @princeantil90 provided following video to reproduce this issue: https://nimb.ws/wcJX67

ihor-sviziev avatar Apr 06 '20 06:04 ihor-sviziev

Hi @ihor-sviziev. 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:

  • [x] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Apr 06 '20 06:04 m2-assistant[bot]

@magento give me 2.4-develop instance

ihor-sviziev avatar Apr 06 '20 06:04 ihor-sviziev

Hi @ihor-sviziev. Thank you for your request. I'm working on Magento 2.4-develop instance for you

magento-engcom-team avatar Apr 06 '20 06:04 magento-engcom-team

Hi @ihor-sviziev, here is your Magento instance. Admin access: https://i-7679-2-4-develop.instances.magento-community.engineering/admin_1743 Login: e63c5858 Password: a24f6d9af8c6 Instance will be terminated in up to 3 hours.

magento-engcom-team avatar Apr 06 '20 06:04 magento-engcom-team

Hi @princeantil90. 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:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!


m2-assistant[bot] avatar Apr 06 '20 07:04 m2-assistant[bot]

:white_check_mark: Confirmed by @ihor-sviziev Thank you for verifying the issue. Based on the provided information internal tickets MC-33098 were created

Issue Available: @ihor-sviziev, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

magento-engcom-team avatar Apr 06 '20 07:04 magento-engcom-team

@magento give me 2.4-develop instance

engcom-Kilo avatar Apr 30 '20 12:04 engcom-Kilo