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 ;
@@ -87,6 +88,13 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
87
88
'status ' ,
88
89
];
89
90
91
+ /**
92
+ * Attributes defined by user
93
+ *
94
+ * @var array
95
+ */
96
+ private $ userDefinedAttributes = [];
97
+
90
98
/**
91
99
* @var array
92
100
*/
@@ -254,6 +262,20 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
254
262
'tax_class_id ' => 'tax_class_name ' ,
255
263
];
256
264
265
+ /**
266
+ * Codes of attributes which are displayed as dates
267
+ *
268
+ * @var array
269
+ */
270
+ protected $ dateAttrCodes = [
271
+ 'special_from_date ' ,
272
+ 'special_to_date ' ,
273
+ 'news_from_date ' ,
274
+ 'news_to_date ' ,
275
+ 'custom_design_from ' ,
276
+ 'custom_design_to '
277
+ ];
278
+
257
279
/**
258
280
* Attributes codes which are appropriate for export and not the part of additional_attributes.
259
281
*
@@ -338,6 +360,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
338
360
* @param Product\Type\Factory $_typeFactory
339
361
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
340
362
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
363
+ * @param array $dateAttrCodes
341
364
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
342
365
*/
343
366
public function __construct (
@@ -356,7 +379,8 @@ public function __construct(
356
379
\Magento \Catalog \Model \ResourceModel \Product \Attribute \CollectionFactory $ attributeColFactory ,
357
380
\Magento \CatalogImportExport \Model \Export \Product \Type \Factory $ _typeFactory ,
358
381
\Magento \Catalog \Model \Product \LinkTypeProvider $ linkTypeProvider ,
359
- \Magento \CatalogImportExport \Model \Export \RowCustomizerInterface $ rowCustomizer
382
+ \Magento \CatalogImportExport \Model \Export \RowCustomizerInterface $ rowCustomizer ,
383
+ array $ dateAttrCodes = []
360
384
) {
361
385
$ this ->_entityCollectionFactory = $ collectionFactory ;
362
386
$ this ->_exportConfig = $ exportConfig ;
@@ -371,6 +395,7 @@ public function __construct(
371
395
$ this ->_typeFactory = $ _typeFactory ;
372
396
$ this ->_linkTypeProvider = $ linkTypeProvider ;
373
397
$ this ->rowCustomizer = $ rowCustomizer ;
398
+ $ this ->dateAttrCodes = array_merge ($ this ->dateAttrCodes , $ dateAttrCodes );
374
399
375
400
parent ::__construct ($ localeDate , $ config , $ resource , $ storeManager );
376
401
@@ -897,12 +922,24 @@ protected function collectRawData()
897
922
}
898
923
$ fieldName = isset ($ this ->_fieldsMap [$ code ]) ? $ this ->_fieldsMap [$ code ] : $ code ;
899
924
900
- if ($ this ->_attributeTypes [$ code ] === 'datetime ' ) {
901
- $ attrValue = $ this ->_localeDate ->formatDateTime (
902
- new \DateTime ($ attrValue ),
903
- \IntlDateFormatter::SHORT ,
904
- \IntlDateFormatter::SHORT
905
- );
925
+ if ($ this ->_attributeTypes [$ code ] == '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
+ }
906
943
}
907
944
908
945
if ($ storeId != Store::DEFAULT_STORE_ID
@@ -1370,6 +1407,9 @@ protected function initAttributes()
1370
1407
$ this ->_attributeValues [$ attribute ->getAttributeCode ()] = $ this ->getAttributeOptions ($ attribute );
1371
1408
$ this ->_attributeTypes [$ attribute ->getAttributeCode ()] =
1372
1409
\Magento \ImportExport \Model \Import::getAttributeType ($ attribute );
1410
+ if ($ attribute ->getIsUserDefined ()) {
1411
+ $ this ->userDefinedAttributes [] = $ attribute ->getAttributeCode ();
1412
+ }
1373
1413
}
1374
1414
return $ this ;
1375
1415
}
0 commit comments