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 - code styling Travis CI build fixes
  • Loading branch information
Tadhg Bowe committed Jul 7, 2018
1 parent 6a5b15d commit b98f417
Showing 1 changed file with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -373,20 +364,22 @@ 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) {
return $element['code'] == $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;
}

/**
Expand Down

0 comments on commit b98f417

Please sign in to comment.