From 188ff102a8965495b9d8809a86dc8cd93d27184e Mon Sep 17 00:00:00 2001 From: Volodymyr Klymenko Date: Thu, 29 Oct 2015 12:51:50 +0200 Subject: [PATCH 1/5] MAGETWO-43336: Catalog Price Rules don't work when based on configurable attribute --- .../Model/Rule/ConfigurableProductHandler.php | 44 +++++-------------- .../Rule/ConfigurableProductHandlerTest.php | 4 -- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php b/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php index b8f8b78108fc9..4b2ce6aa43ba7 100644 --- a/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php +++ b/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php @@ -20,9 +20,6 @@ class ConfigurableProductHandler /** @var ConfigurableProductsProvider */ private $configurableProductsProvider; - /** @var array */ - private $subProductsValidationResults = []; - /** * @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurable * @param ConfigurableProductsProvider $configurableProductsProvider @@ -44,40 +41,19 @@ public function afterGetMatchingProductIds(\Magento\CatalogRule\Model\Rule $rule { $configurableProductIds = $this->configurableProductsProvider->getIds(array_keys($productIds)); foreach ($configurableProductIds as $productId) { - $subProductsIds = $this->configurable->getChildrenIds($productId)[0]; - $parentValidationResult = $productIds[$productId]; - foreach ($subProductsIds as $subProductsId) { - $productIds[$subProductsId] = $this->getSubProductValidationResult( - $rule->getId(), - $subProductsId, - $parentValidationResult - ); + $subProductIds = $this->configurable->getChildrenIds($productId)[0]; + foreach ($subProductIds as $subProductId) { + $parentValidationResult = isset($productIds[$productId]) + ? array_filter($productIds[$productId]) + : []; + $childValidationResult = isset($productIds[$subProductId]) + ? array_filter($productIds[$subProductId]) + : []; + + $productIds[$subProductId] = $parentValidationResult + $childValidationResult; } unset($productIds[$productId]); } return $productIds; } - - /** - * Return validation result for sub-product. - * If any of configurable product is valid for current rule, then their sub-product must be valid too - * - * @param int $urlId - * @param int $subProductsId - * @param array $parentValidationResult - * @return array - */ - private function getSubProductValidationResult($urlId, $subProductsId, $parentValidationResult) - { - if (!isset($this->subProductsValidationResults[$urlId][$subProductsId])) { - $this->subProductsValidationResults[$urlId][$subProductsId] = array_filter($parentValidationResult); - } else { - $parentValidationResult = array_intersect_key( - $this->subProductsValidationResults[$urlId][$subProductsId] + $parentValidationResult, - $parentValidationResult - ); - $this->subProductsValidationResults[$urlId][$subProductsId] = $parentValidationResult; - } - return $parentValidationResult; - } } diff --git a/app/code/Magento/CatalogRuleConfigurable/Test/Unit/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandlerTest.php b/app/code/Magento/CatalogRuleConfigurable/Test/Unit/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandlerTest.php index 5878f7eea8702..90f7856dc81af 100644 --- a/app/code/Magento/CatalogRuleConfigurable/Test/Unit/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandlerTest.php +++ b/app/code/Magento/CatalogRuleConfigurable/Test/Unit/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandlerTest.php @@ -93,13 +93,9 @@ public function testAfterGetMatchingProductIdsWithConfigurableProduct() 0 => true, 1 => true, 3 => true, - 4 => false, ], 'simple2' => [ - 0 => false, - 1 => false, 3 => true, - 4 => false, ] ], $this->configurableProductHandler->afterGetMatchingProductIds( From 6960abff1cee947432201256e24fbdec5c88b396 Mon Sep 17 00:00:00 2001 From: Volodymyr Klymenko Date: Thu, 29 Oct 2015 13:33:33 +0200 Subject: [PATCH 2/5] MAGETWO-43336: Catalog Price Rules don't work when based on configurable attribute --- .../CatalogRule/Model/Rule/ConfigurableProductHandler.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php b/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php index 4b2ce6aa43ba7..dfd897fcf2a6a 100644 --- a/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php +++ b/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php @@ -42,14 +42,13 @@ public function afterGetMatchingProductIds(\Magento\CatalogRule\Model\Rule $rule $configurableProductIds = $this->configurableProductsProvider->getIds(array_keys($productIds)); foreach ($configurableProductIds as $productId) { $subProductIds = $this->configurable->getChildrenIds($productId)[0]; + $parentValidationResult = isset($productIds[$productId]) + ? array_filter($productIds[$productId]) + : []; foreach ($subProductIds as $subProductId) { - $parentValidationResult = isset($productIds[$productId]) - ? array_filter($productIds[$productId]) - : []; $childValidationResult = isset($productIds[$subProductId]) ? array_filter($productIds[$subProductId]) : []; - $productIds[$subProductId] = $parentValidationResult + $childValidationResult; } unset($productIds[$productId]); From f4a16c10c344fbd657b9353bad2c952fdc7369f0 Mon Sep 17 00:00:00 2001 From: Volodymyr Klymenko Date: Fri, 30 Oct 2015 17:29:29 +0200 Subject: [PATCH 3/5] MAGETWO-43336: Catalog Price Rules don't work when based on configurable attribute --- .../Model/Rule/ConfigurableProductHandler.php | 44 +++++-------------- .../Rule/ConfigurableProductHandlerTest.php | 4 -- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php b/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php index b8f8b78108fc9..8c7eff09a889c 100644 --- a/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php +++ b/app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandler.php @@ -20,9 +20,6 @@ class ConfigurableProductHandler /** @var ConfigurableProductsProvider */ private $configurableProductsProvider; - /** @var array */ - private $subProductsValidationResults = []; - /** * @param \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurable * @param ConfigurableProductsProvider $configurableProductsProvider @@ -39,45 +36,24 @@ public function __construct( * @param \Magento\CatalogRule\Model\Rule $rule * @param array $productIds * @return array + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetMatchingProductIds(\Magento\CatalogRule\Model\Rule $rule, array $productIds) { $configurableProductIds = $this->configurableProductsProvider->getIds(array_keys($productIds)); foreach ($configurableProductIds as $productId) { - $subProductsIds = $this->configurable->getChildrenIds($productId)[0]; - $parentValidationResult = $productIds[$productId]; - foreach ($subProductsIds as $subProductsId) { - $productIds[$subProductsId] = $this->getSubProductValidationResult( - $rule->getId(), - $subProductsId, - $parentValidationResult - ); + $subProductIds = $this->configurable->getChildrenIds($productId)[0]; + $parentValidationResult = isset($productIds[$productId]) + ? array_filter($productIds[$productId]) + : []; + foreach ($subProductIds as $subProductId) { + $childValidationResult = isset($productIds[$subProductId]) + ? array_filter($productIds[$subProductId]) + : []; + $productIds[$subProductId] = $parentValidationResult + $childValidationResult; } unset($productIds[$productId]); } return $productIds; } - - /** - * Return validation result for sub-product. - * If any of configurable product is valid for current rule, then their sub-product must be valid too - * - * @param int $urlId - * @param int $subProductsId - * @param array $parentValidationResult - * @return array - */ - private function getSubProductValidationResult($urlId, $subProductsId, $parentValidationResult) - { - if (!isset($this->subProductsValidationResults[$urlId][$subProductsId])) { - $this->subProductsValidationResults[$urlId][$subProductsId] = array_filter($parentValidationResult); - } else { - $parentValidationResult = array_intersect_key( - $this->subProductsValidationResults[$urlId][$subProductsId] + $parentValidationResult, - $parentValidationResult - ); - $this->subProductsValidationResults[$urlId][$subProductsId] = $parentValidationResult; - } - return $parentValidationResult; - } } diff --git a/app/code/Magento/CatalogRuleConfigurable/Test/Unit/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandlerTest.php b/app/code/Magento/CatalogRuleConfigurable/Test/Unit/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandlerTest.php index 5878f7eea8702..90f7856dc81af 100644 --- a/app/code/Magento/CatalogRuleConfigurable/Test/Unit/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandlerTest.php +++ b/app/code/Magento/CatalogRuleConfigurable/Test/Unit/Plugin/CatalogRule/Model/Rule/ConfigurableProductHandlerTest.php @@ -93,13 +93,9 @@ public function testAfterGetMatchingProductIdsWithConfigurableProduct() 0 => true, 1 => true, 3 => true, - 4 => false, ], 'simple2' => [ - 0 => false, - 1 => false, 3 => true, - 4 => false, ] ], $this->configurableProductHandler->afterGetMatchingProductIds( From 7d47a616fb80b220389ccdbcb31c40cdfa4b4343 Mon Sep 17 00:00:00 2001 From: Alex Bomko Date: Mon, 2 Nov 2015 03:32:22 +0200 Subject: [PATCH 4/5] MAGETWO-44779: Issue with values for custom product attribute of type text area when product is updated via import --- .../CatalogImportExport/Model/Import/Product.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index 066e0cf166ee1..c31169fa2821c 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -2223,9 +2223,13 @@ private function _parseAdditionalAttributes($rowData) $attributeNameValuePairs = explode($this->getMultipleValueSeparator(), $rowData['additional_attributes']); foreach ($attributeNameValuePairs as $attributeNameValuePair) { - $nameAndValue = explode(self::PAIR_NAME_VALUE_SEPARATOR, $attributeNameValuePair); - if (!empty($nameAndValue)) { - $rowData[$nameAndValue[0]] = isset($nameAndValue[1]) ? $nameAndValue[1] : ''; + $separatorPosition = strpos($attributeNameValuePair, self::PAIR_NAME_VALUE_SEPARATOR); + if ($separatorPosition !== false) { + $key = substr($attributeNameValuePair, 0, $separatorPosition); + $rowData[$key] = substr( + $attributeNameValuePair, + $separatorPosition + strlen(self::PAIR_NAME_VALUE_SEPARATOR) + ); } } return $rowData; From 53fbce199a2dec8682657b0601aaf3c2ecdb07e6 Mon Sep 17 00:00:00 2001 From: Alex Bomko Date: Mon, 2 Nov 2015 03:40:00 +0200 Subject: [PATCH 5/5] MAGETWO-44779: Issue with values for custom product attribute of type text area when product is updated via import --- app/code/Magento/CatalogImportExport/Model/Import/Product.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index c31169fa2821c..142c4bb7b5f5c 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -2226,10 +2226,11 @@ private function _parseAdditionalAttributes($rowData) $separatorPosition = strpos($attributeNameValuePair, self::PAIR_NAME_VALUE_SEPARATOR); if ($separatorPosition !== false) { $key = substr($attributeNameValuePair, 0, $separatorPosition); - $rowData[$key] = substr( + $value = substr( $attributeNameValuePair, $separatorPosition + strlen(self::PAIR_NAME_VALUE_SEPARATOR) ); + $rowData[$key] = $value === false ? '' : $value; } } return $rowData;