Skip to content

Commit debb977

Browse files
committed
Merge branch 'develop' of github.com:magento/magento2ce into troll_bugfix
2 parents 231825b + 10407d3 commit debb977

File tree

5 files changed

+220
-49
lines changed

5 files changed

+220
-49
lines changed

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

Lines changed: 23 additions & 2 deletions
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
*
@@ -338,6 +348,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
338348
* @param Product\Type\Factory $_typeFactory
339349
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
340350
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
351+
* @param array $dateAttrCodes
341352
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
342353
*/
343354
public function __construct(
@@ -356,7 +367,8 @@ public function __construct(
356367
\Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeColFactory,
357368
\Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory,
358369
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
359-
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
370+
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer,
371+
array $dateAttrCodes = []
360372
) {
361373
$this->_entityCollectionFactory = $collectionFactory;
362374
$this->_exportConfig = $exportConfig;
@@ -371,6 +383,7 @@ public function __construct(
371383
$this->_typeFactory = $_typeFactory;
372384
$this->_linkTypeProvider = $linkTypeProvider;
373385
$this->rowCustomizer = $rowCustomizer;
386+
$this->dateAttrCodes = array_merge($this->dateAttrCodes, $dateAttrCodes);
374387

375388
parent::__construct($localeDate, $config, $resource, $storeManager);
376389

@@ -897,7 +910,15 @@ protected function collectRawData()
897910
}
898911
$fieldName = isset($this->_fieldsMap[$code]) ? $this->_fieldsMap[$code] : $code;
899912

900-
if ($this->_attributeTypes[$code] === 'datetime') {
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') {
901922
$attrValue = $this->_localeDate->formatDateTime(
902923
new \DateTime($attrValue),
903924
\IntlDateFormatter::SHORT,

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

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

213+
/**
214+
* Attributes codes which shows as date
215+
*
216+
* @var array
217+
*/
218+
protected $dateAttrCodes = [
219+
'special_from_date',
220+
'special_to_date'
221+
];
222+
213223
/**
214224
* Need to log in import history
215225
*
@@ -664,6 +674,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
664674
* @param Product\TaxClassProcessor $taxClassProcessor
665675
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
666676
* @param array $data
677+
* @param array $dateAttrCodes
667678
* @throws \Magento\Framework\Exception\LocalizedException
668679
*
669680
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -705,7 +716,8 @@ public function __construct(
705716
Product\TaxClassProcessor $taxClassProcessor,
706717
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
707718
\Magento\Catalog\Model\Product\Url $productUrl,
708-
array $data = []
719+
array $data = [],
720+
array $dateAttrCodes = []
709721
) {
710722
$this->_eventManager = $eventManager;
711723
$this->stockRegistry = $stockRegistry;
@@ -734,6 +746,7 @@ public function __construct(
734746
$this->taxClassProcessor = $taxClassProcessor;
735747
$this->scopeConfig = $scopeConfig;
736748
$this->productUrl = $productUrl;
749+
$this->dateAttrCodes = array_merge($this->dateAttrCodes, $dateAttrCodes);
737750
parent::__construct(
738751
$jsonHelper,
739752
$importExportData,
@@ -1642,7 +1655,12 @@ protected function _saveProducts()
16421655
$attrTable = $attribute->getBackend()->getTable();
16431656
$storeIds = [0];
16441657

1645-
if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
1658+
if (
1659+
'datetime' == $attribute->getBackendType()
1660+
&& in_array($attribute->getAttributeCode(), $this->dateAttrCodes)
1661+
) {
1662+
$attrValue = $this->dateTime->formatDate($attrValue, false);
1663+
} else if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
16461664
$attrValue = $this->dateTime->gmDate(
16471665
'Y-m-d H:i:s',
16481666
$this->_localeDate->date($attrValue)->getTimestamp()

app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ protected function setUp()
343343
$this->attributeColFactory,
344344
$this->typeFactory,
345345
$this->linkTypeProvider,
346-
$this->rowCustomizer,
347-
$this->metadataPool
346+
$this->rowCustomizer
348347
);
348+
$this->setPropertyValue($this->product, 'metadataPool', $this->metadataPool);
349349

350350
$this->object = new StubProduct();
351351
}

app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,49 @@
99
use Symfony\Component\Console\Command\Command;
1010
use Symfony\Component\Console\Input\InputInterface;
1111
use Symfony\Component\Console\Output\OutputInterface;
12-
use Magento\SampleData\Model\Dependency;
1312
use Magento\Framework\App\State;
1413
use Symfony\Component\Console\Input\ArrayInput;
15-
use Symfony\Component\Console\Input\ArrayInputFactory;
1614
use Magento\Framework\App\Filesystem\DirectoryList;
17-
use Magento\Framework\Filesystem;
1815
use Composer\Console\Application;
19-
use Composer\Console\ApplicationFactory;
16+
use Magento\Setup\Model\PackagesAuth;
2017

2118
/**
2219
* Command for deployment of Sample Data
2320
*/
2421
class SampleDataDeployCommand extends Command
2522
{
2623
/**
27-
* @var Filesystem
24+
* @var \Magento\Framework\Filesystem
2825
*/
2926
private $filesystem;
3027

3128
/**
32-
* @var Dependency
29+
* @var \Magento\SampleData\Model\Dependency
3330
*/
3431
private $sampleDataDependency;
3532

3633
/**
37-
* @var ArrayInputFactory
34+
* @var \Symfony\Component\Console\Input\ArrayInputFactory
3835
* @deprecated
3936
*/
4037
private $arrayInputFactory;
4138

4239
/**
43-
* @var ApplicationFactory
40+
* @var \Composer\Console\ApplicationFactory
4441
*/
4542
private $applicationFactory;
4643

4744
/**
48-
* @param Filesystem $filesystem
49-
* @param Dependency $sampleDataDependency
50-
* @param ArrayInputFactory $arrayInputFactory
51-
* @param ApplicationFactory $applicationFactory
45+
* @param \Magento\Framework\Filesystem $filesystem
46+
* @param \Magento\SampleData\Model\Dependency $sampleDataDependency
47+
* @param \Symfony\Component\Console\Input\ArrayInputFactory $arrayInputFactory
48+
* @param \Composer\Console\ApplicationFactory $applicationFactory
5249
*/
5350
public function __construct(
54-
Filesystem $filesystem,
55-
Dependency $sampleDataDependency,
56-
ArrayInputFactory $arrayInputFactory,
57-
ApplicationFactory $applicationFactory
51+
\Magento\Framework\Filesystem $filesystem,
52+
\Magento\SampleData\Model\Dependency $sampleDataDependency,
53+
\Symfony\Component\Console\Input\ArrayInputFactory $arrayInputFactory,
54+
\Composer\Console\ApplicationFactory $applicationFactory
5855
) {
5956
$this->filesystem = $filesystem;
6057
$this->sampleDataDependency = $sampleDataDependency;
@@ -79,6 +76,7 @@ protected function configure()
7976
protected function execute(InputInterface $input, OutputInterface $output)
8077
{
8178
$this->updateMemoryLimit();
79+
$this->createAuthFile();
8280
$sampleDataPackages = $this->sampleDataDependency->getSampleDataPackages();
8381
if (!empty($sampleDataPackages)) {
8482
$baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
@@ -107,6 +105,30 @@ protected function execute(InputInterface $input, OutputInterface $output)
107105
}
108106
}
109107

108+
/**
109+
* Create new auth.json file if it doesn't exist.
110+
*
111+
* We create auth.json with correct permissions instead of relying on Composer.
112+
*
113+
* @return void
114+
* @throws \Exception
115+
*/
116+
private function createAuthFile()
117+
{
118+
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::COMPOSER_HOME);
119+
120+
if (!$directory->isExist(PackagesAuth::PATH_TO_AUTH_FILE)) {
121+
try {
122+
$directory->writeFile(PackagesAuth::PATH_TO_AUTH_FILE, '{}');
123+
} catch (\Exception $e) {
124+
$message = 'Error in writing Auth file '
125+
. $directory->getAbsolutePath(PackagesAuth::PATH_TO_AUTH_FILE)
126+
. '. Please check permissions for writing.';
127+
throw new \Exception($message);
128+
}
129+
}
130+
}
131+
110132
/**
111133
* @return void
112134
*/

0 commit comments

Comments
 (0)