7
7
namespace Magento \Catalog \Model \Product \Option \Type ;
8
8
9
9
use Magento \Catalog \Api \Data \ProductCustomOptionInterface ;
10
+ use function PHPUnit \Framework \matches ;
10
11
11
12
/**
12
13
* Catalog product option date type
@@ -72,6 +73,11 @@ public function validateUserValue($values)
72
73
$ dateValid = true ;
73
74
if ($ this ->_dateExists ()) {
74
75
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
+ }
75
81
$ dateValid = isset ($ value ['date ' ]) && preg_match ('/^\d{1,4}.+\d{1,4}.+\d{1,4}$/ ' , $ value ['date ' ]);
76
82
} else {
77
83
$ dateValid = isset (
@@ -184,8 +190,10 @@ public function prepareForCart()
184
190
$ date = (new \DateTime ())->setTimestamp ($ timestamp );
185
191
$ result = $ date ->format ('Y-m-d H:i:s ' );
186
192
193
+ $ originDate = (isset ($ value ['date ' ]) && $ value ['date ' ] != '' ) ? $ value ['date ' ] : null ;
194
+
187
195
// Save date in internal format to avoid locale date bugs
188
- $ this ->_setInternalInRequest ($ result );
196
+ $ this ->_setInternalInRequest ($ result, $ originDate );
189
197
190
198
return $ result ;
191
199
} else {
@@ -352,9 +360,10 @@ public function getYearEnd()
352
360
* Save internal value of option in infoBuy_request
353
361
*
354
362
* @param string $internalValue Datetime value in internal format
363
+ * @param string|null $originDate date value in origin format
355
364
* @return void
356
365
*/
357
- protected function _setInternalInRequest ($ internalValue )
366
+ protected function _setInternalInRequest ($ internalValue, $ originDate = null )
358
367
{
359
368
$ requestOptions = $ this ->getRequest ()->getOptions ();
360
369
if (!isset ($ requestOptions [$ this ->getOption ()->getId ()])) {
@@ -364,6 +373,9 @@ protected function _setInternalInRequest($internalValue)
364
373
$ requestOptions [$ this ->getOption ()->getId ()] = [];
365
374
}
366
375
$ requestOptions [$ this ->getOption ()->getId ()]['date_internal ' ] = $ internalValue ;
376
+ if ($ originDate ) {
377
+ $ requestOptions [$ this ->getOption ()->getId ()]['date ' ] = $ originDate ;
378
+ }
367
379
$ this ->getRequest ()->setOptions ($ requestOptions );
368
380
}
369
381
0 commit comments