From f86925fbdb234c85923d3c141777b9f8a2e4c16e Mon Sep 17 00:00:00 2001 From: Oleksandr Shmyheliuk Date: Wed, 28 Sep 2016 10:26:09 +0300 Subject: [PATCH 1/6] =?UTF-8?q?MAGETWO-58516:=20Product=20catalog=20Import?= =?UTF-8?q?/export=20=E2=80=93=20Date=20&=20Timezone=20issue.=20Other=20fi?= =?UTF-8?q?elds.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model/Export/Product.php | 49 +++++++++++++------ .../Model/Import/Product.php | 13 +++-- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Export/Product.php b/app/code/Magento/CatalogImportExport/Model/Export/Product.php index 2abd8d97ebc01..410f78dd73038 100644 --- a/app/code/Magento/CatalogImportExport/Model/Export/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Export/Product.php @@ -127,6 +127,13 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity */ protected $_attributeTypes = []; + /** + * Attributes defined by user + * + * @var array + */ + protected $userDefinedAttributes = []; + /** * Product collection * @@ -261,7 +268,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' ]; /** @@ -910,20 +921,25 @@ 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 @@ -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; } diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index 25619620ff487..468e44d672ae5 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -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' ]; /** @@ -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)) { @@ -2509,7 +2516,7 @@ protected function _saveValidatedBunches() $rowData = $this->_customFieldsMapping($rowData); $this->validateRow($rowData, $source->key()); - + $source->next(); } $this->checkUrlKeyDuplicates(); From 1a3f9469adc14c8684ef5de4de99f0219fda5887 Mon Sep 17 00:00:00 2001 From: Oleksandr Shmyheliuk Date: Thu, 29 Sep 2016 13:23:07 +0300 Subject: [PATCH 2/6] =?UTF-8?q?MAGETWO-58516:=20Product=20catalog=20Import?= =?UTF-8?q?/export=20=E2=80=93=20Date=20&=20Timezone=20issue.=20Other=20fi?= =?UTF-8?q?elds.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CatalogImportExport/Model/Import/ProductTest.php | 6 +++++- .../Import/_files/products_to_import_with_datetime.csv | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php index febb4941c2738..3b667e10955ce 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php @@ -387,9 +387,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); diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/products_to_import_with_datetime.csv b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/products_to_import_with_datetime.csv index ae7e27dbd95c0..265e29fab65bb 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/products_to_import_with_datetime.csv +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/products_to_import_with_datetime.csv @@ -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" From 2529ec4fc035eec8c524e94c0b73efd8c3efbb28 Mon Sep 17 00:00:00 2001 From: Oleksandr Shmyheliuk Date: Fri, 30 Sep 2016 11:15:38 +0300 Subject: [PATCH 3/6] MAGETWO-57851: X-Magento-Tags header too large --- app/code/Magento/Catalog/Model/Category.php | 2 +- app/code/Magento/Catalog/Model/Product.php | 4 ++-- .../Unit/Block/Product/ListProductTest.php | 4 ++-- .../Test/Unit/Block/Product/ViewTest.php | 6 +++--- .../Catalog/Test/Unit/Model/ProductTest.php | 20 +++++++++---------- .../Unit/Model/Adminhtml/Stock/ItemTest.php | 2 +- app/code/Magento/Cms/Model/Block.php | 4 ++-- app/code/Magento/Cms/Model/Page.php | 4 ++-- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Category.php b/app/code/Magento/Catalog/Model/Category.php index b1f9dbf8c327a..9e855e05c7ce3 100644 --- a/app/code/Magento/Catalog/Model/Category.php +++ b/app/code/Magento/Catalog/Model/Category.php @@ -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 diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 49df6fd57c323..9e9f18e011371 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -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 diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php index 38ef297e68426..f420f140b3582 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php @@ -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') diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Product/ViewTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Product/ViewTest.php index d030cf456b6b1..f0287e05a4b7b 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Product/ViewTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Product/ViewTest.php @@ -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] ); @@ -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); @@ -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()); } } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php index dd858fa571ae1..5601f1c8eb591 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Adminhtml/Stock/ItemTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Adminhtml/Stock/ItemTest.php index aef8141e70f34..dfb8073e718a7 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Adminhtml/Stock/ItemTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Adminhtml/Stock/ItemTest.php @@ -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()); } } diff --git a/app/code/Magento/Cms/Model/Block.php b/app/code/Magento/Cms/Model/Block.php index d87f0f0d18884..b25d433b0fee4 100644 --- a/app/code/Magento/Cms/Model/Block.php +++ b/app/code/Magento/Cms/Model/Block.php @@ -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 @@ -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 diff --git a/app/code/Magento/Cms/Model/Page.php b/app/code/Magento/Cms/Model/Page.php index 20c2e05471931..f98b56d82db03 100644 --- a/app/code/Magento/Cms/Model/Page.php +++ b/app/code/Magento/Cms/Model/Page.php @@ -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 From a036e159b19b9bc3ea034ed0bb0eece284743dae Mon Sep 17 00:00:00 2001 From: Oleksandr Shmyheliuk Date: Fri, 30 Sep 2016 11:20:51 +0300 Subject: [PATCH 4/6] =?UTF-8?q?MAGETWO-58516:=20Product=20catalog=20Import?= =?UTF-8?q?/export=20=E2=80=93=20Date=20&=20Timezone=20issue.=20Other=20fi?= =?UTF-8?q?elds.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - change property scope to private --- app/code/Magento/CatalogImportExport/Model/Export/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Export/Product.php b/app/code/Magento/CatalogImportExport/Model/Export/Product.php index 410f78dd73038..87a927c81e523 100644 --- a/app/code/Magento/CatalogImportExport/Model/Export/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Export/Product.php @@ -132,7 +132,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity * * @var array */ - protected $userDefinedAttributes = []; + private $userDefinedAttributes = []; /** * Product collection From 5a4585bd7b9bed19a0f911fa26000ad72ff5d2e8 Mon Sep 17 00:00:00 2001 From: Oleksandr Shmyheliuk Date: Fri, 30 Sep 2016 12:20:21 +0300 Subject: [PATCH 5/6] =?UTF-8?q?MAGETWO-58516:=20Product=20catalog=20Import?= =?UTF-8?q?/export=20=E2=80=93=20Date=20&=20Timezone=20issue.=20Other=20fi?= =?UTF-8?q?elds.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fixes --- .../Magento/CatalogImportExport/Model/Export/Product.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Export/Product.php b/app/code/Magento/CatalogImportExport/Model/Export/Product.php index 87a927c81e523..5cbaa6ce81db6 100644 --- a/app/code/Magento/CatalogImportExport/Model/Export/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Export/Product.php @@ -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; @@ -921,9 +922,8 @@ protected function collectRawData() } $fieldName = isset($this->_fieldsMap[$code]) ? $this->_fieldsMap[$code] : $code; - if ($this->_attributeTypes[$code] === 'datetime') { - if ( - in_array($code, $this->dateAttrCodes) + if ($this->_attributeTypes[$code] === Table::TYPE_DATETIME) { + if (in_array($code, $this->dateAttrCodes) || in_array($code, $this->userDefinedAttributes) ) { $attrValue = $this->_localeDate->formatDateTime( From 18cdf9ab3751d717dcaa34d8d02b2e61d4d4fea3 Mon Sep 17 00:00:00 2001 From: Oleksandr Shmyheliuk Date: Wed, 5 Oct 2016 11:00:55 +0300 Subject: [PATCH 6/6] =?UTF-8?q?MAGETWO-58516:=20Product=20catalog=20Import?= =?UTF-8?q?/export=20=E2=80=93=20Date=20&=20Timezone=20issue.=20Other=20fi?= =?UTF-8?q?elds.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - change comparison with constant to string --- app/code/Magento/CatalogImportExport/Model/Export/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Export/Product.php b/app/code/Magento/CatalogImportExport/Model/Export/Product.php index 5cbaa6ce81db6..86b150062d3c0 100644 --- a/app/code/Magento/CatalogImportExport/Model/Export/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Export/Product.php @@ -922,7 +922,7 @@ protected function collectRawData() } $fieldName = isset($this->_fieldsMap[$code]) ? $this->_fieldsMap[$code] : $code; - if ($this->_attributeTypes[$code] === Table::TYPE_DATETIME) { + if ($this->_attributeTypes[$code] == 'datetime') { if (in_array($code, $this->dateAttrCodes) || in_array($code, $this->userDefinedAttributes) ) {