From ae2e92bcf91ac8c5efe522269344255f2cd2b21f Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Fri, 27 Sep 2019 12:30:56 +0300 Subject: [PATCH] MAGETWO-24676: fixed adding variation from another configurable product to cart if variation belongs to same super attribute --- .../Cart/BuyRequest/SuperAttributeDataProvider.php | 5 +++++ .../AddConfigurableProductToCartTest.php | 11 +++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Cart/BuyRequest/SuperAttributeDataProvider.php index f1971e228ac05..222c81803f230 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(__('The child product do not belong to the parent 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..8767b3e2b9044 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 The child product do not belong to the parent 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 The child product do not belong to the parent product. */ public function testAddVariationFromAnotherConfigurableProductWithDifferentSuperAttributeToCart() {