Skip to content

Commit ae2e92b

Browse files
author
Vitaliy Boyko
committed
MAGETWO-24676: fixed adding variation from another configurable product to cart if variation belongs to same super attribute
1 parent ea71192 commit ae2e92b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1213
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1314
use Magento\Framework\Stdlib\ArrayManager;
1415
use Magento\QuoteGraphQl\Model\Cart\BuyRequest\BuyRequestDataProviderInterface;
@@ -76,6 +77,10 @@ public function execute(array $cartItemData): array
7677
} catch (NoSuchEntityException $e) {
7778
throw new GraphQlNoSuchEntityException(__('Could not find specified product.'));
7879
}
80+
$configurableProductLinks = $parentProduct->getExtensionAttributes()->getConfigurableProductLinks();
81+
if (!in_array($product->getId(), $configurableProductLinks)) {
82+
throw new GraphQlInputException(__('The child product do not belong to the parent product.'));
83+
}
7984
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
8085
$this->optionCollection->addProductId((int)$parentProduct->getData($linkField));
8186
$options = $this->optionCollection->getAttributesByProductId((int)$parentProduct->getData($linkField));

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,14 @@ public function testAddMultipleConfigurableProductToCart()
141141
}
142142

143143
/**
144-
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_products.php
144+
* @magentoApiDataFixture Magento/Catalog/_files/configurable_products_with_custom_attribute_layered_navigation.php
145145
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
146146
*
147147
* @expectedException Exception
148-
* @expectedExceptionMessage You need to choose options for your item.
148+
* @expectedExceptionMessage The child product do not belong to the parent product.
149149
*/
150150
public function testAddVariationFromAnotherConfigurableProductWithTheSameSuperAttributeToCart()
151151
{
152-
$this->markTestSkipped(
153-
'Magento automatically selects the correct child product according to the super attribute
154-
https://github.com/magento/graphql-ce/issues/940'
155-
);
156-
157152
$searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable_12345'));
158153
$product = current($searchResponse['products']['items']);
159154

@@ -178,7 +173,7 @@ public function testAddVariationFromAnotherConfigurableProductWithTheSameSuperAt
178173
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
179174
*
180175
* @expectedException Exception
181-
* @expectedExceptionMessage You need to choose options for your item.
176+
* @expectedExceptionMessage The child product do not belong to the parent product.
182177
*/
183178
public function testAddVariationFromAnotherConfigurableProductWithDifferentSuperAttributeToCart()
184179
{

0 commit comments

Comments
 (0)