6
6
7
7
namespace Magento \Sales \Model \Order ;
8
8
9
- use Magento \Catalog \Api \Data \ProductOptionExtensionFactory ;
10
- use Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface ;
11
- use Magento \Catalog \Model \ProductOptionFactory ;
12
9
use Magento \Catalog \Model \ProductOptionProcessorInterface ;
10
+ use Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface ;
13
11
use Magento \Framework \Api \SearchCriteriaInterface ;
14
12
use Magento \Framework \DataObject ;
15
13
use Magento \Framework \DataObject \Factory as DataObjectFactory ;
18
16
use Magento \Sales \Api \Data \OrderItemInterface ;
19
17
use Magento \Sales \Api \Data \OrderItemSearchResultInterfaceFactory ;
20
18
use Magento \Sales \Api \OrderItemRepositoryInterface ;
19
+ use Magento \Sales \Model \Order \ProductOption ;
21
20
use Magento \Sales \Model \ResourceModel \Metadata ;
22
21
23
22
/**
@@ -41,16 +40,6 @@ class ItemRepository implements OrderItemRepositoryInterface
41
40
*/
42
41
protected $ searchResultFactory ;
43
42
44
- /**
45
- * @var ProductOptionFactory
46
- */
47
- protected $ productOptionFactory ;
48
-
49
- /**
50
- * @var ProductOptionExtensionFactory
51
- */
52
- protected $ extensionFactory ;
53
-
54
43
/**
55
44
* @var ProductOptionProcessorInterface[]
56
45
*/
@@ -62,40 +51,41 @@ class ItemRepository implements OrderItemRepositoryInterface
62
51
protected $ registry = [];
63
52
64
53
/**
65
- * @var \Magento\Framework\Api\SearchCriteria\ CollectionProcessorInterface
54
+ * @var CollectionProcessorInterface
66
55
*/
67
56
private $ collectionProcessor ;
68
57
69
58
/**
70
- * ItemRepository constructor.
59
+ * @var ProductOption
60
+ */
61
+ private $ productOption ;
62
+
63
+ /**
71
64
* @param DataObjectFactory $objectFactory
72
65
* @param Metadata $metadata
73
66
* @param OrderItemSearchResultInterfaceFactory $searchResultFactory
74
- * @param ProductOptionFactory $productOptionFactory
75
- * @param ProductOptionExtensionFactory $extensionFactory
67
+ * @param CollectionProcessorInterface $collectionProcessor
68
+ * @param ProductOption $productOption
76
69
* @param array $processorPool
77
- * @param CollectionProcessorInterface|null $collectionProcessor
78
70
*/
79
71
public function __construct (
80
72
DataObjectFactory $ objectFactory ,
81
73
Metadata $ metadata ,
82
74
OrderItemSearchResultInterfaceFactory $ searchResultFactory ,
83
- ProductOptionFactory $ productOptionFactory ,
84
- ProductOptionExtensionFactory $ extensionFactory ,
85
- array $ processorPool = [],
86
- CollectionProcessorInterface $ collectionProcessor = null
75
+ CollectionProcessorInterface $ collectionProcessor ,
76
+ ProductOption $ productOption ,
77
+ array $ processorPool = []
87
78
) {
88
79
$ this ->objectFactory = $ objectFactory ;
89
80
$ this ->metadata = $ metadata ;
90
81
$ this ->searchResultFactory = $ searchResultFactory ;
91
- $ this ->productOptionFactory = $ productOptionFactory ;
92
- $ this ->extensionFactory = $ extensionFactory ;
82
+ $ this ->collectionProcessor = $ collectionProcessor ;
83
+ $ this ->productOption = $ productOption ;
93
84
$ this ->processorPool = $ processorPool ;
94
- $ this ->collectionProcessor = $ collectionProcessor ?: $ this ->getCollectionProcessor ();
95
85
}
96
86
97
87
/**
98
- * Load entity
88
+ * Loads entity.
99
89
*
100
90
* @param int $id
101
91
* @return OrderItemInterface
@@ -116,7 +106,7 @@ public function get($id)
116
106
);
117
107
}
118
108
119
- $ this ->addProductOption ($ orderItem );
109
+ $ this ->productOption -> add ($ orderItem );
120
110
$ this ->addParentItem ($ orderItem );
121
111
$ this ->registry [$ id ] = $ orderItem ;
122
112
}
@@ -137,7 +127,7 @@ public function getList(SearchCriteriaInterface $searchCriteria)
137
127
$ this ->collectionProcessor ->process ($ searchCriteria , $ searchResult );
138
128
/** @var OrderItemInterface $orderItem */
139
129
foreach ($ searchResult ->getItems () as $ orderItem ) {
140
- $ this ->addProductOption ($ orderItem );
130
+ $ this ->productOption -> add ($ orderItem );
141
131
}
142
132
143
133
return $ searchResult ;
@@ -178,45 +168,16 @@ public function save(OrderItemInterface $entity)
178
168
{
179
169
if ($ entity ->getProductOption ()) {
180
170
$ request = $ this ->getBuyRequest ($ entity );
181
- $ entity ->setProductOptions (['info_buyRequest ' => $ request ->toArray ()]);
171
+ $ productOptions = $ entity ->getProductOptions ();
172
+ $ productOptions ['info_buyRequest ' ] = $ request ->toArray ();
173
+ $ entity ->setProductOptions ($ productOptions );
182
174
}
183
175
184
176
$ this ->metadata ->getMapper ()->save ($ entity );
185
177
$ this ->registry [$ entity ->getEntityId ()] = $ entity ;
186
178
return $ this ->registry [$ entity ->getEntityId ()];
187
179
}
188
180
189
- /**
190
- * Add product option data
191
- *
192
- * @param OrderItemInterface $orderItem
193
- * @return $this
194
- */
195
- protected function addProductOption (OrderItemInterface $ orderItem )
196
- {
197
- /** @var DataObject $request */
198
- $ request = $ orderItem ->getBuyRequest ();
199
-
200
- $ productType = $ orderItem ->getProductType ();
201
- if (isset ($ this ->processorPool [$ productType ])
202
- && !$ orderItem ->getParentItemId ()) {
203
- $ data = $ this ->processorPool [$ productType ]->convertToProductOption ($ request );
204
- if ($ data ) {
205
- $ this ->setProductOption ($ orderItem , $ data );
206
- }
207
- }
208
-
209
- if (isset ($ this ->processorPool ['custom_options ' ])
210
- && !$ orderItem ->getParentItemId ()) {
211
- $ data = $ this ->processorPool ['custom_options ' ]->convertToProductOption ($ request );
212
- if ($ data ) {
213
- $ this ->setProductOption ($ orderItem , $ data );
214
- }
215
- }
216
-
217
- return $ this ;
218
- }
219
-
220
181
/**
221
182
* Set parent item.
222
183
*
@@ -239,32 +200,6 @@ private function addParentItem(OrderItemInterface $orderItem)
239
200
}
240
201
}
241
202
242
- /**
243
- * Set product options data
244
- *
245
- * @param OrderItemInterface $orderItem
246
- * @param array $data
247
- * @return $this
248
- */
249
- protected function setProductOption (OrderItemInterface $ orderItem , array $ data )
250
- {
251
- $ productOption = $ orderItem ->getProductOption ();
252
- if (!$ productOption ) {
253
- $ productOption = $ this ->productOptionFactory ->create ();
254
- $ orderItem ->setProductOption ($ productOption );
255
- }
256
-
257
- $ extensionAttributes = $ productOption ->getExtensionAttributes ();
258
- if (!$ extensionAttributes ) {
259
- $ extensionAttributes = $ this ->extensionFactory ->create ();
260
- $ productOption ->setExtensionAttributes ($ extensionAttributes );
261
- }
262
-
263
- $ extensionAttributes ->setData (key ($ data ), current ($ data ));
264
-
265
- return $ this ;
266
- }
267
-
268
203
/**
269
204
* Retrieve order item's buy request
270
205
*
@@ -296,20 +231,4 @@ protected function getBuyRequest(OrderItemInterface $entity)
296
231
297
232
return $ request ;
298
233
}
299
-
300
- /**
301
- * Retrieve collection processor
302
- *
303
- * @deprecated 100.2.0
304
- * @return CollectionProcessorInterface
305
- */
306
- private function getCollectionProcessor ()
307
- {
308
- if (!$ this ->collectionProcessor ) {
309
- $ this ->collectionProcessor = \Magento \Framework \App \ObjectManager::getInstance ()->get (
310
- \Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface::class
311
- );
312
- }
313
- return $ this ->collectionProcessor ;
314
- }
315
234
}
0 commit comments