Skip to content

Commit

Permalink
import-export-improvements #82 : configurable variations - not a supe…
Browse files Browse the repository at this point in the history
…r attribute error message improvements
  • Loading branch information
Tadhg Bowe committed Jun 28, 2018
1 parent 70c5c51 commit e99c99e
Showing 1 changed file with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down Expand Up @@ -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])) {
Expand Down

0 comments on commit e99c99e

Please sign in to comment.