Skip to content

Commit f86925f

Browse files
committed
MAGETWO-58516: Product catalog Import/export – Date & Timezone issue. Other fields.
1 parent 7988331 commit f86925f

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
127127
*/
128128
protected $_attributeTypes = [];
129129

130+
/**
131+
* Attributes defined by user
132+
*
133+
* @var array
134+
*/
135+
protected $userDefinedAttributes = [];
136+
130137
/**
131138
* Product collection
132139
*
@@ -261,7 +268,11 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
261268
*/
262269
protected $dateAttrCodes = [
263270
'special_from_date',
264-
'special_to_date'
271+
'special_to_date',
272+
'news_from_date',
273+
'news_to_date',
274+
'custom_design_from',
275+
'custom_design_to'
265276
];
266277

267278
/**
@@ -910,20 +921,25 @@ protected function collectRawData()
910921
}
911922
$fieldName = isset($this->_fieldsMap[$code]) ? $this->_fieldsMap[$code] : $code;
912923

913-
if (in_array($code, $this->dateAttrCodes)) {
914-
$attrValue = $this->_localeDate->formatDateTime(
915-
new \DateTime($attrValue),
916-
\IntlDateFormatter::SHORT,
917-
\IntlDateFormatter::NONE,
918-
null,
919-
date_default_timezone_get()
920-
);
921-
} else if ($this->_attributeTypes[$code] === 'datetime') {
922-
$attrValue = $this->_localeDate->formatDateTime(
923-
new \DateTime($attrValue),
924-
\IntlDateFormatter::SHORT,
925-
\IntlDateFormatter::SHORT
926-
);
924+
if ($this->_attributeTypes[$code] === 'datetime') {
925+
if (
926+
in_array($code, $this->dateAttrCodes)
927+
|| in_array($code, $this->userDefinedAttributes)
928+
) {
929+
$attrValue = $this->_localeDate->formatDateTime(
930+
new \DateTime($attrValue),
931+
\IntlDateFormatter::SHORT,
932+
\IntlDateFormatter::NONE,
933+
null,
934+
date_default_timezone_get()
935+
);
936+
} else {
937+
$attrValue = $this->_localeDate->formatDateTime(
938+
new \DateTime($attrValue),
939+
\IntlDateFormatter::SHORT,
940+
\IntlDateFormatter::SHORT
941+
);
942+
}
927943
}
928944

929945
if ($storeId != Store::DEFAULT_STORE_ID
@@ -1380,6 +1396,9 @@ protected function initAttributes()
13801396
$this->_attributeValues[$attribute->getAttributeCode()] = $this->getAttributeOptions($attribute);
13811397
$this->_attributeTypes[$attribute->getAttributeCode()] =
13821398
\Magento\ImportExport\Model\Import::getAttributeType($attribute);
1399+
if ($attribute->getIsUserDefined()) {
1400+
$this->userDefinedAttributes[] = $attribute->getAttributeCode();
1401+
}
13831402
}
13841403
return $this;
13851404
}

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
217217
*/
218218
protected $dateAttrCodes = [
219219
'special_from_date',
220-
'special_to_date'
220+
'special_to_date',
221+
'news_from_date',
222+
'news_to_date',
223+
'custom_design_from',
224+
'custom_design_to'
221225
];
222226

223227
/**
@@ -1699,7 +1703,10 @@ protected function _saveProducts()
16991703

17001704
if (
17011705
'datetime' == $attribute->getBackendType()
1702-
&& in_array($attribute->getAttributeCode(), $this->dateAttrCodes)
1706+
&& (
1707+
in_array($attribute->getAttributeCode(), $this->dateAttrCodes)
1708+
|| $attribute->getIsUserDefined()
1709+
)
17031710
) {
17041711
$attrValue = $this->dateTime->formatDate($attrValue, false);
17051712
} else if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
@@ -2509,7 +2516,7 @@ protected function _saveValidatedBunches()
25092516
$rowData = $this->_customFieldsMapping($rowData);
25102517

25112518
$this->validateRow($rowData, $source->key());
2512-
2519+
25132520
$source->next();
25142521
}
25152522
$this->checkUrlKeyDuplicates();

0 commit comments

Comments
 (0)