Skip to content

Commit 3e2bf19

Browse files
MC-36405: Reorder is not working with custom options date with JavaScript Calendar enabled
1 parent 386cbe7 commit 3e2bf19

File tree

1 file changed

+14
-2
lines changed
  • app/code/Magento/Catalog/Model/Product/Option/Type

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Catalog\Model\Product\Option\Type;
88

99
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
10+
use function PHPUnit\Framework\matches;
1011

1112
/**
1213
* Catalog product option date type
@@ -72,6 +73,11 @@ public function validateUserValue($values)
7273
$dateValid = true;
7374
if ($this->_dateExists()) {
7475
if ($this->useCalendar()) {
76+
if (is_string($value) && preg_match('/^\d{1,4}.+\d{1,4}.+\d{1,4},+(\w|\W)*$/', $value)) {
77+
$value = [
78+
'date' => preg_replace('/,([^,]+),?$/', '', $value),
79+
];
80+
}
7581
$dateValid = isset($value['date']) && preg_match('/^\d{1,4}.+\d{1,4}.+\d{1,4}$/', $value['date']);
7682
} else {
7783
$dateValid = isset(
@@ -184,8 +190,10 @@ public function prepareForCart()
184190
$date = (new \DateTime())->setTimestamp($timestamp);
185191
$result = $date->format('Y-m-d H:i:s');
186192

193+
$originDate = (isset($value['date']) && $value['date'] != '') ? $value['date'] : null;
194+
187195
// Save date in internal format to avoid locale date bugs
188-
$this->_setInternalInRequest($result);
196+
$this->_setInternalInRequest($result, $originDate);
189197

190198
return $result;
191199
} else {
@@ -352,9 +360,10 @@ public function getYearEnd()
352360
* Save internal value of option in infoBuy_request
353361
*
354362
* @param string $internalValue Datetime value in internal format
363+
* @param string|null $originDate date value in origin format
355364
* @return void
356365
*/
357-
protected function _setInternalInRequest($internalValue)
366+
protected function _setInternalInRequest($internalValue, $originDate = null)
358367
{
359368
$requestOptions = $this->getRequest()->getOptions();
360369
if (!isset($requestOptions[$this->getOption()->getId()])) {
@@ -364,6 +373,9 @@ protected function _setInternalInRequest($internalValue)
364373
$requestOptions[$this->getOption()->getId()] = [];
365374
}
366375
$requestOptions[$this->getOption()->getId()]['date_internal'] = $internalValue;
376+
if ($originDate) {
377+
$requestOptions[$this->getOption()->getId()]['date'] = $originDate;
378+
}
367379
$this->getRequest()->setOptions($requestOptions);
368380
}
369381

0 commit comments

Comments
 (0)