diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php index f1971e228ac05..4a613254ddf84 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php @@ -9,6 +9,7 @@ use Magento\Catalog\Api\Data\ProductInterface; use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\Stdlib\ArrayManager; use Magento\QuoteGraphQl\Model\Cart\BuyRequest\BuyRequestDataProviderInterface; @@ -76,6 +77,10 @@ public function execute(array $cartItemData): array } catch (NoSuchEntityException $e) { throw new GraphQlNoSuchEntityException(__('Could not find specified product.')); } + $configurableProductLinks = $parentProduct->getExtensionAttributes()->getConfigurableProductLinks(); + if (!in_array($product->getId(), $configurableProductLinks)) { + throw new GraphQlInputException(__('Could not find specified product.')); + } $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); $this->optionCollection->addProductId((int)$parentProduct->getData($linkField)); $options = $this->optionCollection->getAttributesByProductId((int)$parentProduct->getData($linkField)); diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php index 5ea5cef63a13f..39b69f86cbe13 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php @@ -141,19 +141,14 @@ public function testAddMultipleConfigurableProductToCart() } /** - * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_products.php + * @magentoApiDataFixture Magento/Catalog/_files/configurable_products_with_custom_attribute_layered_navigation.php * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php * * @expectedException Exception - * @expectedExceptionMessage You need to choose options for your item. + * @expectedExceptionMessage Could not find specified product. */ public function testAddVariationFromAnotherConfigurableProductWithTheSameSuperAttributeToCart() { - $this->markTestSkipped( - 'Magento automatically selects the correct child product according to the super attribute - https://github.com/magento/graphql-ce/issues/940' - ); - $searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable_12345')); $product = current($searchResponse['products']['items']); @@ -178,7 +173,7 @@ public function testAddVariationFromAnotherConfigurableProductWithTheSameSuperAt * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php * * @expectedException Exception - * @expectedExceptionMessage You need to choose options for your item. + * @expectedExceptionMessage Could not find specified product. */ public function testAddVariationFromAnotherConfigurableProductWithDifferentSuperAttributeToCart() {