Skip to content

Commit 702e6d8

Browse files
committed
magento/graphql-ce#438: Adjust adding configurable products to the shopping cart
1 parent ba871f5 commit 702e6d8

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

+14-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
namespace Magento\ConfigurableProductGraphQl\Model\Cart\BuyRequest;
99

10+
use Magento\Catalog\Api\Data\ProductInterface;
1011
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1213
use Magento\Framework\Stdlib\ArrayManager;
1314
use Magento\QuoteGraphQl\Model\Cart\BuyRequest\BuyRequestDataProviderInterface;
1415
use Magento\Catalog\Api\ProductRepositoryInterface;
1516
use Magento\ConfigurableProductGraphQl\Model\Options\Collection as OptionCollection;
17+
use Magento\Framework\EntityManager\MetadataPool;
1618

1719
/**
1820
* DataProvider for building super attribute options in buy requests
@@ -35,19 +37,26 @@ class SuperAttributeDataProvider implements BuyRequestDataProviderInterface
3537
private $optionCollection;
3638

3739
/**
38-
* SuperAttributeDataProvider constructor.
40+
* @var MetadataPool
41+
*/
42+
private $metadataPool;
43+
44+
/**
3945
* @param ArrayManager $arrayManager
4046
* @param ProductRepositoryInterface $productRepository
4147
* @param OptionCollection $optionCollection
48+
* @param MetadataPool $metadataPool
4249
*/
4350
public function __construct(
4451
ArrayManager $arrayManager,
4552
ProductRepositoryInterface $productRepository,
46-
OptionCollection $optionCollection
53+
OptionCollection $optionCollection,
54+
MetadataPool $metadataPool
4755
) {
4856
$this->arrayManager = $arrayManager;
4957
$this->productRepository = $productRepository;
5058
$this->optionCollection = $optionCollection;
59+
$this->metadataPool = $metadataPool;
5160
}
5261

5362
/**
@@ -67,9 +76,9 @@ public function execute(array $cartItemData): array
6776
} catch (NoSuchEntityException $e) {
6877
throw new GraphQlNoSuchEntityException(__('Could not find specified product.'));
6978
}
70-
71-
$this->optionCollection->addProductId((int)$parentProduct->getId());
72-
$options = $this->optionCollection->getAttributesByProductId((int)$parentProduct->getId());
79+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
80+
$this->optionCollection->addProductId((int)$parentProduct->getData($linkField));
81+
$options = $this->optionCollection->getAttributesByProductId((int)$parentProduct->getData($linkField));
7382

7483
$superAttributesData = [];
7584
foreach ($options as $option) {

0 commit comments

Comments
 (0)