Skip to content

Commit c780c15

Browse files
committed
Merge branch 'MC-41981' of https://github.com/magento-l3/magento2ce into PR-2021-08-18
2 parents 12dcafa + 738b461 commit c780c15

File tree

5 files changed

+262
-8
lines changed

5 files changed

+262
-8
lines changed

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,16 @@ public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $q
684684
foreach ($productOptions['options'] as $option) {
685685
if (in_array($option['option_type'], ['date', 'date_time', 'time', 'file'])) {
686686
$product->setSkipCheckRequiredOption(false);
687+
if ($option['option_type'] === 'file') {
688+
try {
689+
$formattedOptions[$option['option_id']] =
690+
$this->serializer->unserialize($option['option_value']);
691+
continue;
692+
} catch (\InvalidArgumentException $exception) {
693+
//log the exception as warning
694+
$this->_logger->warning($exception);
695+
}
696+
}
687697
$formattedOptions[$option['option_id']] =
688698
$buyRequest->getDataByKey('options')[$option['option_id']];
689699
continue;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Sales\Model\Reorder;
8+
9+
use Magento\Framework\DataObject;
10+
use Magento\Sales\Api\Data\OrderItemInterface;
11+
use Magento\Framework\Serialize\SerializerInterface;
12+
use Psr\Log\LoggerInterface;
13+
14+
/**
15+
* Gets info buy request from order info interface and process custom options
16+
*/
17+
class OrderInfoBuyRequestGetter
18+
{
19+
/**
20+
* @var LoggerInterface
21+
*/
22+
private $logger;
23+
24+
/**
25+
* @var SerializerInterface
26+
*/
27+
private $serializer;
28+
29+
/**
30+
* @param LoggerInterface $logger
31+
* @param SerializerInterface $serializer
32+
*/
33+
public function __construct(
34+
LoggerInterface $logger,
35+
SerializerInterface $serializer
36+
) {
37+
$this->logger = $logger;
38+
$this->serializer = $serializer;
39+
}
40+
41+
/**
42+
* Prepare Custom Option for order Item by unserializing custom options data
43+
*
44+
* @param OrderItemInterface $orderItem
45+
* @return DataObject
46+
*/
47+
public function getInfoBuyRequest(OrderItemInterface $orderItem): DataObject
48+
{
49+
$info = $orderItem->getProductOptionByCode('info_buyRequest');
50+
$options = $orderItem->getProductOptionByCode('options');
51+
52+
if (!empty($options) && is_array($info)) {
53+
foreach ($options as $option) {
54+
if (array_key_exists($option['option_id'], $info['options'])) {
55+
try {
56+
$value = $this->serializer->unserialize($option['option_value']);
57+
$info['options'][$option['option_id']] = $value;
58+
} catch (\InvalidArgumentException $exception) {
59+
$this->logger->warning($exception);
60+
}
61+
}
62+
}
63+
}
64+
65+
$infoBuyRequest = new DataObject($info);
66+
$infoBuyRequest->setQty($orderItem->getQtyOrdered());
67+
68+
return $infoBuyRequest;
69+
}
70+
71+
}

app/code/Magento/Sales/Model/Reorder/Reorder.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Sales\Model\OrderFactory;
2323
use Magento\Sales\Model\ResourceModel\Order\Item\Collection as ItemCollection;
2424
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
25+
use Psr\Log\LoggerInterface;
2526

2627
/**
2728
* Allows customer quickly to reorder previously added products and put them to the Cart
@@ -63,7 +64,7 @@ class Reorder
6364
private $reorderHelper;
6465

6566
/**
66-
* @var \Psr\Log\LoggerInterface
67+
* @var LoggerInterface
6768
*/
6869
private $logger;
6970

@@ -92,23 +93,30 @@ class Reorder
9293
*/
9394
private $guestCartResolver;
9495

96+
/**
97+
* @var OrderInfoBuyRequestGetter
98+
*/
99+
private $orderInfoBuyRequestGetter;
100+
95101
/**
96102
* @param OrderFactory $orderFactory
97103
* @param CustomerCartResolver $customerCartProvider
98104
* @param GuestCartResolver $guestCartResolver
99105
* @param CartRepositoryInterface $cartRepository
100106
* @param ReorderHelper $reorderHelper
101-
* @param \Psr\Log\LoggerInterface $logger
107+
* @param LoggerInterface $logger
102108
* @param ProductCollectionFactory $productCollectionFactory
109+
* @param OrderInfoBuyRequestGetter $orderInfoBuyRequestGetter
103110
*/
104111
public function __construct(
105112
OrderFactory $orderFactory,
106113
CustomerCartResolver $customerCartProvider,
107114
GuestCartResolver $guestCartResolver,
108115
CartRepositoryInterface $cartRepository,
109116
ReorderHelper $reorderHelper,
110-
\Psr\Log\LoggerInterface $logger,
111-
ProductCollectionFactory $productCollectionFactory
117+
LoggerInterface $logger,
118+
ProductCollectionFactory $productCollectionFactory,
119+
OrderInfoBuyRequestGetter $orderInfoBuyRequestGetter
112120
) {
113121
$this->orderFactory = $orderFactory;
114122
$this->cartRepository = $cartRepository;
@@ -117,6 +125,7 @@ public function __construct(
117125
$this->customerCartProvider = $customerCartProvider;
118126
$this->guestCartResolver = $guestCartResolver;
119127
$this->productCollectionFactory = $productCollectionFactory;
128+
$this->orderInfoBuyRequestGetter = $orderInfoBuyRequestGetter;
120129
}
121130

122131
/**
@@ -243,13 +252,11 @@ private function getOrderProducts(string $storeId, array $orderItemProductIds):
243252
*/
244253
private function addItemToCart(OrderItemInterface $orderItem, Quote $cart, ProductInterface $product): void
245254
{
246-
$info = $orderItem->getProductOptionByCode('info_buyRequest');
247-
$info = new \Magento\Framework\DataObject($info);
248-
$info->setQty($orderItem->getQtyOrdered());
255+
$infoBuyRequest = $this->orderInfoBuyRequestGetter->getInfoBuyRequest($orderItem);
249256

250257
$addProductResult = null;
251258
try {
252-
$addProductResult = $cart->addProduct($product, $info);
259+
$addProductResult = $cart->addProduct($product, $infoBuyRequest);
253260
} catch (\Magento\Framework\Exception\LocalizedException $e) {
254261
$this->addError($this->getCartItemErrorMessage($orderItem, $product, $e->getMessage()));
255262
} catch (\Throwable $e) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminReorderProductWithCustomOptionsTest" extends="StorefrontCustomerReorderProductWithCustomOptionsTest">
11+
<annotations>
12+
<stories value="Admin reorder product with custom options"/>
13+
<title value="Make reorder as Admin"/>
14+
<description value="Make reorder as admin on admin order page with simple product custom options"/>
15+
<severity value="CRITICAL"/>
16+
<testCaseId value="MC-42974"/>
17+
<useCaseId value="MC-41981" />
18+
<group value="sales"/>
19+
</annotations>
20+
21+
<!-- Reorder created order -->
22+
<actionGroup ref="OpenOrderByIdActionGroup" after="placeReorder" stepKey="adminOpenOrderById">
23+
<argument name="orderId" value="{$grabOrderNumber}"/>
24+
</actionGroup>
25+
<actionGroup ref="AdminStartReorderFromOrderPageActionGroup" after="adminOpenOrderById" stepKey="adminStartReorder"/>
26+
<actionGroup ref="AdminSubmitOrderActionGroup" after="adminStartReorder" stepKey="adminSubmitOrder"/>
27+
</test>
28+
</tests>
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="StorefrontCustomerReorderProductWithCustomOptionsTest">
11+
<annotations>
12+
<stories value="Reorder product with custom options"/>
13+
<title value="Make reorder as customer on frontend"/>
14+
<description value="Make reorder as customer on Frontend with simple product custom options"/>
15+
<severity value="CRITICAL"/>
16+
<testCaseId value="MC-42899"/>
17+
<useCaseId value="MC-41981" />
18+
<group value="sales"/>
19+
</annotations>
20+
21+
<before>
22+
<!-- Login As Admin -->
23+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
24+
<!-- Create Customer -->
25+
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
26+
<!-- Create Simple Category -->
27+
<createData entity="_defaultCategory" stepKey="initialCategoryEntity"/>
28+
<!-- Create Simple Product -->
29+
<createData entity="defaultSimpleProduct" stepKey="initialSimpleProduct"/>
30+
</before>
31+
32+
<after>
33+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
34+
<deleteData createDataKey="initialCategoryEntity" stepKey="deleteDefaultCategory"/>
35+
<deleteData createDataKey="initialSimpleProduct" stepKey="deleteSimpleProduct"/>
36+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
37+
</after>
38+
39+
<!-- Search default simple product in the grid -->
40+
<actionGroup ref="AdminClearFiltersActionGroup" stepKey="openProductCatalogPage"/>
41+
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="clickFirstRowToOpenDefaultSimpleProduct">
42+
<argument name="product" value="$$initialSimpleProduct$$"/>
43+
</actionGroup>
44+
45+
<!-- Open custom option panel -->
46+
<click selector="{{AdminProductCustomizableOptionsSection.customizableOptions}}" stepKey="openCustomizableOptions"/>
47+
<waitForPageLoad stepKey="waitForCustomOptionsOpen"/>
48+
49+
<!-- Add First Drop Down Custom Options -->
50+
<actionGroup ref="AdminAddProductCustomOptionActionGroup" stepKey="addProductCustomDropDownOptionFirst">
51+
<argument name="customOptionTitle" value="{{ProductOptionDropDown.title}}"/>
52+
<argument name="customOptionType" value="Drop-down"/>
53+
</actionGroup>
54+
<actionGroup ref="AdminAddTitleAndPriceValueToCustomOptionActionGroup" stepKey="addTitleAndPriceValueToCustomDropDownOptionFirst">
55+
<argument name="optionValue" value="ProductOptionValueDropdown1"/>
56+
</actionGroup>
57+
58+
<!-- Add Custom file option -->
59+
<actionGroup ref="AddProductCustomOptionFileActionGroup" stepKey="addFileOption">
60+
<argument name="option" value="ProductOptionFile"/>
61+
</actionGroup>
62+
63+
<!-- Add Second Drop Down Custom Options -->
64+
<!-- As per issue both drop-down are fixed valued so used again ProductOptionValueDropdown1 DataEntity -->
65+
<actionGroup ref="AdminAddProductCustomOptionActionGroup" stepKey="addProductCustomDropDownOptionSecond">
66+
<argument name="customOptionTitle" value="{{ProductOptionDropDownWithLongValuesTitle.title}}"/>
67+
<argument name="customOptionType" value="Drop-down"/>
68+
</actionGroup>
69+
<actionGroup ref="AdminAddTitleAndPriceValueToCustomOptionActionGroup" stepKey="addTitleAndPriceValueToCustomDropDownOptionSecond">
70+
<argument name="optionValue" value="ProductOptionValueDropdown2"/>
71+
</actionGroup>
72+
73+
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct"/>
74+
75+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
76+
77+
<!-- Login to storefront as Customer -->
78+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="customerLogin">
79+
<argument name="Customer" value="$$createCustomer$$"/>
80+
</actionGroup>
81+
82+
<!-- Place Order as Customer -->
83+
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductPage">
84+
<argument name="productUrl" value="$$initialSimpleProduct.custom_attributes[url_key]$$"/>
85+
</actionGroup>
86+
87+
<!-- Select Option From First DropDown option -->
88+
<actionGroup ref="StorefrontProductPageSelectDropDownOptionValueActionGroup" stepKey="selectFirstOption">
89+
<argument name="attributeLabel" value="{{ProductOptionDropDown.title}}"/>
90+
<argument name="optionLabel" value="{{ProductOptionValueDropdown1.title}}"/>
91+
</actionGroup>
92+
93+
<!-- Attach file option -->
94+
<actionGroup ref="StorefrontAttachOptionFileActionGroup" stepKey="selectAndAttachFile"/>
95+
96+
<!-- Select Option From Second DropDown option -->
97+
<actionGroup ref="StorefrontProductPageSelectDropDownOptionValueActionGroup" stepKey="selectSecondOption">
98+
<argument name="attributeLabel" value="{{ProductOptionDropDownWithLongValuesTitle.title}}"/>
99+
<argument name="optionLabel" value="{{ProductOptionValueDropdown2.title}}"/>
100+
</actionGroup>
101+
102+
<!-- Add Product to Card -->
103+
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addProductToCart">
104+
<argument name="product" value="$$initialSimpleProduct$$"/>
105+
<argument name="productCount" value="1"/>
106+
</actionGroup>
107+
108+
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="openCart"/>
109+
<actionGroup ref="PlaceOrderWithLoggedUserActionGroup" stepKey="placeOrder"/>
110+
<grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabOrderNumber"/>
111+
112+
<!-- Log out from storefront as Customer -->
113+
<actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="customerLogOut"/>
114+
115+
<!-- Again Login As Admin -->
116+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdminForSubmitShipment"/>
117+
118+
<!-- Open order -->
119+
<actionGroup ref="OpenOrderByIdActionGroup" stepKey="openOrderForCreatingShipment">
120+
<argument name="orderId" value="{$grabOrderNumber}"/>
121+
</actionGroup>
122+
123+
<!-- Create Shipment for the order -->
124+
<actionGroup ref="GoToShipmentIntoOrderActionGroup" stepKey="startCreateShipment"/>
125+
<actionGroup ref="SubmitShipmentIntoOrderActionGroup" stepKey="submitShipment"/>
126+
127+
<!-- Login to storefront as Customer for Reorder -->
128+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="customerLoginForReorder">
129+
<argument name="Customer" value="$$createCustomer$$"/>
130+
</actionGroup>
131+
132+
<!-- Make reorder -->
133+
<actionGroup ref="StorefrontCustomerReorderActionGroup" stepKey="makeReorder">
134+
<argument name="orderNumber" value="{$grabOrderNumber}"/>
135+
</actionGroup>
136+
<actionGroup ref="PlaceOrderWithLoggedUserActionGroup" stepKey="placeReorder"/>
137+
</test>
138+
</tests>

0 commit comments

Comments
 (0)