Skip to content

Commit b6d071f

Browse files
committed
MC-5233: DateTime product attributes support
1 parent 1eb8d4b commit b6d071f

File tree

7 files changed

+14
-15
lines changed

7 files changed

+14
-15
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Main.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private function removeUnusedFields(): void
113113
$fieldsToRemove = ['attribute_code', 'is_unique', 'frontend_class'];
114114
foreach ($fieldset->getElements() as $element) {
115115
/** @var AbstractElement $element */
116-
if (substr($element->getId(), 0, strlen('default_value')) == 'default_value') {
116+
if (substr($element->getId(), 0, strlen('default_value')) === 'default_value') {
117117
$fieldsToRemove[] = $element->getId();
118118
}
119119
}

app/code/Magento/Catalog/Ui/Component/ColumnFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ private function getDateConfig(ProductAttributeInterface $attribute): array
131131
$dateFormat = $isDatetime
132132
? $this->timezone->getDateTimeFormat(\IntlDateFormatter::MEDIUM)
133133
: $this->timezone->getDateFormat(\IntlDateFormatter::MEDIUM);
134-
$timeZone = $isDatetime
134+
$timezone = $isDatetime
135135
? $this->timezone->getConfigTimezone()
136136
: $this->timezone->getDefaultTimezone();
137137

138138
return [
139-
'timeZone' => $timeZone,
139+
'timezone' => $timezone,
140140
'dateFormat' => $dateFormat,
141-
'options' => [ 'showsTime' => $isDatetime],
141+
'options' => ['showsTime' => $isDatetime],
142142
];
143143
}
144144

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ private function customizeWysiwyg(ProductAttributeInterface $attribute, array $m
957957
* @param array $meta
958958
* @return array
959959
*/
960-
private function customizeDatetimeAttribute(array $meta)
960+
private function customizeDatetimeAttribute(array $meta): array
961961
{
962962
$meta['arguments']['data']['config']['options']['showsTime'] = 1;
963963

app/code/Magento/Eav/Model/Entity/Attribute/Frontend/Datetime.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public function getValue(\Magento\Framework\DataObject $object)
4444
$value = parent::getValue($object);
4545

4646
if ($value) {
47-
$timeType = $this->getAttribute()->getFrontendInput() === 'datetime'
47+
$showTime = $this->getAttribute()->getFrontendInput() === 'datetime'
4848
? \IntlDateFormatter::MEDIUM : \IntlDateFormatter::NONE;
4949
$data = $this->_localeDate->formatDateTime(
5050
new \DateTime($value),
5151
\IntlDateFormatter::MEDIUM,
52-
$timeType
52+
$showTime
5353
);
5454
}
5555

app/code/Magento/Ui/Component/Form/Element/DataType/Date.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,20 @@ public function convertDate($date, $hour = 0, $minute = 0, $second = 0, $setUtcT
127127
* Convert given date to default (UTC) timezone
128128
*
129129
* @param string $date
130-
* @param bool $setUtcTimeZone
130+
* @param bool $setUtcTimezone
131131
* @return \DateTime|null
132132
*/
133-
public function convertDatetime(string $date, bool $setUtcTimeZone = true): ?\DateTime
133+
public function convertDatetime(string $date, bool $setUtcTimezone = true): ?\DateTime
134134
{
135135
try {
136136
$date = rtrim($date, 'Z');
137137
$dateObj = new \DateTime($date, new \DateTimeZone($this->localeDate->getConfigTimezone()));
138138
//convert store date to default date in UTC timezone without DST
139-
if ($setUtcTimeZone) {
139+
if ($setUtcTimezone) {
140140
$dateObj->setTimezone(new \DateTimeZone('UTC'));
141141
}
142142
return $dateObj;
143-
} catch (\Exception $e) {
143+
} catch (\Throwable $e) {
144144
return null;
145145
}
146146
}

app/code/Magento/Ui/view/base/web/js/grid/columns/date.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ define([
4646
moment.locale(this.storeLocale, utils.extend({}, this.calendarConfig));
4747
}
4848

49-
if (!_.isUndefined(this.timeZone)) {
50-
date = date.tz(this.timeZone);
49+
if (!_.isUndefined(this.timezone)) {
50+
date = date.tz(this.timezone);
5151
}
5252

5353
date = date.isValid() && value[this.index] ?

dev/tests/integration/testsuite/Magento/Eav/Model/Entity/AttributeTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\Eav\Model\Entity;
99

10-
use Magento\Framework\Exception\LocalizedException;
1110
use Magento\Framework\Locale\ResolverInterface;
1211
use Magento\Framework\ObjectManagerInterface;
1312
use Magento\TestFramework\Helper\Bootstrap;
@@ -103,7 +102,7 @@ public function beforeSaveDataProvider()
103102
* @param string $locale
104103
* @param string $expected
105104
* @dataProvider beforeSaveErrorDataDataProvider
106-
* @expectedException LocalizedException
105+
* @expectedException \Magento\Framework\Exception\LocalizedException
107106
*/
108107
public function testBeforeSaveErrorData($defaultValue, $backendType, $locale, $expected)
109108
{

0 commit comments

Comments
 (0)