Magento2: How to Merge guest quote items to customer quote(if customer log in) by magento 2 rest API

Created on 1 Oct 2019  路  11Comments  路  Source: magento/magento2

Preconditions (*)

Magento 2.3-develop
If any one is add products in cart by guest and after that login then how it will merge guest cart to customer login cart items by Rest API.

Steps to reproduce (*)

  1. Create a customer
  2. Log out from customer account
  3. Add any product to cart
  4. Try to merge quotes via API
Authorization -"Bearer {user-token}"
PUT {URL}/rest/V1/guest-carts/{guest-card-id}
Body: 
{
  "customerId": {customer id},
  "storeId": {store id}
}

Expected result (*)

200 OK
true

Actual result (*)

getting error : "The customer can't be assigned to the cart because the customer already has an active cart."
Screenshot from 2019-10-02 13-18-36

Api Quote Fixed in 2.3.x Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.3.x

All 11 comments

Hi @sangeetajain. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@sangeetajain do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @engcom-Charlie. 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.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.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.

:white_check_mark: Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-21009 were created

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

Hi @ivan-koliadynskyy. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

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

  • [ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


Hello Team,
Is there any update regarding this issue...?

Hello Team,
Is there any update regarding this issue...?

Hello @sangeetajain !
Fix in progress as you can see in #24862 .

I created a workaround from the above fix for versions < 2.3.4. https://github.com/troublediehard/plab-cartsmergefix

What need to do for work with magento 2.3.3

The fix is working but the merge is not taking into consideration the available quantity of stock items of the products in cart.
At Model\Quote.php, lines 2392 and 2393:
...
$quoteItem->setQty($quoteItem->getQty() + $item->getQty());
$this->itemProcessor->merge($item, $quoteItem);
...

The setQty bypasses any check of availability / eligibility.
Let's say a product has only 1 item in stock, a logged in customer adds it to the cart, then logs out, adds it again as a guest and then logs back in. The merge will result in 2x items of a 1x stock available product, and the checkout will throw an error, forcing the customer to manually adjust qty in cart.

Was this page helpful?
0 / 5 - 0 ratings