Skip to content

Commit ff068db

Browse files
committed
Merge remote-tracking branch 'falcon/MAGETWO-58516' into MAGETWO-59264
2 parents 0f1af99 + 5a4585b commit ff068db

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

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

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CatalogImportExport\Model\Export;
77

8+
use Magento\Framework\DB\Ddl\Table;
89
use Magento\ImportExport\Model\Import;
910
use \Magento\Store\Model\Store;
1011
use \Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
@@ -127,6 +128,13 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
127128
*/
128129
protected $_attributeTypes = [];
129130

131+
/**
132+
* Attributes defined by user
133+
*
134+
* @var array
135+
*/
136+
private $userDefinedAttributes = [];
137+
130138
/**
131139
* Product collection
132140
*
@@ -261,7 +269,11 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
261269
*/
262270
protected $dateAttrCodes = [
263271
'special_from_date',
264-
'special_to_date'
272+
'special_to_date',
273+
'news_from_date',
274+
'news_to_date',
275+
'custom_design_from',
276+
'custom_design_to'
265277
];
266278

267279
/**
@@ -910,20 +922,24 @@ protected function collectRawData()
910922
}
911923
$fieldName = isset($this->_fieldsMap[$code]) ? $this->_fieldsMap[$code] : $code;
912924

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-
);
925+
if ($this->_attributeTypes[$code] === Table::TYPE_DATETIME) {
926+
if (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)) {
@@ -2523,7 +2530,7 @@ protected function _saveValidatedBunches()
25232530
$rowData = $this->_customFieldsMapping($rowData);
25242531

25252532
$this->validateRow($rowData, $source->key());
2526-
2533+
25272534
$source->next();
25282535
}
25292536
$this->checkUrlKeyDuplicates();

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,13 @@ public function testSaveDatetimeAttribute()
387387
);
388388
$productAfterImport->load($productBeforeImport->getId());
389389
$this->assertEquals(
390-
@strtotime($row['news_from_date']),
390+
@strtotime(date('m/d/Y', @strtotime($row['news_from_date']))),
391391
@strtotime($productAfterImport->getNewsFromDate())
392392
);
393+
$this->assertEquals(
394+
@strtotime($row['news_to_date']),
395+
@strtotime($productAfterImport->getNewsToDate())
396+
);
393397
unset($productAfterImport);
394398
}
395399
unset($productsBeforeImport, $product);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
sku,news_from_date
2-
simple1,"1/1/2015 20:00"
3-
simple2,"10/8/2012 23:58"
4-
simple3,"12/31/1998 17:30"
1+
sku,news_from_date,news_to_date
2+
simple1,"1/1/2015 20:00","1/2/2015"
3+
simple2,"10/8/2012 23:58","1/3/2015"
4+
simple3,"12/31/1998 17:30","1/4/2015"

0 commit comments

Comments
 (0)