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

GraphQL APIs for add<Type>ProductsToCart are unintuitive leading to excess requests #37955

Open ioweb-gr opened 1 year ago

ioweb-gr commented 1 year ago

Summary

Currently it seems that when using the addProductsToCart mutations in GraphQL if one product is out of stock, it will reject the whole request. Based on our developers' feedback this makes them resort to adding items to the cart one by one instead of using the mass endpoint because:

  1. it will take longer to respond and not actually add items to the cart (performance)
  2. it will only provide one failed sku in the response even if there are more out of stock products than 1 so it can potentially need the same requests as adding one by one but they are slower
  3. it's not intuitive

Examples

Think of the reorder case. I would like to reorder my previously purchased items. What's expected is that we can add them all in one sweep if possible for every single product type.

For example

Problem Statement

When attempting to add multiple products to the shopping cart in a single request, there's a chance that some products may not be available (out-of-stock, for instance). For every failed product, the entire request needs to be retried with one fewer product. This leads to extra requests, increasing server load and reducing performance.

Example Scenario

Let's consider you want to add 5 products: [prod1, prod2, prod3, prod4, prod5]. Two of them, prod2 and prod4, are not in stock.

First Request: Attempt to add 5 products.

Second Request: Remove prod2, and retry with 4 products.

Third Request: Remove prod4, and retry with 3 products.

Proposed solution

Solution 1

List all problematic products in one response. Then the user only needs one additional request to add the products to cart

Solution 2

Add the correct products, notify about the failed ones. The user doesn't need additional requests.

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @ioweb-gr. 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 1 year 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 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo, here is your Magento Instance: https://0f66e63d1b4388498e63ec7f917d5fa9.instances-prod.magento-community.engineering Admin access: https://0f66e63d1b4388498e63ec7f917d5fa9.instances-prod.magento-community.engineering/admin_09da Login: 129d5179 Password: f64f8a4e43d7

engcom-Bravo commented 1 year ago

Hi @ioweb-gr,

Thank you for reporting and collaboration.

Verified the Scenario on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.

We have created Prod1,Prod2,Prod3,Prod4,Prod5 and Prod2,Prod3 we have make it as Out Of Stock.

Screenshot 2023-09-05 at 4 05 17 PM

First Request: Attempt to add 5 products

Screenshot 2023-09-05 at 4 07 19 PM

Second Request: Remove prod2, and retry with 4 products.

Screenshot 2023-09-05 at 4 07 53 PM

Third Request: Remove prod4, and retry with 3 products.

Screenshot 2023-09-05 at 4 08 34 PM

We are agree with your proposed solutions In the first request itself we can skip the out of stock products and it can add other products to the cart User didn't go for additional requests.

Hence Confirming the issue.

Thanks.

github-jira-sync-bot commented 1 year ago

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

m2-assistant[bot] commented 1 year 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.

ioweb-gr commented 1 year ago

The tricky part with that is how to post back the skus that weren't added with the errors encountered. In other systems the response would include some message array listing those

Fabicool commented 1 year ago

@magento I am working on this