7
7
8
8
namespace Magento \ConfigurableProductGraphQl \Model \Cart \BuyRequest ;
9
9
10
+ use Magento \Catalog \Api \Data \ProductInterface ;
10
11
use Magento \Framework \Exception \NoSuchEntityException ;
11
12
use Magento \Framework \GraphQl \Exception \GraphQlNoSuchEntityException ;
12
13
use Magento \Framework \Stdlib \ArrayManager ;
13
14
use Magento \QuoteGraphQl \Model \Cart \BuyRequest \BuyRequestDataProviderInterface ;
14
15
use Magento \Catalog \Api \ProductRepositoryInterface ;
15
16
use Magento \ConfigurableProductGraphQl \Model \Options \Collection as OptionCollection ;
17
+ use Magento \Framework \EntityManager \MetadataPool ;
16
18
17
19
/**
18
20
* DataProvider for building super attribute options in buy requests
@@ -35,19 +37,26 @@ class SuperAttributeDataProvider implements BuyRequestDataProviderInterface
35
37
private $ optionCollection ;
36
38
37
39
/**
38
- * SuperAttributeDataProvider constructor.
40
+ * @var MetadataPool
41
+ */
42
+ private $ metadataPool ;
43
+
44
+ /**
39
45
* @param ArrayManager $arrayManager
40
46
* @param ProductRepositoryInterface $productRepository
41
47
* @param OptionCollection $optionCollection
48
+ * @param MetadataPool $metadataPool
42
49
*/
43
50
public function __construct (
44
51
ArrayManager $ arrayManager ,
45
52
ProductRepositoryInterface $ productRepository ,
46
- OptionCollection $ optionCollection
53
+ OptionCollection $ optionCollection ,
54
+ MetadataPool $ metadataPool
47
55
) {
48
56
$ this ->arrayManager = $ arrayManager ;
49
57
$ this ->productRepository = $ productRepository ;
50
58
$ this ->optionCollection = $ optionCollection ;
59
+ $ this ->metadataPool = $ metadataPool ;
51
60
}
52
61
53
62
/**
@@ -67,9 +76,9 @@ public function execute(array $cartItemData): array
67
76
} catch (NoSuchEntityException $ e ) {
68
77
throw new GraphQlNoSuchEntityException (__ ('Could not find specified product. ' ));
69
78
}
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 ));
73
82
74
83
$ superAttributesData = [];
75
84
foreach ($ options as $ option ) {
0 commit comments