9
9
use Magento \Catalog \Api \Data \ProductInterface ;
10
10
use Magento \Catalog \Model \Product ;
11
11
use Magento \Catalog \Model \ResourceModel \Product \Collection ;
12
+ use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory as ProductCollectionFactory ;
13
+ use Magento \Framework \DataObject ;
12
14
use Magento \Framework \Exception \InputException ;
13
15
use Magento \Framework \Exception \NoSuchEntityException ;
14
16
use Magento \Quote \Api \CartRepositoryInterface ;
15
17
use Magento \Quote \Api \Data \CartInterface ;
16
18
use Magento \Quote \Model \Cart \CustomerCartResolver ;
17
- use Magento \Quote \Model \Quote ;
18
19
use Magento \Quote \Model \GuestCart \GuestCartResolver ;
20
+ use Magento \Quote \Model \Quote ;
19
21
use Magento \Sales \Api \Data \OrderItemInterface ;
20
22
use Magento \Sales \Helper \Reorder as ReorderHelper ;
21
23
use Magento \Sales \Model \Order \Item ;
22
24
use Magento \Sales \Model \OrderFactory ;
23
25
use Magento \Sales \Model \ResourceModel \Order \Item \Collection as ItemCollection ;
24
- use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory as ProductCollectionFactory ;
25
26
use Psr \Log \LoggerInterface ;
26
27
27
28
/**
30
31
*/
31
32
class Reorder
32
33
{
34
+ /**
35
+ * Forbidden reorder item properties
36
+ */
37
+ private const FORBIDDEN_REORDER_PROPERTIES = ['custom_price ' ];
38
+
33
39
/**#@+
34
40
* Error message codes
35
41
*/
@@ -253,6 +259,7 @@ private function getOrderProducts(string $storeId, array $orderItemProductIds):
253
259
private function addItemToCart (OrderItemInterface $ orderItem , Quote $ cart , ProductInterface $ product ): void
254
260
{
255
261
$ infoBuyRequest = $ this ->orderInfoBuyRequestGetter ->getInfoBuyRequest ($ orderItem );
262
+ $ this ->sanitizeBuyRequest ($ infoBuyRequest );
256
263
257
264
$ addProductResult = null ;
258
265
try {
@@ -273,6 +280,21 @@ private function addItemToCart(OrderItemInterface $orderItem, Quote $cart, Produ
273
280
}
274
281
}
275
282
283
+ /**
284
+ * Removes forbidden reorder item properties
285
+ *
286
+ * @param DataObject $dataObject
287
+ * @return void
288
+ */
289
+ private function sanitizeBuyRequest (DataObject $ dataObject ): void
290
+ {
291
+ foreach (self ::FORBIDDEN_REORDER_PROPERTIES as $ forbiddenProp ) {
292
+ if ($ dataObject ->hasData ($ forbiddenProp )) {
293
+ $ dataObject ->unsetData ($ forbiddenProp );
294
+ }
295
+ }
296
+ }
297
+
276
298
/**
277
299
* Add order line item error
278
300
*
0 commit comments