Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to add configurable product to cart on any non-default store view #3264

Closed
wants to merge 2 commits into from

Conversation

shikhamis11
Copy link
Member

@shikhamis11 shikhamis11 commented Jan 18, 2021

Description (*)

Note: Simple Products work across website/store code, this bug is specific to configurable products

PWA Repro:

URL - https://integration-5ojmyuq-jnz3dtiuj77ca.us-4.magentosite.cloud/montana-wind-jacket.html

Steps -

Go to above URL.

Switch to French Store and try adding configurable to to cart.

Expected - Product should get added.

Actual - User gets error "Could not add item to cart. Please check required options and try again."

GQL Repro:

Using a backend on 2.4.2-beta3, create a cart
Attempt to add a configurable item to the "french" store:

// Query

mutation addConfigurableProductToCart(
  $cartId: String!
  $quantity: Float!
  $sku: String!
  $parentSku: String!
) {
  addConfigurableProductsToCart(
    input: {
      cart_id: $cartId
      cart_items: [
        { data: { quantity: $quantity, sku: $sku }, parent_sku: $parentSku }
      ]
    }
  ) {
    cart {
      id
      total_quantity
    }
  }
}
{code}

{code:java}
// Query Variables
{
  "cartId":"9cfw1jBRxnyyic8jVoBLXELkDOZtobJ4",
  "quantity": 1,
  "sku": "WT09-XL-Yellow",
  "parentSku": "WT09"
} {code}
{code:java}
// Header
{ 
  "store": "fr" 
}{code}
 

Expected:
{code:java}
 {
  "data": {
    "addConfigurableProductsToCart": {
      "cart": {
        "id": "9cfw1jBRxnyyic8jVoBLXELkDOZtobJ4",
        "total_quantity": 4
      }
    }
  }
}{code}
 

Actual:
{code:java}
{
  "errors": [
    {
      "message": "Could not add the product with SKU WT09 to the shopping cart: The website with id 2 that was requested wasn't found. Verify the website and try again.",
      "extensions": {
        "category": "graphql-input"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "addConfigurableProductsToCart"
      ]
    }
  >,
  "data": {
    "addConfigurableProductsToCart": null
  }
} 

Fixed Issues (if relevant)

  1. Fixes Unable to add configurable product to cart on any non-default store view (French store). magento2#31660

Manual testing scenarios (*)

  1. ...
  2. ...

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@shikhamis11
Copy link
Member Author

@magento give me test instance

@magento-deployment-service
Copy link

Hi @shikhamis11. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@shikhamis11
Copy link
Member Author

@magento run all tests

@shikhamis11
Copy link
Member Author

@magento run all tests

@shikhamis11
Copy link
Member Author

@magento give me test instance

@magento-deployment-service
Copy link

Hi @shikhamis11. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

Copy link
Contributor

@novikor novikor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @shikhamis11. Thank you for your contribution.
The solution provided is not acceptable: due to these changes the $scopeId parameter is always ignored making it impossible to check the QTY for a non-current website.

I would recommend to research commit 1cc26fa instead. More likely reverting it is a preferable way.

As another solution, we might pass websiteId instead of storeId in https://github.com/magento/magento2/blob/45ff6359d82a761562aa4a56782e1c262ab8bb33/app/code/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php#L96

@shikhamis11
Copy link
Member Author

shikhamis11 commented Jan 19, 2021

hi @novikor ,
Thanks for review
yes I tried with given scope id variable. The thing is $scopeId variable passed in the CheckQuoteItemQty function is not clear
I tried for simple product & others there it is websiteId and for Configurable product It is storeViewId.
Let me know what it should be as It may be multiple times. so I tried to get It from actual storemanager & I think It is giving the right value for all areas

@novikor
Copy link
Contributor

novikor commented Jan 19, 2021

@shikhamis11 you are right, more likely getting a current website will cover all frontend and GraphQL usage cases, but \Magento\CatalogInventory\Api\StockStateInterface::checkQuoteItemQty still might be called elsewhere with $scopeId that differs from the current one, so this approach might be a little dangerous.

As I can see, the plugin affected expects to get websiteId in the $scopeId parameter, and \Magento\ConfigurableProductGraphQl\Model\Cart\BuyRequest\SuperAttributeDataProvider::checkProductStock is the only place where this argument is ambiguous.

Looks like it should be resolved on ConfigurableProductGraphQl level, \Magento\InventorySales\Plugin\StockState\CheckQuoteItemQtyPlugin::aroundCheckQuoteItemQty seems to be working properly.

@dthampy
Copy link

dthampy commented Jan 19, 2021

Thanks @shikhamis11 . Please add api-functional test coverage for this fix.

@shikhamis11
Copy link
Member Author

thanks @novikor
I am proceeding with magento 2 repo PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to add configurable product to cart on any non-default store view (French store).
4 participants