77
88namespace Magento \ConfigurableProductGraphQl \Model \Cart \BuyRequest ;
99
10+ use Magento \Catalog \Api \Data \ProductInterface ;
1011use Magento \Framework \Exception \NoSuchEntityException ;
1112use Magento \Framework \GraphQl \Exception \GraphQlNoSuchEntityException ;
1213use Magento \Framework \Stdlib \ArrayManager ;
1314use Magento \QuoteGraphQl \Model \Cart \BuyRequest \BuyRequestDataProviderInterface ;
1415use Magento \Catalog \Api \ProductRepositoryInterface ;
1516use 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