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. *