22
22
use Magento \Sales \Model \OrderFactory ;
23
23
use Magento \Sales \Model \ResourceModel \Order \Item \Collection as ItemCollection ;
24
24
use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory as ProductCollectionFactory ;
25
- use \ Magento \ Framework \ Serialize \ SerializerInterface ;
25
+ use Psr \ Log \ LoggerInterface ;
26
26
27
27
/**
28
28
* Allows customer quickly to reorder previously added products and put them to the Cart
@@ -64,7 +64,7 @@ class Reorder
64
64
private $ reorderHelper ;
65
65
66
66
/**
67
- * @var \Psr\Log\ LoggerInterface
67
+ * @var LoggerInterface
68
68
*/
69
69
private $ logger ;
70
70
@@ -94,28 +94,29 @@ class Reorder
94
94
private $ guestCartResolver ;
95
95
96
96
/**
97
- * @var SerializerInterface
97
+ * @var OrderInfoBuyRequestGetter
98
98
*/
99
- private $ serializer ;
99
+ private $ orderInfoBuyRequestGetter ;
100
100
101
101
/**
102
102
* @param OrderFactory $orderFactory
103
103
* @param CustomerCartResolver $customerCartProvider
104
104
* @param GuestCartResolver $guestCartResolver
105
105
* @param CartRepositoryInterface $cartRepository
106
106
* @param ReorderHelper $reorderHelper
107
- * @param \Psr\Log\ LoggerInterface $logger
107
+ * @param LoggerInterface $logger
108
108
* @param ProductCollectionFactory $productCollectionFactory
109
+ * @param OrderInfoBuyRequestGetter $orderInfoBuyRequestGetter
109
110
*/
110
111
public function __construct (
111
112
OrderFactory $ orderFactory ,
112
113
CustomerCartResolver $ customerCartProvider ,
113
114
GuestCartResolver $ guestCartResolver ,
114
115
CartRepositoryInterface $ cartRepository ,
115
116
ReorderHelper $ reorderHelper ,
116
- \ Psr \ Log \ LoggerInterface $ logger ,
117
+ LoggerInterface $ logger ,
117
118
ProductCollectionFactory $ productCollectionFactory ,
118
- \ Magento \ Framework \ Serialize \ SerializerInterface $ serializer
119
+ OrderInfoBuyRequestGetter $ orderInfoBuyRequestGetter
119
120
) {
120
121
$ this ->orderFactory = $ orderFactory ;
121
122
$ this ->cartRepository = $ cartRepository ;
@@ -124,7 +125,7 @@ public function __construct(
124
125
$ this ->customerCartProvider = $ customerCartProvider ;
125
126
$ this ->guestCartResolver = $ guestCartResolver ;
126
127
$ this ->productCollectionFactory = $ productCollectionFactory ;
127
- $ this ->serializer = $ serializer ;
128
+ $ this ->orderInfoBuyRequestGetter = $ orderInfoBuyRequestGetter ;
128
129
}
129
130
130
131
/**
@@ -251,9 +252,7 @@ private function getOrderProducts(string $storeId, array $orderItemProductIds):
251
252
*/
252
253
private function addItemToCart (OrderItemInterface $ orderItem , Quote $ cart , ProductInterface $ product ): void
253
254
{
254
- $ infoBuyRequest = $ this ->getInfoBuyRequest ($ orderItem );
255
- $ infoBuyRequest = new \Magento \Framework \DataObject ($ infoBuyRequest );
256
- $ infoBuyRequest ->setQty ($ orderItem ->getQtyOrdered ());
255
+ $ infoBuyRequest = $ this ->orderInfoBuyRequestGetter ->getInfoBuyRequest ($ orderItem );
257
256
258
257
$ addProductResult = null ;
259
258
try {
@@ -346,35 +345,4 @@ private function getCartItemErrorMessage(Item $item, Product $product, string $m
346
345
? __ ('Could not add the product with SKU "%1" to the shopping cart: %2 ' , $ sku , $ message )
347
346
: __ ('Could not add the product with SKU "%1" to the shopping cart ' , $ sku ));
348
347
}
349
-
350
- /**
351
- * Prepare Custom Option for order Item
352
- *
353
- * @param OrderItemInterface $orderItem
354
- * @return array|null
355
- */
356
- private function getInfoBuyRequest (OrderItemInterface $ orderItem ): ?array
357
- {
358
- $ info = $ orderItem ->getProductOptionByCode ('info_buyRequest ' );
359
- $ options = $ orderItem ->getProductOptionByCode ('options ' );
360
-
361
- if (empty ($ options ) || !is_array ($ info ['options ' ])) {
362
- return $ info ;
363
- }
364
-
365
- foreach ($ options as $ option ) {
366
- if (array_key_exists ($ option ['option_id ' ], $ info ['options ' ])) {
367
- try {
368
- $ value = $ this ->serializer ->unserialize ($ option ['option_value ' ]);
369
- $ info ['options ' ][$ option ['option_id ' ]] = $ value ;
370
- } catch (\InvalidArgumentException $ exception ) {
371
- //log the exception as warning
372
- $ this ->_logger ->warning ($ exception );
373
- }
374
- }
375
- }
376
-
377
- return $ info ;
378
- }
379
-
380
348
}
0 commit comments