7
7
8
8
namespace Magento \QuoteGraphQl \Model \Cart ;
9
9
10
- use Magento \Catalog \Api \Data \ProductCustomOptionInterface ;
11
- use Magento \Catalog \Api \ProductCustomOptionRepositoryInterface ;
12
10
use Magento \Catalog \Api \ProductRepositoryInterface ;
13
11
use Magento \Framework \DataObject ;
14
12
use Magento \Framework \DataObjectFactory ;
25
23
*/
26
24
class AddSimpleProductToCart
27
25
{
28
- /**
29
- * @var ProductCustomOptionRepositoryInterface
30
- */
31
- private $ customOptionRepository ;
32
-
33
26
/**
34
27
* @var ArrayManager
35
28
*/
@@ -49,18 +42,15 @@ class AddSimpleProductToCart
49
42
* @param ArrayManager $arrayManager
50
43
* @param DataObjectFactory $dataObjectFactory
51
44
* @param ProductRepositoryInterface $productRepository
52
- * @param ProductCustomOptionRepositoryInterface $customOptionRepository
53
45
*/
54
46
public function __construct (
55
47
ArrayManager $ arrayManager ,
56
48
DataObjectFactory $ dataObjectFactory ,
57
- ProductRepositoryInterface $ productRepository ,
58
- ProductCustomOptionRepositoryInterface $ customOptionRepository
49
+ ProductRepositoryInterface $ productRepository
59
50
) {
60
51
$ this ->arrayManager = $ arrayManager ;
61
52
$ this ->dataObjectFactory = $ dataObjectFactory ;
62
53
$ this ->productRepository = $ productRepository ;
63
- $ this ->customOptionRepository = $ customOptionRepository ;
64
54
}
65
55
66
56
/**
@@ -77,7 +67,7 @@ public function execute(Quote $cart, array $cartItemData): void
77
67
{
78
68
$ sku = $ this ->extractSku ($ cartItemData );
79
69
$ qty = $ this ->extractQty ($ cartItemData );
80
- $ customizableOptions = $ this ->extractCustomizableOptions ($ cartItemData, $ sku );
70
+ $ customizableOptions = $ this ->extractCustomizableOptions ($ cartItemData );
81
71
82
72
try {
83
73
$ product = $ this ->productRepository ->get ($ sku );
@@ -137,23 +127,15 @@ private function extractQty(array $cartItemData): float
137
127
* Extract Customizable Options from cart item data
138
128
*
139
129
* @param array $cartItemData
140
- * @param string $sku
141
130
* @return array
142
131
*/
143
- private function extractCustomizableOptions (array $ cartItemData, string $ sku ): array
132
+ private function extractCustomizableOptions (array $ cartItemData ): array
144
133
{
145
134
$ customizableOptions = $ this ->arrayManager ->get ('customizable_options ' , $ cartItemData , []);
146
- $ productCustomOptions = $ this ->customOptionRepository ->getList ($ sku );
147
- $ productCustomOptionsMap = $ this ->getProductCustomOptionsMap ($ productCustomOptions );
148
- $ customizableOptionsData = [];
149
135
136
+ $ customizableOptionsData = [];
150
137
foreach ($ customizableOptions as $ customizableOption ) {
151
- $ multipleOptionTypesList = ['multiple ' , 'checkbox ' ]; // TODO: use constants
152
- if (in_array ($ productCustomOptionsMap [$ customizableOption ['id ' ]]->getType (), $ multipleOptionTypesList )) {
153
- $ customizableOptionsData [$ customizableOption ['id ' ]] = explode (', ' , $ customizableOption ['value ' ]);
154
- } else {
155
- $ customizableOptionsData [$ customizableOption ['id ' ]] = $ customizableOption ['value ' ];
156
- }
138
+ $ customizableOptionsData [$ customizableOption ['id ' ]] = $ customizableOption ['value ' ];
157
139
}
158
140
return $ customizableOptionsData ;
159
141
}
@@ -174,21 +156,4 @@ private function createBuyRequest(float $qty, array $customOptions): DataObject
174
156
],
175
157
]);
176
158
}
177
-
178
- /**
179
- * Creates an array with a key equals option ID
180
- *
181
- * @param array $productCustomOptions
182
- * @return array
183
- */
184
- private function getProductCustomOptionsMap (array $ productCustomOptions ): array
185
- {
186
- $ customOptionsData = [];
187
- /** @var ProductCustomOptionInterface $productCustomOption */
188
- foreach ($ productCustomOptions as $ productCustomOption ) {
189
- $ customOptionsData [$ productCustomOption ->getOptionId ()] = $ productCustomOption ;
190
- }
191
-
192
- return $ customOptionsData ;
193
- }
194
159
}
0 commit comments