7
7
8
8
namespace Magento \GraphQl \Quote ;
9
9
10
- use Magento \Quote \Api \CartRepositoryInterface ;
10
+ use Magento \Catalog \Api \Data \ProductCustomOptionInterface ;
11
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
12
+ use Magento \Framework \Exception \NoSuchEntityException ;
11
13
use Magento \Quote \Model \Quote as QuoteModel ;
12
- use Magento \Quote \Model \QuoteIdMask ;
13
14
use Magento \Quote \Model \QuoteIdToMaskedQuoteIdInterface ;
14
15
use Magento \TestFramework \ObjectManager ;
15
16
use Magento \TestFramework \TestCase \GraphQlAbstract ;
19
20
*/
20
21
class AddSimpleProductsToCartTest extends GraphQlAbstract
21
22
{
22
- /**
23
- * @var QuoteIdMask
24
- */
25
- private $ quoteIdMask ;
26
-
27
23
/**
28
24
* @var ObjectManager
29
25
*/
@@ -39,14 +35,19 @@ class AddSimpleProductsToCartTest extends GraphQlAbstract
39
35
*/
40
36
private $ quoteIdToMaskedQuote ;
41
37
38
+ /**
39
+ * @var ProductRepositoryInterface
40
+ */
41
+ private $ productRepository ;
42
+
42
43
/**
43
44
* @return void
44
45
*/
45
46
protected function setUp ()
46
47
{
47
48
$ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
48
- $ this ->quoteIdMask = $ this ->objectManager ->create (QuoteIdMask::class);
49
49
$ this ->quoteModel = $ this ->objectManager ->create (QuoteModel::class);
50
+ $ this ->productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
50
51
$ this ->quoteIdToMaskedQuote = $ this ->objectManager ->create (QuoteIdToMaskedQuoteIdInterface::class);
51
52
}
52
53
@@ -57,8 +58,10 @@ protected function setUp()
57
58
*/
58
59
public function testAddSimpleProductsToCartForGuest ()
59
60
{
61
+ $ productSku = 'simple ' ;
60
62
$ this ->quoteModel ->load ('test_order_1 ' , 'reserved_order_id ' );
61
63
$ quoteHash = $ this ->quoteIdToMaskedQuote ->execute ((int ) $ this ->quoteModel ->getId ());
64
+ $ selectedOptionData = $ this ->getSelectedOptionData ($ productSku );
62
65
63
66
$ query = <<<QUERY
64
67
mutation {
@@ -68,7 +71,7 @@ public function testAddSimpleProductsToCartForGuest()
68
71
cartItems: [
69
72
{
70
73
details: {
71
- sku: "simple ",
74
+ sku: " $ productSku ",
72
75
qty: 1
73
76
},
74
77
customizable_options: [{id: 1, value: "Test"}, {id: 2, value: "Wow"}, {id: 3, value: "test.jpg"}, {id: 5, value: "1"}, {id: 6, value: "3"}]
@@ -120,4 +123,32 @@ public function testAddSimpleProductsToCartForGuest()
120
123
121
124
122
125
}
126
+
127
+ /**
128
+ * @param string $productSku
129
+ * @throws NoSuchEntityException
130
+ */
131
+ protected function getSelectedOptionData (string $ productSku )
132
+ {
133
+ $ selectedProductData = [];
134
+ $ product = $ this ->productRepository ->get ($ productSku );
135
+ $ fieldTypes = [ProductCustomOptionInterface::OPTION_TYPE_AREA , ProductCustomOptionInterface::OPTION_TYPE_FIELD ];
136
+ $ dropdownTypes = [
137
+ ProductCustomOptionInterface::OPTION_TYPE_DROP_DOWN ,
138
+ ProductCustomOptionInterface::OPTION_TYPE_RADIO ,
139
+ ProductCustomOptionInterface::OPTION_TYPE_CHECKBOX ,
140
+ ];
141
+
142
+ foreach ($ product ->getOptions () as $ option ) {
143
+ if (in_array ($ option ->getType (), $ fieldTypes )) {
144
+ $ selectedProductData [$ option ->getOptionId ()] = $ option ->getType (); // custom text
145
+ }
146
+ if (in_array ($ option ->getType (), $ dropdownTypes )) {
147
+ $ optionValues = $ option ->getValues ();
148
+
149
+ }
150
+ }
151
+
152
+ return $ selectedProductData ;
153
+ }
123
154
}
0 commit comments