Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:magento/magento2ce into troll_bu…
Browse files Browse the repository at this point in the history
…gfix
  • Loading branch information
rganin committed Aug 8, 2016
2 parents 231825b + 10407d3 commit debb977
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 49 deletions.
25 changes: 23 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
'tax_class_id' => 'tax_class_name',
];

/**
* Attributes codes which shows as date
*
* @var array
*/
protected $dateAttrCodes = [
'special_from_date',
'special_to_date'
];

/**
* Attributes codes which are appropriate for export and not the part of additional_attributes.
*
Expand Down Expand Up @@ -338,6 +348,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
* @param Product\Type\Factory $_typeFactory
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
* @param array $dateAttrCodes
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -356,7 +367,8 @@ public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeColFactory,
\Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory,
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer,
array $dateAttrCodes = []
) {
$this->_entityCollectionFactory = $collectionFactory;
$this->_exportConfig = $exportConfig;
Expand All @@ -371,6 +383,7 @@ public function __construct(
$this->_typeFactory = $_typeFactory;
$this->_linkTypeProvider = $linkTypeProvider;
$this->rowCustomizer = $rowCustomizer;
$this->dateAttrCodes = array_merge($this->dateAttrCodes, $dateAttrCodes);

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

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

if ($this->_attributeTypes[$code] === 'datetime') {
if (in_array($code, $this->dateAttrCodes)) {
$attrValue = $this->_localeDate->formatDateTime(
new \DateTime($attrValue),
\IntlDateFormatter::SHORT,
\IntlDateFormatter::NONE,
null,
date_default_timezone_get()
);
} else if ($this->_attributeTypes[$code] === 'datetime') {
$attrValue = $this->_localeDate->formatDateTime(
new \DateTime($attrValue),
\IntlDateFormatter::SHORT,
Expand Down
22 changes: 20 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
'_upsell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL,
];

/**
* Attributes codes which shows as date
*
* @var array
*/
protected $dateAttrCodes = [
'special_from_date',
'special_to_date'
];

/**
* Need to log in import history
*
Expand Down Expand Up @@ -664,6 +674,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
* @param Product\TaxClassProcessor $taxClassProcessor
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param array $data
* @param array $dateAttrCodes
* @throws \Magento\Framework\Exception\LocalizedException
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand Down Expand Up @@ -705,7 +716,8 @@ public function __construct(
Product\TaxClassProcessor $taxClassProcessor,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Catalog\Model\Product\Url $productUrl,
array $data = []
array $data = [],
array $dateAttrCodes = []
) {
$this->_eventManager = $eventManager;
$this->stockRegistry = $stockRegistry;
Expand Down Expand Up @@ -734,6 +746,7 @@ public function __construct(
$this->taxClassProcessor = $taxClassProcessor;
$this->scopeConfig = $scopeConfig;
$this->productUrl = $productUrl;
$this->dateAttrCodes = array_merge($this->dateAttrCodes, $dateAttrCodes);
parent::__construct(
$jsonHelper,
$importExportData,
Expand Down Expand Up @@ -1642,7 +1655,12 @@ protected function _saveProducts()
$attrTable = $attribute->getBackend()->getTable();
$storeIds = [0];

if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
if (
'datetime' == $attribute->getBackendType()
&& in_array($attribute->getAttributeCode(), $this->dateAttrCodes)
) {
$attrValue = $this->dateTime->formatDate($attrValue, false);
} else if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
$attrValue = $this->dateTime->gmDate(
'Y-m-d H:i:s',
$this->_localeDate->date($attrValue)->getTimestamp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ protected function setUp()
$this->attributeColFactory,
$this->typeFactory,
$this->linkTypeProvider,
$this->rowCustomizer,
$this->metadataPool
$this->rowCustomizer
);
$this->setPropertyValue($this->product, 'metadataPool', $this->metadataPool);

$this->object = new StubProduct();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,49 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\SampleData\Model\Dependency;
use Magento\Framework\App\State;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\ArrayInputFactory;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Composer\Console\Application;
use Composer\Console\ApplicationFactory;
use Magento\Setup\Model\PackagesAuth;

/**
* Command for deployment of Sample Data
*/
class SampleDataDeployCommand extends Command
{
/**
* @var Filesystem
* @var \Magento\Framework\Filesystem
*/
private $filesystem;

/**
* @var Dependency
* @var \Magento\SampleData\Model\Dependency
*/
private $sampleDataDependency;

/**
* @var ArrayInputFactory
* @var \Symfony\Component\Console\Input\ArrayInputFactory
* @deprecated
*/
private $arrayInputFactory;

/**
* @var ApplicationFactory
* @var \Composer\Console\ApplicationFactory
*/
private $applicationFactory;

/**
* @param Filesystem $filesystem
* @param Dependency $sampleDataDependency
* @param ArrayInputFactory $arrayInputFactory
* @param ApplicationFactory $applicationFactory
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\SampleData\Model\Dependency $sampleDataDependency
* @param \Symfony\Component\Console\Input\ArrayInputFactory $arrayInputFactory
* @param \Composer\Console\ApplicationFactory $applicationFactory
*/
public function __construct(
Filesystem $filesystem,
Dependency $sampleDataDependency,
ArrayInputFactory $arrayInputFactory,
ApplicationFactory $applicationFactory
\Magento\Framework\Filesystem $filesystem,
\Magento\SampleData\Model\Dependency $sampleDataDependency,
\Symfony\Component\Console\Input\ArrayInputFactory $arrayInputFactory,
\Composer\Console\ApplicationFactory $applicationFactory
) {
$this->filesystem = $filesystem;
$this->sampleDataDependency = $sampleDataDependency;
Expand All @@ -79,6 +76,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->updateMemoryLimit();
$this->createAuthFile();
$sampleDataPackages = $this->sampleDataDependency->getSampleDataPackages();
if (!empty($sampleDataPackages)) {
$baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath();
Expand Down Expand Up @@ -107,6 +105,30 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

/**
* Create new auth.json file if it doesn't exist.
*
* We create auth.json with correct permissions instead of relying on Composer.
*
* @return void
* @throws \Exception
*/
private function createAuthFile()
{
$directory = $this->filesystem->getDirectoryWrite(DirectoryList::COMPOSER_HOME);

if (!$directory->isExist(PackagesAuth::PATH_TO_AUTH_FILE)) {
try {
$directory->writeFile(PackagesAuth::PATH_TO_AUTH_FILE, '{}');
} catch (\Exception $e) {
$message = 'Error in writing Auth file '
. $directory->getAbsolutePath(PackagesAuth::PATH_TO_AUTH_FILE)
. '. Please check permissions for writing.';
throw new \Exception($message);
}
}
}

/**
* @return void
*/
Expand Down
Loading

0 comments on commit debb977

Please sign in to comment.