Skip to content

Commit a38744a

Browse files
committed
Merge remote-tracking branch 'origin/MC-39317' into 2.4-develop-pr120
2 parents 03e3812 + 2a0b9ac commit a38744a

File tree

4 files changed

+158
-1
lines changed

4 files changed

+158
-1
lines changed

app/code/Magento/Catalog/Model/ProductOptionProcessor.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ private function getUrlBuilder()
152152
*/
153153
private function isDateWithDateInternal(array $optionValue): bool
154154
{
155-
return array_key_exists('date_internal', $optionValue) && array_key_exists('date', $optionValue);
155+
$hasDate = !empty($optionValue['day'])
156+
&& !empty($optionValue['month'])
157+
&& !empty($optionValue['year']);
158+
159+
$hasTime = !empty($optionValue['hour'])
160+
&& isset($optionValue['minute']);
161+
162+
$hasDateInternal = !empty($optionValue['date_internal']);
163+
164+
return $hasDateInternal && ($hasDate || $hasTime || !empty($optionValue['date']));
156165
}
157166
}

dev/tests/integration/testsuite/Magento/Customer/Controller/Account/CreatePostTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
use Magento\Customer\Api\CustomerRepositoryInterface;
1111
use Magento\Customer\Api\Data\CustomerInterface;
1212
use Magento\Customer\Model\CustomerRegistry;
13+
use Magento\Customer\Model\Delegation\Storage as DelegatedStorage;
1314
use Magento\Framework\App\Http;
1415
use Magento\Framework\App\Request\Http as HttpRequest;
1516
use Magento\Framework\Exception\NoSuchEntityException;
1617
use Magento\Framework\Message\MessageInterface;
1718
use Magento\Framework\Stdlib\CookieManagerInterface;
1819
use Magento\Framework\UrlInterface;
20+
use Magento\Sales\Model\Order;
21+
use Magento\Sales\Model\Order\Item as OrderItem;
1922
use Magento\Store\Model\StoreManagerInterface;
2023
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
2124
use Magento\TestFramework\Request;
@@ -96,6 +99,52 @@ public function testNoFormKeyCreatePostAction(): void
9699
);
97100
}
98101

102+
/**
103+
* Check that DateTime option is NOT changed after creating Customer account for which guest order was placed.
104+
*
105+
* @return void
106+
* @magentoDataFixture Magento/Sales/_files/guest_order_with_product_and_custom_options.php
107+
*/
108+
public function testCreateCustomerAccountAfterIssuingGuestOrder(): void
109+
{
110+
/** @var Order $order */
111+
$order = $this->_objectManager->create(Order::class);
112+
$order->loadByIncrementId('100000001');
113+
114+
/** @var CustomerInterface $customer */
115+
$customer = $this->_objectManager->create(CustomerInterface::class);
116+
117+
/** @var DelegatedStorage $delegatedStorage */
118+
$delegatedStorage = $this->_objectManager->get(DelegatedStorage::class);
119+
$delegatedStorage->storeNewOperation($customer, ['__sales_assign_order_id' => $order->getId()]);
120+
121+
$this->fillRequestWithAccountData('customer@example.com');
122+
$this->dispatch('customer/account/createPost');
123+
124+
$this->assertRedirect($this->stringEndsWith('customer/account/'));
125+
$this->assertSessionMessages(
126+
$this->containsEqual(
127+
(string)__('Thank you for registering with %1.', $this->storeManager->getStore()->getFrontendName())
128+
),
129+
MessageInterface::TYPE_SUCCESS
130+
);
131+
132+
$expectedResult = [
133+
'year' => '2021',
134+
'month' => '9',
135+
'day' => '9',
136+
'hour' => '2',
137+
'minute' => '2',
138+
'day_part' => 'am',
139+
'date_internal' => '2021-09-09 02:02:00',
140+
];
141+
/** @var OrderItem $orderItem */
142+
$orderItem = $order->getItemsCollection()->getFirstItem();
143+
$actualResult = current($orderItem->getBuyRequest()->getOptions());
144+
$this->assertIsArray($actualResult);
145+
$this->assertEquals($expectedResult, $actualResult);
146+
}
147+
99148
/**
100149
* @magentoDbIsolation enabled
101150
* @magentoAppIsolation enabled
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Model\ProductRepository;
9+
use Magento\Sales\Api\Data\OrderAddressInterface;
10+
use Magento\Sales\Api\Data\OrderPaymentInterface;
11+
use Magento\Sales\Model\Order;
12+
use Magento\Sales\Model\Order\Item as OrderItem;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
16+
17+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple.php');
18+
19+
$addressData = include __DIR__ . '/../../../Magento/Sales/_files/address_data.php';
20+
21+
$objectManager = Bootstrap::getObjectManager();
22+
/** @var OrderAddressInterface $billingAddress */
23+
$billingAddress = $objectManager->create(OrderAddressInterface::class, ['data' => $addressData]);
24+
$billingAddress->setAddressType('billing');
25+
26+
$shippingAddress = clone $billingAddress;
27+
$shippingAddress->setId(null)->setAddressType('shipping');
28+
29+
/** @var OrderPaymentInterface $payment */
30+
$payment = $objectManager->create(OrderPaymentInterface::class);
31+
$payment->setMethod('checkmo');
32+
33+
/** @var ProductRepository $productRepository */
34+
$productRepository = $objectManager->get(ProductRepository::class);
35+
$productRepository->cleanCache();
36+
37+
$optionValuesByType = [
38+
'field' => 'Test value',
39+
'date_time' => [
40+
'year' => '2021',
41+
'month' => '9',
42+
'day' => '9',
43+
'hour' => '2',
44+
'minute' => '2',
45+
'day_part' => 'am',
46+
'date_internal' => '2021-09-09 02:02:00',
47+
],
48+
'drop_down' => '3-1-select',
49+
'radio' => '4-1-radio',
50+
];
51+
52+
$requestInfo = ['options' => []];
53+
$product = $productRepository->get('simple');
54+
$productOptions = $product->getOptions();
55+
foreach ($productOptions as $option) {
56+
$requestInfo['options'][$option->getOptionId()] = $optionValuesByType[$option->getType()];
57+
}
58+
59+
/** @var OrderItem $orderItem */
60+
$orderItem = $objectManager->create(OrderItem::class);
61+
$orderItem->setProductId($product->getId());
62+
$orderItem->setSku($product->getSku());
63+
$orderItem->setQtyOrdered(1);
64+
$orderItem->setBasePrice($product->getPrice());
65+
$orderItem->setPrice($product->getPrice());
66+
$orderItem->setRowTotal($product->getPrice());
67+
$orderItem->setProductType($product->getTypeId());
68+
$orderItem->setProductOptions(['info_buyRequest' => $requestInfo]);
69+
70+
/** @var Order $order */
71+
$order = $objectManager->create(Order::class);
72+
$order->setIncrementId('100000001');
73+
$order->setState(Order::STATE_NEW);
74+
$order->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_NEW));
75+
$order->setCustomerIsGuest(true);
76+
$order->setCustomerEmail('customer@example.com');
77+
$order->setCustomerFirstname('firstname');
78+
$order->setCustomerLastname('lastname');
79+
$order->setBillingAddress($billingAddress);
80+
$order->setShippingAddress($shippingAddress);
81+
$order->setAddresses([$billingAddress, $shippingAddress]);
82+
$order->setPayment($payment);
83+
$order->addItem($orderItem);
84+
$order->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId());
85+
$order->setSubtotal(100);
86+
$order->setBaseSubtotal(100);
87+
$order->setBaseGrandTotal(100);
88+
$order->save();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
9+
10+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_rollback.php');
11+
Resolver::getInstance()->requireDataFixture('Magento/Sales/_files/default_rollback.php');

0 commit comments

Comments
 (0)