Skip to content

Commit 1140fcc

Browse files
MC-36405: Reorder is not working with custom options date with JavaScript Calendar enabled
1 parent d88eba2 commit 1140fcc

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

app/code/Magento/Catalog/Model/Product/Option/Type/Date.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public function validateUserValue($values)
7272
$dateValid = true;
7373
if ($this->_dateExists()) {
7474
if ($this->useCalendar()) {
75+
/* Fixed validation if the date was not saved correctly after re-saved the order
76+
for example: "09\/24\/2020,2020-09-24 00:00:00" */
7577
if (is_string($value) && preg_match('/^\d{1,4}.+\d{1,4}.+\d{1,4},+(\w|\W)*$/', $value)) {
7678
$value = [
7779
'date' => preg_replace('/,([^,]+),?$/', '', $value),

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,16 @@ class ProductOptionProcessor implements ProductOptionProcessorInterface
3232
*/
3333
private $urlBuilder;
3434

35-
/**
36-
* Serializer interface instance.
37-
*
38-
* @var Json
39-
*/
40-
private $serializer;
41-
4235
/**
4336
* @param DataObjectFactory $objectFactory
4437
* @param CustomOptionFactory $customOptionFactory
45-
* @param Json|null $serializer
4638
*/
4739
public function __construct(
4840
DataObjectFactory $objectFactory,
49-
CustomOptionFactory $customOptionFactory,
50-
Json $serializer = null
41+
CustomOptionFactory $customOptionFactory
5142
) {
5243
$this->objectFactory = $objectFactory;
5344
$this->customOptionFactory = $customOptionFactory;
54-
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
55-
->get(\Magento\Framework\Serialize\Serializer\Json::class);
5645
}
5746

5847
/**

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ protected function _initShippingAddressFromOrder(\Magento\Sales\Model\Order $ord
642642
* @param \Magento\Sales\Model\Order\Item $orderItem
643643
* @param int $qty
644644
* @return \Magento\Quote\Model\Quote\Item|string|$this
645+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
645646
*/
646647
public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $qty = null)
647648
{
@@ -667,9 +668,15 @@ public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $q
667668
if ($productOptions !== null && !empty($productOptions['options'])) {
668669
$formattedOptions = [];
669670
foreach ($productOptions['options'] as $option) {
671+
if (in_array($option['option_type'], ['date', 'date_time']) && $this->useFrontendCalendar()) {
672+
$product->setSkipCheckRequiredOption(false);
673+
break;
674+
}
670675
$formattedOptions[$option['option_id']] = $option['option_value'];
671676
}
672-
$buyRequest->setData('options', $formattedOptions);
677+
if (!empty($formattedOptions)) {
678+
$buyRequest->setData('options', $formattedOptions);
679+
}
673680
}
674681
$item = $this->getQuote()->addProduct($product, $buyRequest);
675682
if (is_string($item)) {
@@ -2113,4 +2120,17 @@ private function isAddressesAreEqual(Order $order)
21132120

21142121
return $shippingData == $billingData;
21152122
}
2123+
2124+
/**
2125+
* Use Calendar on frontend or not
2126+
*
2127+
* @return bool
2128+
*/
2129+
private function useFrontendCalendar(): bool
2130+
{
2131+
return (bool)$this->_scopeConfig->getValue(
2132+
'catalog/custom_options/use_calendar',
2133+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
2134+
);
2135+
}
21162136
}

0 commit comments

Comments
 (0)