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 ;
@@ -186,37 +176,6 @@ public function save(OrderItemInterface $entity)
186
176
return $ this ->registry [$ entity ->getEntityId ()];
187
177
}
188
178
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
179
/**
221
180
* Set parent item.
222
181
*
@@ -231,32 +190,6 @@ private function addParentItem(OrderItemInterface $orderItem)
231
190
}
232
191
}
233
192
234
- /**
235
- * Set product options data
236
- *
237
- * @param OrderItemInterface $orderItem
238
- * @param array $data
239
- * @return $this
240
- */
241
- protected function setProductOption (OrderItemInterface $ orderItem , array $ data )
242
- {
243
- $ productOption = $ orderItem ->getProductOption ();
244
- if (!$ productOption ) {
245
- $ productOption = $ this ->productOptionFactory ->create ();
246
- $ orderItem ->setProductOption ($ productOption );
247
- }
248
-
249
- $ extensionAttributes = $ productOption ->getExtensionAttributes ();
250
- if (!$ extensionAttributes ) {
251
- $ extensionAttributes = $ this ->extensionFactory ->create ();
252
- $ productOption ->setExtensionAttributes ($ extensionAttributes );
253
- }
254
-
255
- $ extensionAttributes ->setData (key ($ data ), current ($ data ));
256
-
257
- return $ this ;
258
- }
259
-
260
193
/**
261
194
* Retrieve order item's buy request
262
195
*
@@ -288,20 +221,4 @@ protected function getBuyRequest(OrderItemInterface $entity)
288
221
289
222
return $ request ;
290
223
}
291
-
292
- /**
293
- * Retrieve collection processor
294
- *
295
- * @deprecated 100.2.0
296
- * @return CollectionProcessorInterface
297
- */
298
- private function getCollectionProcessor ()
299
- {
300
- if (!$ this ->collectionProcessor ) {
301
- $ this ->collectionProcessor = \Magento \Framework \App \ObjectManager::getInstance ()->get (
302
- \Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface::class
303
- );
304
- }
305
- return $ this ->collectionProcessor ;
306
- }
307
224
}
0 commit comments