Skip to content

Commit a51ab90

Browse files
committed
Unable to add configurable product to cart on any non-default store view
1 parent 67c52ad commit a51ab90

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function execute(array $cartItemData): array
9393
throw new GraphQlNoSuchEntityException(__('Could not find specified product.'));
9494
}
9595

96-
$this->checkProductStock($sku, (float) $qty, (int) $cart->getStoreId());
96+
$this->checkProductStock($sku, (float) $qty, (int) $cart->getStore()->getWebsite()->getId());
9797

9898
$configurableProductLinks = $parentProduct->getExtensionAttributes()->getConfigurableProductLinks();
9999
if (!in_array($product->getId(), $configurableProductLinks)) {

app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function execute(Quote $cart, array $cartItemData): void
6363

6464
try {
6565
$result = $cart->addProduct($product, $this->buyRequestBuilder->build($cartItemData));
66-
} catch (Exception $e) {die($e);
66+
} catch (Exception $e) {
6767
throw new GraphQlInputException(
6868
__(
6969
'Could not add the product with SKU %sku to the shopping cart: %message',

dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,44 @@ public function testAddConfigurableProductToCartWithCustomOption()
416416
$this->assertResponseFields($item['customizable_options'], $expectedOptions['customizable_options']);
417417
}
418418

419+
/**
420+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
421+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
422+
* @magentoApiDataFixture Magento/Store/_files/second_store.php
423+
*/
424+
public function testAddConfigurableProductToCartWithDifferentStoreHeader()
425+
{
426+
$searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable'));
427+
$product = current($searchResponse['products']['items']);
428+
429+
$quantity = 2;
430+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
431+
$parentSku = $product['sku'];
432+
$sku = 'simple_20';
433+
$attributeId = (int) $product['configurable_options'][0]['attribute_id'];
434+
$optionId = $product['configurable_options'][0]['values'][1]['value_index'];
435+
436+
$query = $this->getQuery(
437+
$maskedQuoteId,
438+
$parentSku,
439+
$sku,
440+
$quantity
441+
);
442+
$headerMap = ['Store' => 'fixture_second_store'];
443+
$response = $this->graphQlMutation($query, [], '', $headerMap);
444+
445+
$cartItem = current($response['addConfigurableProductsToCart']['cart']['items']);
446+
self::assertEquals($quantity, $cartItem['quantity']);
447+
self::assertEquals($parentSku, $cartItem['product']['sku']);
448+
self::assertArrayHasKey('configurable_options', $cartItem);
449+
450+
$option = current($cartItem['configurable_options']);
451+
self::assertEquals($attributeId, $option['id']);
452+
self::assertEquals($optionId, $option['value_id']);
453+
self::assertArrayHasKey('option_label', $option);
454+
self::assertArrayHasKey('value_label', $option);
455+
}
456+
419457
/**
420458
* @param string $maskedQuoteId
421459
* @param string $parentSku

0 commit comments

Comments
 (0)