Skip to content

Commit

Permalink
Merge pull request #463 from magento-falcons/MAGETWO-59264
Browse files Browse the repository at this point in the history
[Falcons] Bug fixes for Composer, Cache, Catalog
  • Loading branch information
Yaroslav Onischenko authored Oct 6, 2016
2 parents 4d69ecb + 723f16e commit 6674762
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 46 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
*/
const TREE_ROOT_ID = 1;

const CACHE_TAG = 'catalog_category';
const CACHE_TAG = 'cat_c';

/**#@+
* Constants
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
/**
* Product cache tag
*/
const CACHE_TAG = 'catalog_product';
const CACHE_TAG = 'cat_p';

/**
* Category product relation cache tag
*/
const CACHE_PRODUCT_CATEGORY_TAG = 'catalog_category_product';
const CACHE_PRODUCT_CATEGORY_TAG = 'cat_c_p';

/**
* Product Store Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ protected function tearDown()

public function testGetIdentities()
{
$productTag = 'catalog_product_1';
$categoryTag = 'catalog_category_product_1';
$productTag = 'cat_p_1';
$categoryTag = 'cat_c_p_1';

$this->productMock->expects($this->once())
->method('getIdentities')
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Catalog/Test/Unit/Block/Product/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function setUp()
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->productTypeConfig = $this->getMock(\Magento\Catalog\Model\ProductTypes\ConfigInterface::class);
$this->registryMock = $this->getMock(\Magento\Framework\Registry::class, [], [], '', false);
$this->view = $helper->getObject(
$this->view = $helper->getObject(
\Magento\Catalog\Block\Product\View::class,
['productTypeConfig' => $this->productTypeConfig, 'registry' => $this->registryMock]
);
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testShouldRenderQuantity()

public function testGetIdentities()
{
$productTags = ['catalog_product_1'];
$productTags = ['cat_p_1'];
$product = $this->getMock(\Magento\Catalog\Model\Product::class, [], [], '', false);
$category = $this->getMock(\Magento\Catalog\Model\Category::class, [], [], '', false);

Expand All @@ -84,6 +84,6 @@ public function testGetIdentities()
]
)
);
$this->assertEquals(['catalog_product_1', 'catalog_category_1'], $this->view->getIdentities());
$this->assertEquals(['cat_p_1', 'cat_c_1'], $this->view->getIdentities());
}
}
20 changes: 10 additions & 10 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,13 @@ public function getIdentitiesProvider()

return [
'no changes' => [
['catalog_product_1'],
['cat_p_1'],
['id' => 1, 'name' => 'value', 'category_ids' => [1]],
['id' => 1, 'name' => 'value', 'category_ids' => [1]],
],
'new product' => $this->getNewProductProviderData(),
'status and category change' => [
[0 => 'catalog_product_1', 1 => 'catalog_category_product_1', 2 => 'catalog_category_product_2'],
[0 => 'cat_p_1', 1 => 'cat_c_p_1', 2 => 'cat_c_p_2'],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
[
'id' => 1,
Expand All @@ -726,18 +726,18 @@ public function getIdentitiesProvider()
],
],
'status change only' => [
[0 => 'catalog_product_1', 1 => 'catalog_category_product_7'],
[0 => 'cat_p_1', 1 => 'cat_c_p_7'],
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => 1],
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => 2],
],
'status changed, category unassigned' => $this->getStatusAndCategoryChangesData(),
'no status changes' => [
[0 => 'catalog_product_1'],
[0 => 'cat_p_1'],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
],
'no stock status changes' => [
[0 => 'catalog_product_1'],
[0 => 'cat_p_1'],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
[
'id' => 1,
Expand All @@ -749,7 +749,7 @@ public function getIdentitiesProvider()
],
],
'no stock status data 1' => [
[0 => 'catalog_product_1'],
[0 => 'cat_p_1'],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
[
'id' => 1,
Expand All @@ -760,7 +760,7 @@ public function getIdentitiesProvider()
],
],
'no stock status data 2' => [
[0 => 'catalog_product_1'],
[0 => 'cat_p_1'],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
[
'id' => 1,
Expand All @@ -780,7 +780,7 @@ public function getIdentitiesProvider()
private function getStatusAndCategoryChangesData()
{
return [
[0 => 'catalog_product_1', 1 => 'catalog_category_product_5'],
[0 => 'cat_p_1', 1 => 'cat_c_p_5'],
['id' => 1, 'name' => 'value', 'category_ids' => [5], 'status' => 2],
[
'id' => 1,
Expand All @@ -799,7 +799,7 @@ private function getStatusAndCategoryChangesData()
private function getNewProductProviderData()
{
return [
['catalog_product_1', 'catalog_category_product_1'],
['cat_p_1', 'cat_c_p_1'],
null,
[
'id' => 1,
Expand All @@ -818,7 +818,7 @@ private function getNewProductProviderData()
private function getStatusStockProviderData($extensionAttributesMock)
{
return [
[0 => 'catalog_product_1', 1 => 'catalog_category_product_1'],
[0 => 'cat_p_1', 1 => 'cat_c_p_1'],
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
[
'id' => 1,
Expand Down
49 changes: 34 additions & 15 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\CatalogImportExport\Model\Export;

use Magento\Framework\DB\Ddl\Table;
use Magento\ImportExport\Model\Import;
use \Magento\Store\Model\Store;
use \Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
Expand Down Expand Up @@ -127,6 +128,13 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
*/
protected $_attributeTypes = [];

/**
* Attributes defined by user
*
* @var array
*/
private $userDefinedAttributes = [];

/**
* Product collection
*
Expand Down Expand Up @@ -261,7 +269,11 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
*/
protected $dateAttrCodes = [
'special_from_date',
'special_to_date'
'special_to_date',
'news_from_date',
'news_to_date',
'custom_design_from',
'custom_design_to'
];

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

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,
\IntlDateFormatter::SHORT
);
if ($this->_attributeTypes[$code] == 'datetime') {
if (in_array($code, $this->dateAttrCodes)
|| in_array($code, $this->userDefinedAttributes)
) {
$attrValue = $this->_localeDate->formatDateTime(
new \DateTime($attrValue),
\IntlDateFormatter::SHORT,
\IntlDateFormatter::NONE,
null,
date_default_timezone_get()
);
} else {
$attrValue = $this->_localeDate->formatDateTime(
new \DateTime($attrValue),
\IntlDateFormatter::SHORT,
\IntlDateFormatter::SHORT
);
}
}

if ($storeId != Store::DEFAULT_STORE_ID
Expand Down Expand Up @@ -1380,6 +1396,9 @@ protected function initAttributes()
$this->_attributeValues[$attribute->getAttributeCode()] = $this->getAttributeOptions($attribute);
$this->_attributeTypes[$attribute->getAttributeCode()] =
\Magento\ImportExport\Model\Import::getAttributeType($attribute);
if ($attribute->getIsUserDefined()) {
$this->userDefinedAttributes[] = $attribute->getAttributeCode();
}
}
return $this;
}
Expand Down
13 changes: 10 additions & 3 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
*/
protected $dateAttrCodes = [
'special_from_date',
'special_to_date'
'special_to_date',
'news_from_date',
'news_to_date',
'custom_design_from',
'custom_design_to'
];

/**
Expand Down Expand Up @@ -1699,7 +1703,10 @@ protected function _saveProducts()

if (
'datetime' == $attribute->getBackendType()
&& in_array($attribute->getAttributeCode(), $this->dateAttrCodes)
&& (
in_array($attribute->getAttributeCode(), $this->dateAttrCodes)
|| $attribute->getIsUserDefined()
)
) {
$attrValue = $this->dateTime->formatDate($attrValue, false);
} else if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
Expand Down Expand Up @@ -2533,7 +2540,7 @@ protected function _saveValidatedBunches()
$rowData = $this->_customFieldsMapping($rowData);

$this->validateRow($rowData, $source->key());

$source->next();
}
$this->checkUrlKeyDuplicates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ public function testGetCustomerGroupId()
public function testGetIdentities()
{
$this->_model->setProductId(1);
$this->assertEquals(['catalog_product_1'], $this->_model->getIdentities());
$this->assertEquals(['cat_p_1'], $this->_model->getIdentities());
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Cms/Model/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Block extends AbstractModel implements BlockInterface, IdentityInterface
/**
* CMS block cache tag
*/
const CACHE_TAG = 'cms_block';
const CACHE_TAG = 'cms_b';

/**#@+
* Block's statuses
Expand All @@ -36,7 +36,7 @@ class Block extends AbstractModel implements BlockInterface, IdentityInterface
/**
* @var string
*/
protected $_cacheTag = 'cms_block';
protected $_cacheTag = self::CACHE_TAG;

/**
* Prefix of model events names
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Cms/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class Page extends AbstractModel implements PageInterface, IdentityInterface
/**
* CMS page cache tag
*/
const CACHE_TAG = 'cms_page';
const CACHE_TAG = 'cms_p';

/**
* @var string
*/
protected $_cacheTag = 'cms_page';
protected $_cacheTag = self::CACHE_TAG;

/**
* Prefix of model events names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,13 @@ public function testSaveDatetimeAttribute()
);
$productAfterImport->load($productBeforeImport->getId());
$this->assertEquals(
@strtotime($row['news_from_date']),
@strtotime(date('m/d/Y', @strtotime($row['news_from_date']))),
@strtotime($productAfterImport->getNewsFromDate())
);
$this->assertEquals(
@strtotime($row['news_to_date']),
@strtotime($productAfterImport->getNewsToDate())
);
unset($productAfterImport);
}
unset($productsBeforeImport, $product);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sku,news_from_date
simple1,"1/1/2015 20:00"
simple2,"10/8/2012 23:58"
simple3,"12/31/1998 17:30"
sku,news_from_date,news_to_date
simple1,"1/1/2015 20:00","1/2/2015"
simple2,"10/8/2012 23:58","1/3/2015"
simple3,"12/31/1998 17:30","1/4/2015"

0 comments on commit 6674762

Please sign in to comment.