From e99c99edb075e32d90a98fba9057c8e5affaebe8 Mon Sep 17 00:00:00 2001 From: Tadhg Bowe Date: Thu, 28 Jun 2018 08:48:54 +0100 Subject: [PATCH 01/25] import-export-improvements #82 : configurable variations - not a super attribute error message improvements --- .../Import/Product/Type/Configurable.php | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php index 151bf5aa9263e..939c122b0d9d7 100644 --- a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php @@ -25,6 +25,12 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ /** * Error codes. */ + const ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST = 'attrCodeDoesNotExist'; + + const ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE = 'attrCodeNotGlobalScope'; + + const ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT = 'attrCodeNotTypeSelect'; + const ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER = 'attrCodeIsNotSuper'; const ERROR_INVALID_OPTION_VALUE = 'invalidOptionValue'; @@ -41,8 +47,11 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ * @var array */ protected $_messageTemplates = [ - self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER => 'Attribute with code "%s" is not super', - self::ERROR_INVALID_OPTION_VALUE => 'Invalid option value for attribute "%s"', + self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST => 'Column configurable_variations: Attribute with code "%s" does not exist or is missing from product attribute set', + self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE => 'Column configurable_variations: Attribute with code "%s" is not super - it needs to have Global Scope', + self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT => 'Column configurable_variations: Attribute with code "%s" is not super - it needs to be Input Type of Dropdown, Visual Swatch or Text Swatch', + self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER => 'Column configurable_variations: Attribute with code "%s" is not super', + self::ERROR_INVALID_OPTION_VALUE => 'Column configurable_variations: Invalid option value for attribute "%s"', self::ERROR_INVALID_WEBSITE => 'Invalid website code for super attribute', self::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations', self::ERROR_UNIDENTIFIABLE_VARIATION => 'Configurable variation "%s" is unidentifiable', @@ -291,9 +300,50 @@ protected function _isParticularAttributesValid(array $rowData, $rowNum) $superAttrCode = $rowData['_super_attribute_code']; if (!$this->_isAttributeSuper($superAttrCode)) { - // check attribute superity + // This attribute code is not a super attribute. Need to give a clearer message why? + $codeExists = false; + $codeNotGlobal = false; + $codeNotTypeSelect = false; + // Does this attribute code exist? Does is have the correct settings? + $commonAttributes = self::$commonAttributesCache; + foreach ($commonAttributes as $attributeRow) { + + if ($attributeRow['code'] == $superAttrCode) + { + $codeExists = true; + + if ($attributeRow['is_global'] !== '1') + { + $codeNotGlobal = true; + } + elseif ($attributeRow['type'] !== 'select') + { + $codeNotTypeSelect = true; + } + + break; + } + } + + if ($codeExists == false) + { + $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST, $rowNum, $superAttrCode); + return false; + } + elseif ($codeNotGlobal == true) + { + $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE, $rowNum, $superAttrCode); + return false; + } + elseif ($codeNotTypeSelect == true) + { + $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT, $rowNum, $superAttrCode); + return false; + } + $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER, $rowNum, $superAttrCode); return false; + } elseif (isset($rowData['_super_attribute_option']) && strlen($rowData['_super_attribute_option'])) { $optionKey = strtolower($rowData['_super_attribute_option']); if (!isset($this->_superAttributes[$superAttrCode]['options'][$optionKey])) { From 65bce0aa9e678382bf2f88b3cae2e23d14702391 Mon Sep 17 00:00:00 2001 From: Tadhg Bowe Date: Thu, 28 Jun 2018 16:07:37 +0100 Subject: [PATCH 02/25] import-export-improvements #82 : configurable variations - not a super attribute error message improvements - travis ci build code fix --- .../Import/Product/Type/Configurable.php | 100 ++++++++++-------- 1 file changed, 58 insertions(+), 42 deletions(-) diff --git a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php index 939c122b0d9d7..a3f550d03e8fe 100644 --- a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php @@ -298,52 +298,13 @@ protected function _isParticularAttributesValid(array $rowData, $rowNum) { if (!empty($rowData['_super_attribute_code'])) { $superAttrCode = $rowData['_super_attribute_code']; - if (!$this->_isAttributeSuper($superAttrCode)) { - // This attribute code is not a super attribute. Need to give a clearer message why? - $codeExists = false; - $codeNotGlobal = false; - $codeNotTypeSelect = false; - // Does this attribute code exist? Does is have the correct settings? - $commonAttributes = self::$commonAttributesCache; - foreach ($commonAttributes as $attributeRow) { - - if ($attributeRow['code'] == $superAttrCode) - { - $codeExists = true; - - if ($attributeRow['is_global'] !== '1') - { - $codeNotGlobal = true; - } - elseif ($attributeRow['type'] !== 'select') - { - $codeNotTypeSelect = true; - } - - break; - } - } - - if ($codeExists == false) - { - $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST, $rowNum, $superAttrCode); - return false; - } - elseif ($codeNotGlobal == true) + // Identify reason why attribute is not super: + if (!$this->_identifySuperAttributeError($superAttrCode, $rowNum)) { - $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE, $rowNum, $superAttrCode); - return false; + $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER, $rowNum, $superAttrCode); } - elseif ($codeNotTypeSelect == true) - { - $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT, $rowNum, $superAttrCode); - return false; - } - - $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER, $rowNum, $superAttrCode); return false; - } elseif (isset($rowData['_super_attribute_option']) && strlen($rowData['_super_attribute_option'])) { $optionKey = strtolower($rowData['_super_attribute_option']); if (!isset($this->_superAttributes[$superAttrCode]['options'][$optionKey])) { @@ -355,6 +316,61 @@ protected function _isParticularAttributesValid(array $rowData, $rowNum) return true; } + /** + * Identify exactly why a super attribute code is not super. + * + * @param string $superAttrCode + * @param int $rowNum + * @return bool + */ + protected function _identifySuperAttributeError($superAttrCode, $rowNum) + { + // This attribute code is not a super attribute. Need to give a clearer message why? + $reasonFound = false; + + $codeExists = false; + $codeNotGlobal = false; + $codeNotTypeSelect = false; + // Does this attribute code exist? Does is have the correct settings? + $commonAttributes = self::$commonAttributesCache; + foreach ($commonAttributes as $attributeRow) { + + if ($attributeRow['code'] == $superAttrCode) + { + $codeExists = true; + + if ($attributeRow['is_global'] !== '1') + { + $codeNotGlobal = true; + } + elseif ($attributeRow['type'] !== 'select') + { + $codeNotTypeSelect = true; + } + + break; + } + } + + if ($codeExists == false) + { + $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST, $rowNum, $superAttrCode); + $reasonFound = true; + } + elseif ($codeNotGlobal == true) + { + $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE, $rowNum, $superAttrCode); + $reasonFound = true; + } + elseif ($codeNotTypeSelect == true) + { + $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT, $rowNum, $superAttrCode); + $reasonFound = true; + } + + return $reasonFound; + } + /** * Array of SKU to array of super attribute values for all products. * From 7f9f6db9510508aae12260f517eba7e5ba198742 Mon Sep 17 00:00:00 2001 From: Tadhg Bowe Date: Fri, 29 Jun 2018 14:38:05 +0100 Subject: [PATCH 03/25] import-export-improvements #82 : configurable variations - not a super attribute error message improvements - travis ci build code style fix --- .../Import/Product/Type/Configurable.php | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php index a3f550d03e8fe..07468c429a234 100644 --- a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php @@ -41,10 +41,13 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ const ERROR_UNIDENTIFIABLE_VARIATION = 'unidentifiableVariation'; + // @codingStandardsIgnoreStart /** * Validation failure message template definitions * * @var array + * + * Note: Many of these messages exceed maximum limit of 120 characters. Ignore from coding standards. */ protected $_messageTemplates = [ self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST => 'Column configurable_variations: Attribute with code "%s" does not exist or is missing from product attribute set', @@ -56,6 +59,7 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ self::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations', self::ERROR_UNIDENTIFIABLE_VARIATION => 'Configurable variation "%s" is unidentifiable', ]; + // @codingStandardsIgnoreEnd /** * Column names that holds values with particular meaning. @@ -300,8 +304,7 @@ protected function _isParticularAttributesValid(array $rowData, $rowNum) $superAttrCode = $rowData['_super_attribute_code']; if (!$this->_isAttributeSuper($superAttrCode)) { // Identify reason why attribute is not super: - if (!$this->_identifySuperAttributeError($superAttrCode, $rowNum)) - { + if (!$this->_identifySuperAttributeError($superAttrCode, $rowNum)) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER, $rowNum, $superAttrCode); } return false; @@ -334,17 +337,13 @@ protected function _identifySuperAttributeError($superAttrCode, $rowNum) // Does this attribute code exist? Does is have the correct settings? $commonAttributes = self::$commonAttributesCache; foreach ($commonAttributes as $attributeRow) { - - if ($attributeRow['code'] == $superAttrCode) - { + if ($attributeRow['code'] == $superAttrCode) { $codeExists = true; - if ($attributeRow['is_global'] !== '1') - { + if ($attributeRow['is_global'] !== '1') { $codeNotGlobal = true; } - elseif ($attributeRow['type'] !== 'select') - { + elseif ($attributeRow['type'] !== 'select') { $codeNotTypeSelect = true; } @@ -352,18 +351,15 @@ protected function _identifySuperAttributeError($superAttrCode, $rowNum) } } - if ($codeExists == false) - { + if ($codeExists == false) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST, $rowNum, $superAttrCode); $reasonFound = true; } - elseif ($codeNotGlobal == true) - { + elseif ($codeNotGlobal == true) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE, $rowNum, $superAttrCode); $reasonFound = true; } - elseif ($codeNotTypeSelect == true) - { + elseif ($codeNotTypeSelect == true) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT, $rowNum, $superAttrCode); $reasonFound = true; } From a76e3a3e8cd545b16fda1bd56c5db5d6cf687d56 Mon Sep 17 00:00:00 2001 From: Tadhg Bowe Date: Fri, 29 Jun 2018 20:28:07 +0100 Subject: [PATCH 04/25] import-export-improvements #82 : configurable variations - not a super attribute error message improvements - travis ci build code style fixes --- .../Model/Import/Product/Type/Configurable.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php index 07468c429a234..4f3308ff3d6e1 100644 --- a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php @@ -342,8 +342,7 @@ protected function _identifySuperAttributeError($superAttrCode, $rowNum) if ($attributeRow['is_global'] !== '1') { $codeNotGlobal = true; - } - elseif ($attributeRow['type'] !== 'select') { + } elseif ($attributeRow['type'] !== 'select') { $codeNotTypeSelect = true; } @@ -354,12 +353,10 @@ protected function _identifySuperAttributeError($superAttrCode, $rowNum) if ($codeExists == false) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST, $rowNum, $superAttrCode); $reasonFound = true; - } - elseif ($codeNotGlobal == true) { + } elseif ($codeNotGlobal == true) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE, $rowNum, $superAttrCode); $reasonFound = true; - } - elseif ($codeNotTypeSelect == true) { + } elseif ($codeNotTypeSelect == true) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT, $rowNum, $superAttrCode); $reasonFound = true; } From 3a0599d196e937db48dd1fa81dfdd8f4341903be Mon Sep 17 00:00:00 2001 From: Tadhg Bowe Date: Fri, 6 Jul 2018 11:43:58 +0100 Subject: [PATCH 05/25] import-export-improvements #82 : configurable variations - not a super attribute error message improvements - code styling fixes --- .../Import/Product/Type/Configurable.php | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php index 4f3308ff3d6e1..36e77358936b4 100644 --- a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php @@ -41,25 +41,27 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ const ERROR_UNIDENTIFIABLE_VARIATION = 'unidentifiableVariation'; - // @codingStandardsIgnoreStart /** * Validation failure message template definitions * * @var array * - * Note: Many of these messages exceed maximum limit of 120 characters. Ignore from coding standards. + * Note: Some of these messages exceed maximum limit of 120 characters per line. Split up accordingly. */ protected $_messageTemplates = [ - self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST => 'Column configurable_variations: Attribute with code "%s" does not exist or is missing from product attribute set', - self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE => 'Column configurable_variations: Attribute with code "%s" is not super - it needs to have Global Scope', - self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT => 'Column configurable_variations: Attribute with code "%s" is not super - it needs to be Input Type of Dropdown, Visual Swatch or Text Swatch', - self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER => 'Column configurable_variations: Attribute with code "%s" is not super', + self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST => 'Column configurable_variations: Attribute with code ' . + '"%s" does not exist or is missing from product attribute set', + self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE => 'Column configurable_variations: Attribute with code ' . + '"%s" is not super - it needs to have Global Scope', + self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT => 'Column configurable_variations: Attribute with code ' . + '"%s" is not super - it needs to be Input Type of Dropdown, Visual Swatch or Text Swatch', + self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER => 'Column configurable_variations: Attribute with code ' . + '"%s" is not super', self::ERROR_INVALID_OPTION_VALUE => 'Column configurable_variations: Invalid option value for attribute "%s"', self::ERROR_INVALID_WEBSITE => 'Invalid website code for super attribute', self::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations', self::ERROR_UNIDENTIFIABLE_VARIATION => 'Configurable variation "%s" is unidentifiable', ]; - // @codingStandardsIgnoreEnd /** * Column names that holds values with particular meaning. @@ -304,7 +306,7 @@ protected function _isParticularAttributesValid(array $rowData, $rowNum) $superAttrCode = $rowData['_super_attribute_code']; if (!$this->_isAttributeSuper($superAttrCode)) { // Identify reason why attribute is not super: - if (!$this->_identifySuperAttributeError($superAttrCode, $rowNum)) { + if (!$this->identifySuperAttributeError($superAttrCode, $rowNum)) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER, $rowNum, $superAttrCode); } return false; @@ -326,7 +328,7 @@ protected function _isParticularAttributesValid(array $rowData, $rowNum) * @param int $rowNum * @return bool */ - protected function _identifySuperAttributeError($superAttrCode, $rowNum) + private function identifySuperAttributeError($superAttrCode, $rowNum) { // This attribute code is not a super attribute. Need to give a clearer message why? $reasonFound = false; @@ -334,23 +336,28 @@ protected function _identifySuperAttributeError($superAttrCode, $rowNum) $codeExists = false; $codeNotGlobal = false; $codeNotTypeSelect = false; - // Does this attribute code exist? Does is have the correct settings? - $commonAttributes = self::$commonAttributesCache; - foreach ($commonAttributes as $attributeRow) { - if ($attributeRow['code'] == $superAttrCode) { - $codeExists = true; + // Does this attribute code exist? Does it have the correct settings? + $filterAttribute = array_filter( + self::$commonAttributesCache, + function ($element) use($superAttrCode) { + return $element['code'] == $superAttrCode; + } + ); - if ($attributeRow['is_global'] !== '1') { + if (is_array($filterAttribute) && count($filterAttribute)) { + $codeExists = true; + // Examine the first element of the filtered array + $sourceAttribute = array_shift($filterAttribute); + if (is_array($sourceAttribute)) { + if (isset($sourceAttribute['is_global']) && $sourceAttribute['is_global'] !== '1') { $codeNotGlobal = true; - } elseif ($attributeRow['type'] !== 'select') { + } elseif (isset($sourceAttribute['type']) && $sourceAttribute['type'] !== 'select') { $codeNotTypeSelect = true; } - - break; } } - if ($codeExists == false) { + if ($codeExists === false) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST, $rowNum, $superAttrCode); $reasonFound = true; } elseif ($codeNotGlobal == true) { From 6a5b15d7a691fa494921b3ee1ad0949ea607da16 Mon Sep 17 00:00:00 2001 From: Tadhg Bowe Date: Fri, 6 Jul 2018 14:44:13 +0100 Subject: [PATCH 06/25] import-export-improvements #82 : configurable variations - not a super attribute error message improvements - code styling Travis CI build fixes --- .../Import/Product/Type/Configurable.php | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php index 36e77358936b4..43da5661e966b 100644 --- a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php @@ -336,18 +336,11 @@ private function identifySuperAttributeError($superAttrCode, $rowNum) $codeExists = false; $codeNotGlobal = false; $codeNotTypeSelect = false; - // Does this attribute code exist? Does it have the correct settings? - $filterAttribute = array_filter( - self::$commonAttributesCache, - function ($element) use($superAttrCode) { - return $element['code'] == $superAttrCode; - } - ); - - if (is_array($filterAttribute) && count($filterAttribute)) { + // Does this attribute code exist? + $sourceAttribute = $this->doesSuperAttributeExist($superAttrCode); + if (count($sourceAttribute)) { $codeExists = true; - // Examine the first element of the filtered array - $sourceAttribute = array_shift($filterAttribute); + // Does attribute have the correct settings? if (is_array($sourceAttribute)) { if (isset($sourceAttribute['is_global']) && $sourceAttribute['is_global'] !== '1') { $codeNotGlobal = true; @@ -357,13 +350,14 @@ function ($element) use($superAttrCode) { } } + // Identify (if any) the correct fault: if ($codeExists === false) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST, $rowNum, $superAttrCode); $reasonFound = true; - } elseif ($codeNotGlobal == true) { + } elseif ($codeNotGlobal === true) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE, $rowNum, $superAttrCode); $reasonFound = true; - } elseif ($codeNotTypeSelect == true) { + } elseif ($codeNotTypeSelect === true) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT, $rowNum, $superAttrCode); $reasonFound = true; } @@ -371,6 +365,30 @@ function ($element) use($superAttrCode) { return $reasonFound; } + /** + * Does the super attribute exist in the current attribute set? + * + * @param string $superAttrCode + * @return array + */ + private function doesSuperAttributeExist($superAttrCode) + { + $returnFilterArray = []; + if (is_array(self::$commonAttributesCache)) + { + $filteredAttribute = array_filter( + self::$commonAttributesCache, + function ($element) use ($superAttrCode) { + return $element['code'] == $superAttrCode; + } + ); + + // Return the first element of the filtered array. + $returnFilterArray = array_shift($filteredAttribute); + } + return $returnFilterArray; + } + /** * Array of SKU to array of super attribute values for all products. * From b98f41796650d36e44fcd2cb42d02bb09cf8ccd1 Mon Sep 17 00:00:00 2001 From: Tadhg Bowe Date: Sat, 7 Jul 2018 12:38:15 +0100 Subject: [PATCH 07/25] import-export-improvements #82 : configurable variations - not a super attribute error message improvements - code styling Travis CI build fixes --- .../Import/Product/Type/Configurable.php | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php index 43da5661e966b..5969f872616e0 100644 --- a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php @@ -332,34 +332,25 @@ private function identifySuperAttributeError($superAttrCode, $rowNum) { // This attribute code is not a super attribute. Need to give a clearer message why? $reasonFound = false; - $codeExists = false; - $codeNotGlobal = false; - $codeNotTypeSelect = false; + // Does this attribute code exist? $sourceAttribute = $this->doesSuperAttributeExist($superAttrCode); - if (count($sourceAttribute)) { + if (!is_null($sourceAttribute)) { $codeExists = true; // Does attribute have the correct settings? - if (is_array($sourceAttribute)) { - if (isset($sourceAttribute['is_global']) && $sourceAttribute['is_global'] !== '1') { - $codeNotGlobal = true; - } elseif (isset($sourceAttribute['type']) && $sourceAttribute['type'] !== 'select') { - $codeNotTypeSelect = true; - } + if (isset($sourceAttribute['is_global']) && $sourceAttribute['is_global'] !== '1') { + $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE, $rowNum, $superAttrCode); + $reasonFound = true; + } elseif (isset($sourceAttribute['type']) && $sourceAttribute['type'] !== 'select') { + $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT, $rowNum, $superAttrCode); + $reasonFound = true; } } - // Identify (if any) the correct fault: if ($codeExists === false) { $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST, $rowNum, $superAttrCode); $reasonFound = true; - } elseif ($codeNotGlobal === true) { - $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE, $rowNum, $superAttrCode); - $reasonFound = true; - } elseif ($codeNotTypeSelect === true) { - $this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT, $rowNum, $superAttrCode); - $reasonFound = true; } return $reasonFound; @@ -373,9 +364,8 @@ private function identifySuperAttributeError($superAttrCode, $rowNum) */ private function doesSuperAttributeExist($superAttrCode) { - $returnFilterArray = []; - if (is_array(self::$commonAttributesCache)) - { + $returnAttributeArray = null; + if (is_array(self::$commonAttributesCache)) { $filteredAttribute = array_filter( self::$commonAttributesCache, function ($element) use ($superAttrCode) { @@ -383,10 +373,13 @@ function ($element) use ($superAttrCode) { } ); - // Return the first element of the filtered array. - $returnFilterArray = array_shift($filteredAttribute); + // Return the first element of the filtered array (if found). + if (count($filteredAttribute)) + { + $returnAttributeArray = array_shift($filteredAttribute); + } } - return $returnFilterArray; + return $returnAttributeArray; } /** From 8db836b16fa92aeed478173b7ad857f51cd70591 Mon Sep 17 00:00:00 2001 From: Tadhg Bowe Date: Sat, 7 Jul 2018 15:11:33 +0100 Subject: [PATCH 08/25] import-export-improvements #82 : configurable variations - not a super attribute error message improvements - code styling Travis CI build fixes --- .../Model/Import/Product/Type/Configurable.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php index 5969f872616e0..fdbd8560c2664 100644 --- a/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php @@ -336,7 +336,7 @@ private function identifySuperAttributeError($superAttrCode, $rowNum) // Does this attribute code exist? $sourceAttribute = $this->doesSuperAttributeExist($superAttrCode); - if (!is_null($sourceAttribute)) { + if (is_array($sourceAttribute)) { $codeExists = true; // Does attribute have the correct settings? if (isset($sourceAttribute['is_global']) && $sourceAttribute['is_global'] !== '1') { @@ -374,8 +374,7 @@ function ($element) use ($superAttrCode) { ); // Return the first element of the filtered array (if found). - if (count($filteredAttribute)) - { + if (count($filteredAttribute)) { $returnAttributeArray = array_shift($filteredAttribute); } } From 20483c523dd1de12365530c2ae18f11bfb6f21b7 Mon Sep 17 00:00:00 2001 From: NamrataChangani Date: Tue, 10 Jul 2018 18:29:16 +0530 Subject: [PATCH 09/25] Added 'title' attribute to 'img' tag in knockout template files. --- .../Braintree/view/frontend/web/template/payment/paypal.html | 2 +- .../Captcha/view/frontend/web/template/checkout/captcha.html | 1 + .../Catalog/view/adminhtml/web/template/image-preview.html | 3 ++- .../view/base/web/template/product/list/columns/image.html | 1 + .../web/template/product/list/columns/image_with_borders.html | 2 +- .../frontend/web/template/summary/item/details/thumbnail.html | 2 +- 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Braintree/view/frontend/web/template/payment/paypal.html b/app/code/Magento/Braintree/view/frontend/web/template/payment/paypal.html index f5c8c15c8f3ba..e47024b7d2330 100644 --- a/app/code/Magento/Braintree/view/frontend/web/template/payment/paypal.html +++ b/app/code/Magento/Braintree/view/frontend/web/template/payment/paypal.html @@ -12,7 +12,7 @@ data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()" />