Skip to content

Commit

Permalink
ENGCOM-5962: MAGETWO-24676: fixed adding variation from another confi…
Browse files Browse the repository at this point in the history
…gurable produ… #968
  • Loading branch information
lenaorobei authored Oct 1, 2019
2 parents 01fef01 + af0ed6f commit d425563
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

0 comments on commit d425563

Please sign in to comment.