Skip to content

Commit 1a09ba2

Browse files
committed
MAGETWO-53428: Product catalog Import/export - Date & Timezone issue
1 parent eaabc17 commit 1a09ba2

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,16 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
254254
'tax_class_id' => 'tax_class_name',
255255
];
256256

257+
/**
258+
* Attributes codes which shows as date
259+
*
260+
* @var array
261+
*/
262+
protected $dateAttrCodes = [
263+
'special_from_date',
264+
'special_to_date'
265+
];
266+
257267
/**
258268
* Attributes codes which are appropriate for export and not the part of additional_attributes.
259269
*
@@ -897,7 +907,15 @@ protected function collectRawData()
897907
}
898908
$fieldName = isset($this->_fieldsMap[$code]) ? $this->_fieldsMap[$code] : $code;
899909

900-
if ($this->_attributeTypes[$code] === 'datetime') {
910+
if (in_array($code, $this->dateAttrCodes)) {
911+
$attrValue = $this->_localeDate->formatDateTime(
912+
new \DateTime($attrValue),
913+
\IntlDateFormatter::SHORT,
914+
\IntlDateFormatter::NONE,
915+
null,
916+
date_default_timezone_get()
917+
);
918+
} else if ($this->_attributeTypes[$code] === 'datetime') {
901919
$attrValue = $this->_localeDate->formatDateTime(
902920
new \DateTime($attrValue),
903921
\IntlDateFormatter::SHORT,

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
209209
'_upsell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL,
210210
];
211211

212+
/**
213+
* Attributes codes which shows as date
214+
*
215+
* @var array
216+
*/
217+
protected $dateAttrCodes = [
218+
'special_from_date',
219+
'special_to_date'
220+
];
221+
212222
/**
213223
* Need to log in import history
214224
*
@@ -1642,7 +1652,12 @@ protected function _saveProducts()
16421652
$attrTable = $attribute->getBackend()->getTable();
16431653
$storeIds = [0];
16441654

1645-
if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
1655+
if (
1656+
'datetime' == $attribute->getBackendType()
1657+
&& in_array($attribute->getAttributeCode(), $this->dateAttrCodes)
1658+
) {
1659+
$attrValue = $this->dateTime->formatDate($attrValue, false);
1660+
} else if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
16461661
$attrValue = $this->dateTime->gmDate(
16471662
'Y-m-d H:i:s',
16481663
$this->_localeDate->date($attrValue)->getTimestamp()

0 commit comments

Comments
 (0)