Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

MAGETWO-24676: fixed adding variation from another configurable produ… #968

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

Expand All @@ -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()
{
Expand Down