5
5
*/
6
6
namespace Magento \CatalogImportExport \Model \Export ;
7
7
8
+ use Magento \Framework \DB \Ddl \Table ;
8
9
use Magento \ImportExport \Model \Import ;
9
10
use \Magento \Store \Model \Store ;
10
11
use \Magento \CatalogImportExport \Model \Import \Product as ImportProduct ;
@@ -88,6 +89,13 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
88
89
'gift_message_available ' ,
89
90
];
90
91
92
+ /**
93
+ * Attributes defined by user
94
+ *
95
+ * @var array
96
+ */
97
+ private $ userDefinedAttributes = [];
98
+
91
99
/**
92
100
* @var array
93
101
*/
@@ -255,6 +263,20 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
255
263
'tax_class_id ' => 'tax_class_name ' ,
256
264
];
257
265
266
+ /**
267
+ * Codes of attributes which are displayed as dates
268
+ *
269
+ * @var array
270
+ */
271
+ protected $ dateAttrCodes = [
272
+ 'special_from_date ' ,
273
+ 'special_to_date ' ,
274
+ 'news_from_date ' ,
275
+ 'news_to_date ' ,
276
+ 'custom_design_from ' ,
277
+ 'custom_design_to '
278
+ ];
279
+
258
280
/**
259
281
* Attributes codes which are appropriate for export and not the part of additional_attributes.
260
282
*
@@ -327,6 +349,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
327
349
* @param Product\Type\Factory $_typeFactory
328
350
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
329
351
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
352
+ * @param array $dateAttrCodes
330
353
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
331
354
*/
332
355
public function __construct (
@@ -345,7 +368,8 @@ public function __construct(
345
368
\Magento \Catalog \Model \ResourceModel \Product \Attribute \CollectionFactory $ attributeColFactory ,
346
369
\Magento \CatalogImportExport \Model \Export \Product \Type \Factory $ _typeFactory ,
347
370
\Magento \Catalog \Model \Product \LinkTypeProvider $ linkTypeProvider ,
348
- \Magento \CatalogImportExport \Model \Export \RowCustomizerInterface $ rowCustomizer
371
+ \Magento \CatalogImportExport \Model \Export \RowCustomizerInterface $ rowCustomizer ,
372
+ array $ dateAttrCodes = []
349
373
) {
350
374
$ this ->_entityCollectionFactory = $ collectionFactory ;
351
375
$ this ->_exportConfig = $ exportConfig ;
@@ -360,6 +384,7 @@ public function __construct(
360
384
$ this ->_typeFactory = $ _typeFactory ;
361
385
$ this ->_linkTypeProvider = $ linkTypeProvider ;
362
386
$ this ->rowCustomizer = $ rowCustomizer ;
387
+ $ this ->dateAttrCodes = array_merge ($ this ->dateAttrCodes , $ dateAttrCodes );
363
388
364
389
parent ::__construct ($ localeDate , $ config , $ resource , $ storeManager );
365
390
@@ -875,12 +900,24 @@ protected function collectRawData()
875
900
}
876
901
$ fieldName = isset ($ this ->_fieldsMap [$ code ]) ? $ this ->_fieldsMap [$ code ] : $ code ;
877
902
878
- if ($ this ->_attributeTypes [$ code ] === 'datetime ' ) {
879
- $ attrValue = $ this ->_localeDate ->formatDateTime (
880
- new \DateTime ($ attrValue ),
881
- \IntlDateFormatter::SHORT ,
882
- \IntlDateFormatter::SHORT
883
- );
903
+ if ($ this ->_attributeTypes [$ code ] == 'datetime ' ) {
904
+ if (in_array ($ code , $ this ->dateAttrCodes )
905
+ || in_array ($ code , $ this ->userDefinedAttributes )
906
+ ) {
907
+ $ attrValue = $ this ->_localeDate ->formatDateTime (
908
+ new \DateTime ($ attrValue ),
909
+ \IntlDateFormatter::SHORT ,
910
+ \IntlDateFormatter::NONE ,
911
+ null ,
912
+ date_default_timezone_get ()
913
+ );
914
+ } else {
915
+ $ attrValue = $ this ->_localeDate ->formatDateTime (
916
+ new \DateTime ($ attrValue ),
917
+ \IntlDateFormatter::SHORT ,
918
+ \IntlDateFormatter::SHORT
919
+ );
920
+ }
884
921
}
885
922
886
923
if ($ storeId != Store::DEFAULT_STORE_ID
@@ -1327,6 +1364,9 @@ protected function initAttributes()
1327
1364
$ this ->_attributeValues [$ attribute ->getAttributeCode ()] = $ this ->getAttributeOptions ($ attribute );
1328
1365
$ this ->_attributeTypes [$ attribute ->getAttributeCode ()] =
1329
1366
\Magento \ImportExport \Model \Import::getAttributeType ($ attribute );
1367
+ if ($ attribute ->getIsUserDefined ()) {
1368
+ $ this ->userDefinedAttributes [] = $ attribute ->getAttributeCode ();
1369
+ }
1330
1370
}
1331
1371
return $ this ;
1332
1372
}
0 commit comments