Skip to content

Commit b85d00f

Browse files
committed
CE#34569: Added fixes after code review
- rolled back wrong fixes; - added additional logic fixes
1 parent 0a19738 commit b85d00f

File tree

3 files changed

+44
-50
lines changed

3 files changed

+44
-50
lines changed

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

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
/**
1212
* Catalog product option date type
1313
*
14-
* @author Magento Core Team <core@magentocommerce.com>
1514
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1615
*/
1716
class Date extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
@@ -218,32 +217,36 @@ public function prepareForCart()
218217
public function getFormattedOptionValue($optionValue)
219218
{
220219
if ($this->_formattedOptionValue === null) {
221-
if ($this->getOption()->getType() == ProductCustomOptionInterface::OPTION_TYPE_DATE) {
222-
$result = $this->_localeDate->formatDateTime(
223-
new \DateTime($optionValue),
224-
\IntlDateFormatter::MEDIUM,
225-
\IntlDateFormatter::NONE,
226-
null,
227-
'UTC'
228-
);
229-
} elseif ($this->getOption()->getType() == ProductCustomOptionInterface::OPTION_TYPE_DATE_TIME) {
230-
$result = $this->_localeDate->formatDateTime(
231-
new \DateTime($optionValue),
232-
\IntlDateFormatter::SHORT,
233-
\IntlDateFormatter::SHORT,
234-
null,
235-
'UTC'
236-
);
237-
} elseif ($this->getOption()->getType() == ProductCustomOptionInterface::OPTION_TYPE_TIME) {
238-
$result = $this->_localeDate->formatDateTime(
239-
new \DateTime($optionValue),
240-
\IntlDateFormatter::NONE,
241-
\IntlDateFormatter::SHORT,
242-
null,
243-
'UTC'
244-
);
245-
} else {
246-
$result = $optionValue;
220+
switch ($this->getOption()->getType()) {
221+
case ProductCustomOptionInterface::OPTION_TYPE_DATE:
222+
$result = $this->_localeDate->formatDateTime(
223+
new \DateTime($optionValue),
224+
\IntlDateFormatter::MEDIUM,
225+
\IntlDateFormatter::NONE,
226+
null,
227+
'UTC'
228+
);
229+
break;
230+
case ProductCustomOptionInterface::OPTION_TYPE_DATE_TIME:
231+
$result = $this->_localeDate->formatDateTime(
232+
new \DateTime($optionValue),
233+
\IntlDateFormatter::SHORT,
234+
\IntlDateFormatter::SHORT,
235+
null,
236+
'UTC'
237+
);
238+
break;
239+
case ProductCustomOptionInterface::OPTION_TYPE_TIME:
240+
$result = $this->_localeDate->formatDateTime(
241+
new \DateTime($optionValue),
242+
\IntlDateFormatter::NONE,
243+
\IntlDateFormatter::SHORT,
244+
null,
245+
'UTC'
246+
);
247+
break;
248+
default:
249+
$result = $optionValue;
247250
}
248251
$this->_formattedOptionValue = $result;
249252
}
@@ -302,7 +305,9 @@ public function prepareOptionValueForRequest($optionValue)
302305
$infoBuyRequest = $confItem->getOptionByCode('info_buyRequest');
303306
try {
304307
$value = $this->serializer->unserialize($infoBuyRequest->getValue());
305-
if (is_array($value) && isset($value['options']) && isset($value['options'][$this->getOption()->getId()])
308+
309+
if (
310+
is_array($value) && isset($value['options']) && isset($value['options'][$this->getOption()->getId()])
306311
) {
307312
return $value['options'][$this->getOption()->getId()];
308313
} else {
@@ -341,12 +346,9 @@ public function is24hTimeFormat()
341346
public function getYearStart()
342347
{
343348
$_range = $this->getConfigData('year_range') !== null
344-
? explode(',', $this->getConfigData('year_range')) : [];
345-
if (isset($_range[0]) && !empty($_range[0])) {
346-
return $_range[0];
347-
} else {
348-
return date('Y');
349-
}
349+
? explode(',', $this->getConfigData('year_range'))
350+
: [];
351+
return (isset($_range[0]) && !empty($_range[0])) ? $_range[0] : date('Y');
350352
}
351353

352354
/**
@@ -357,12 +359,9 @@ public function getYearStart()
357359
public function getYearEnd()
358360
{
359361
$_range = $this->getConfigData('year_range') !== null
360-
? explode(',', $this->getConfigData('year_range')) : [];
361-
if (isset($_range[1]) && !empty($_range[1])) {
362-
return $_range[1];
363-
} else {
364-
return date('Y');
365-
}
362+
? explode(',', $this->getConfigData('year_range'))
363+
: [];
364+
return (isset($_range[1]) && !empty($_range[1])) ? $_range[1] : date('Y');
366365
}
367366

368367
/**

app/code/Magento/Catalog/Ui/DataProvider/CatalogEavValidationRules.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,19 @@ public function build(ProductAttributeInterface $attribute, array $data)
3434
}
3535

3636
$validationClasses = $attribute->getFrontendClass()
37-
? explode(' ', $attribute->getFrontendClass()) : [];
37+
? explode(' ', $attribute->getFrontendClass())
38+
: [];
3839

3940
foreach ($validationClasses as $class) {
4041
if (preg_match('/^maximum-length-(\d+)$/', $class, $matches)) {
41-
$rules['max_text_length'][] = $matches[1];
42+
$rules = array_merge($rules, ['max_text_length' => $matches[1]]);
4243
continue;
4344
}
4445
if (preg_match('/^minimum-length-(\d+)$/', $class, $matches)) {
45-
$rules['min_text_length'][] = $matches[1];
46+
$rules = array_merge($rules, ['min_text_length' => $matches[1]]);
4647
continue;
4748
}
4849

49-
if (isset($rules['max_text_length'])) {
50-
$rules['max_text_length'] = array_merge([], ...$rules['max_text_length']);
51-
}
52-
if (isset($rules['min_text_length'])) {
53-
$rules['min_text_length'] = array_merge([], ...$rules['min_text_length']);
54-
}
5550
$rules = $this->mapRules($class, $rules);
5651
}
5752

app/code/Magento/Tax/Model/Calculation/Rule/Validator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function isValid($value)
7373
}
7474

7575
// Code is required
76-
if ($value->getCode() !== null || !\Zend_Validate::is(trim($value->getCode()), 'NotEmpty')) {
76+
if ($value->getCode() === null || !\Zend_Validate::is(trim($value->getCode()), 'NotEmpty')) {
7777
$this->addErrorMessage(
7878
$messages,
7979
'"%fieldName" is required. Enter and try again.',

0 commit comments

Comments
 (0)