Skip to content

Commit 5b3b234

Browse files
committed
AC-13535: Minimum and maximum value validation does not work for DOB attribute on Storefront
1 parent 0a68eaa commit 5b3b234

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

app/code/Magento/Customer/Plugin/ValidateDobOnSave.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Eav\Model\Config as EavConfig;
1414
use Magento\Framework\Exception\InputException;
1515
use Magento\Framework\Serialize\Serializer\Json as JsonSerializer;
16+
use Magento\Framework\Stdlib\DateTime;
1617

1718
class ValidateDobOnSave
1819
{
@@ -86,13 +87,19 @@ public function aroundSave(
8687
$minDate = $this->parseDate($min);
8788
$maxDate = $this->parseDate($max);
8889

89-
$dobKey = $dobDate->format('Y-m-d');
90+
$dobKey = $dobDate->format(DateTime::DATE_PHP_FORMAT);
9091

91-
if ($minDate && $dobKey < $minDate->format('Y-m-d')) {
92-
throw new InputException(__('Date of Birth must be on or after %1.', $minDate->format('Y-m-d')));
92+
if ($minDate && $dobKey < $minDate->format(DateTime::DATE_PHP_FORMAT)) {
93+
throw new InputException(__(
94+
'Date of Birth must be on or after %1.',
95+
$minDate->format(DateTime::DATE_PHP_FORMAT)
96+
));
9397
}
94-
if ($maxDate && $dobKey > $maxDate->format('Y-m-d')) {
95-
throw new InputException(__('Date of Birth must be on or before %1.', $maxDate->format('Y-m-d')));
98+
if ($maxDate && $dobKey > $maxDate->format(DateTime::DATE_PHP_FORMAT)) {
99+
throw new InputException(__(
100+
'Date of Birth must be on or before %1.',
101+
$maxDate->format(DateTime::DATE_PHP_FORMAT)
102+
));
96103
}
97104
}
98105

0 commit comments

Comments
 (0)