File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
app/code/Magento/ConfigurableProductGraphQl Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \ConfigurableProductGraphQl \Model \Resolver ;
9
+
10
+ use Magento \Framework \Exception \LocalizedException ;
11
+ use Magento \Framework \GraphQl \Config \Element \Field ;
12
+ use Magento \Framework \GraphQl \Query \ResolverInterface ;
13
+ use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
14
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
15
+
16
+ /**
17
+ * Fetches the Product data according to the GraphQL schema
18
+ */
19
+ class ProductResolver implements ResolverInterface
20
+ {
21
+ /**
22
+ * @var ProductRepositoryInterface
23
+ */
24
+ private $ productRepository ;
25
+
26
+ /**
27
+ * @param ProductRepositoryInterface $productRepository
28
+ */
29
+ public function __construct (ProductRepositoryInterface $ productRepository )
30
+ {
31
+ $ this ->productRepository = $ productRepository ;
32
+ }
33
+
34
+ /**
35
+ * @inheritdoc
36
+ */
37
+ public function resolve (
38
+ Field $ field ,
39
+ $ context ,
40
+ ResolveInfo $ info ,
41
+ array $ value = null ,
42
+ array $ args = null
43
+ ) {
44
+ if (!isset ($ value ['model ' ])) {
45
+ throw new LocalizedException (__ ('"model" value should be specified ' ));
46
+ }
47
+
48
+ $ cartItem = $ value ['model ' ];
49
+ $ product = $ this ->productRepository ->get ($ cartItem ->getSku ());
50
+ $ productData = $ product ->toArray ();
51
+ $ productData ['model ' ] = $ product ;
52
+ return $ productData ;
53
+ }
54
+ }
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ input ConfigurableProductCartItemInput {
61
61
type ConfigurableCartItem implements CartItemInterface {
62
62
customizable_options : [SelectedCustomizableOption ] @resolver (class : " Magento\\ QuoteGraphQl\\ Model\\ Resolver\\ CustomizableOptions" )
63
63
configurable_options : [SelectedConfigurableOption ! ]! @resolver (class : " Magento\\ ConfigurableProductGraphQl\\ Model\\ Resolver\\ ConfigurableCartItemOptions" )
64
+ configured_variant : ProductInterface @doc (description : " Product details of the cart item" ) @resolver (class : " \\ Magento\\ ConfigurableProductGraphQl\\ Model\\ Resolver\\ ProductResolver" )
64
65
}
65
66
66
67
type SelectedConfigurableOption {
You can’t perform that action at this time.
0 commit comments