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 - travis ci build code fix
  • Loading branch information
Tadhg Bowe committed Jun 28, 2018
1 parent e99c99e commit 65bce0a
Showing 1 changed file with 58 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand All @@ -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.
*
Expand Down

0 comments on commit 65bce0a

Please sign in to comment.