5
5
*/
6
6
namespace Magento \Sales \Model \Order ;
7
7
8
- use Magento \Catalog \Api \Data \ProductOptionExtensionFactory ;
9
8
use Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface ;
10
- use Magento \Catalog \Model \ProductOptionFactory ;
11
9
use Magento \Catalog \Model \ProductOptionProcessorInterface ;
12
10
use Magento \Framework \Api \SearchCriteriaInterface ;
13
11
use Magento \Framework \DataObject ;
17
15
use Magento \Sales \Api \Data \OrderItemInterface ;
18
16
use Magento \Sales \Api \Data \OrderItemSearchResultInterfaceFactory ;
19
17
use Magento \Sales \Api \OrderItemRepositoryInterface ;
18
+ use Magento \Sales \Model \Order \ProductOption ;
20
19
use Magento \Sales \Model \ResourceModel \Metadata ;
21
20
22
21
/**
@@ -40,16 +39,6 @@ class ItemRepository implements OrderItemRepositoryInterface
40
39
*/
41
40
protected $ searchResultFactory ;
42
41
43
- /**
44
- * @var ProductOptionFactory
45
- */
46
- protected $ productOptionFactory ;
47
-
48
- /**
49
- * @var ProductOptionExtensionFactory
50
- */
51
- protected $ extensionFactory ;
52
-
53
42
/**
54
43
* @var ProductOptionProcessorInterface[]
55
44
*/
@@ -61,40 +50,41 @@ class ItemRepository implements OrderItemRepositoryInterface
61
50
protected $ registry = [];
62
51
63
52
/**
64
- * @var \Magento\Framework\Api\SearchCriteria\ CollectionProcessorInterface
53
+ * @var CollectionProcessorInterface
65
54
*/
66
55
private $ collectionProcessor ;
67
56
68
57
/**
69
- * ItemRepository constructor.
58
+ * @var ProductOption
59
+ */
60
+ private $ productOption ;
61
+
62
+ /**
70
63
* @param DataObjectFactory $objectFactory
71
64
* @param Metadata $metadata
72
65
* @param OrderItemSearchResultInterfaceFactory $searchResultFactory
73
- * @param ProductOptionFactory $productOptionFactory
74
- * @param ProductOptionExtensionFactory $extensionFactory
66
+ * @param CollectionProcessorInterface $collectionProcessor
67
+ * @param ProductOption $productOption
75
68
* @param array $processorPool
76
- * @param CollectionProcessorInterface|null $collectionProcessor
77
69
*/
78
70
public function __construct (
79
71
DataObjectFactory $ objectFactory ,
80
72
Metadata $ metadata ,
81
73
OrderItemSearchResultInterfaceFactory $ searchResultFactory ,
82
- ProductOptionFactory $ productOptionFactory ,
83
- ProductOptionExtensionFactory $ extensionFactory ,
84
- array $ processorPool = [],
85
- CollectionProcessorInterface $ collectionProcessor = null
74
+ CollectionProcessorInterface $ collectionProcessor ,
75
+ ProductOption $ productOption ,
76
+ array $ processorPool = []
86
77
) {
87
78
$ this ->objectFactory = $ objectFactory ;
88
79
$ this ->metadata = $ metadata ;
89
80
$ this ->searchResultFactory = $ searchResultFactory ;
90
- $ this ->productOptionFactory = $ productOptionFactory ;
91
- $ this ->extensionFactory = $ extensionFactory ;
81
+ $ this ->collectionProcessor = $ collectionProcessor ;
82
+ $ this ->productOption = $ productOption ;
92
83
$ this ->processorPool = $ processorPool ;
93
- $ this ->collectionProcessor = $ collectionProcessor ?: $ this ->getCollectionProcessor ();
94
84
}
95
85
96
86
/**
97
- * load entity
87
+ * Loads entity.
98
88
*
99
89
* @param int $id
100
90
* @return OrderItemInterface
@@ -113,7 +103,7 @@ public function get($id)
113
103
throw new NoSuchEntityException (__ ('Requested entity doesn \'t exist ' ));
114
104
}
115
105
116
- $ this ->addProductOption ($ orderItem );
106
+ $ this ->productOption -> add ($ orderItem );
117
107
$ this ->addParentItem ($ orderItem );
118
108
$ this ->registry [$ id ] = $ orderItem ;
119
109
}
@@ -134,7 +124,7 @@ public function getList(SearchCriteriaInterface $searchCriteria)
134
124
$ this ->collectionProcessor ->process ($ searchCriteria , $ searchResult );
135
125
/** @var OrderItemInterface $orderItem */
136
126
foreach ($ searchResult ->getItems () as $ orderItem ) {
137
- $ this ->addProductOption ($ orderItem );
127
+ $ this ->productOption -> add ($ orderItem );
138
128
}
139
129
140
130
return $ searchResult ;
@@ -175,45 +165,16 @@ public function save(OrderItemInterface $entity)
175
165
{
176
166
if ($ entity ->getProductOption ()) {
177
167
$ request = $ this ->getBuyRequest ($ entity );
178
- $ entity ->setProductOptions (['info_buyRequest ' => $ request ->toArray ()]);
168
+ $ productOptions = $ entity ->getProductOptions ();
169
+ $ productOptions ['info_buyRequest ' ] = $ request ->toArray ();
170
+ $ entity ->setProductOptions ($ productOptions );
179
171
}
180
172
181
173
$ this ->metadata ->getMapper ()->save ($ entity );
182
174
$ this ->registry [$ entity ->getEntityId ()] = $ entity ;
183
175
return $ this ->registry [$ entity ->getEntityId ()];
184
176
}
185
177
186
- /**
187
- * Add product option data
188
- *
189
- * @param OrderItemInterface $orderItem
190
- * @return $this
191
- */
192
- protected function addProductOption (OrderItemInterface $ orderItem )
193
- {
194
- /** @var DataObject $request */
195
- $ request = $ orderItem ->getBuyRequest ();
196
-
197
- $ productType = $ orderItem ->getProductType ();
198
- if (isset ($ this ->processorPool [$ productType ])
199
- && !$ orderItem ->getParentItemId ()) {
200
- $ data = $ this ->processorPool [$ productType ]->convertToProductOption ($ request );
201
- if ($ data ) {
202
- $ this ->setProductOption ($ orderItem , $ data );
203
- }
204
- }
205
-
206
- if (isset ($ this ->processorPool ['custom_options ' ])
207
- && !$ orderItem ->getParentItemId ()) {
208
- $ data = $ this ->processorPool ['custom_options ' ]->convertToProductOption ($ request );
209
- if ($ data ) {
210
- $ this ->setProductOption ($ orderItem , $ data );
211
- }
212
- }
213
-
214
- return $ this ;
215
- }
216
-
217
178
/**
218
179
* Set parent item.
219
180
*
@@ -228,32 +189,6 @@ private function addParentItem(OrderItemInterface $orderItem)
228
189
}
229
190
}
230
191
231
- /**
232
- * Set product options data
233
- *
234
- * @param OrderItemInterface $orderItem
235
- * @param array $data
236
- * @return $this
237
- */
238
- protected function setProductOption (OrderItemInterface $ orderItem , array $ data )
239
- {
240
- $ productOption = $ orderItem ->getProductOption ();
241
- if (!$ productOption ) {
242
- $ productOption = $ this ->productOptionFactory ->create ();
243
- $ orderItem ->setProductOption ($ productOption );
244
- }
245
-
246
- $ extensionAttributes = $ productOption ->getExtensionAttributes ();
247
- if (!$ extensionAttributes ) {
248
- $ extensionAttributes = $ this ->extensionFactory ->create ();
249
- $ productOption ->setExtensionAttributes ($ extensionAttributes );
250
- }
251
-
252
- $ extensionAttributes ->setData (key ($ data ), current ($ data ));
253
-
254
- return $ this ;
255
- }
256
-
257
192
/**
258
193
* Retrieve order item's buy request
259
194
*
@@ -285,20 +220,4 @@ protected function getBuyRequest(OrderItemInterface $entity)
285
220
286
221
return $ request ;
287
222
}
288
-
289
- /**
290
- * Retrieve collection processor
291
- *
292
- * @deprecated 100.2.0
293
- * @return CollectionProcessorInterface
294
- */
295
- private function getCollectionProcessor ()
296
- {
297
- if (!$ this ->collectionProcessor ) {
298
- $ this ->collectionProcessor = \Magento \Framework \App \ObjectManager::getInstance ()->get (
299
- \Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface::class
300
- );
301
- }
302
- return $ this ->collectionProcessor ;
303
- }
304
223
}
0 commit comments