Skip to content

Commit 6223196

Browse files
ENGCOM-2174: import-export-improvements #82 : super attribute error message improvements #115
- Merge Pull Request magento-engcom/import-export-improvements#115 from tadhgbowe/import-export-improvements:import-export-issue-82-error-messaging - Merged commits: 1. e99c99e 2. 65bce0a 3. 7f9f6db 4. a76e3a3 5. 3a0599d 6. 6a5b15d 7. b98f417 8. 8db836b
2 parents 0c2fa6f + 8db836b commit 6223196

File tree

1 file changed

+81
-5
lines changed
  • app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type

1 file changed

+81
-5
lines changed

app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type/Configurable.php

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
2525
/**
2626
* Error codes.
2727
*/
28+
const ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST = 'attrCodeDoesNotExist';
29+
30+
const ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE = 'attrCodeNotGlobalScope';
31+
32+
const ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT = 'attrCodeNotTypeSelect';
33+
2834
const ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER = 'attrCodeIsNotSuper';
2935

3036
const ERROR_INVALID_OPTION_VALUE = 'invalidOptionValue';
@@ -39,10 +45,19 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
3945
* Validation failure message template definitions
4046
*
4147
* @var array
48+
*
49+
* Note: Some of these messages exceed maximum limit of 120 characters per line. Split up accordingly.
4250
*/
4351
protected $_messageTemplates = [
44-
self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER => 'Attribute with code "%s" is not super',
45-
self::ERROR_INVALID_OPTION_VALUE => 'Invalid option value for attribute "%s"',
52+
self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST => 'Column configurable_variations: Attribute with code ' .
53+
'"%s" does not exist or is missing from product attribute set',
54+
self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE => 'Column configurable_variations: Attribute with code ' .
55+
'"%s" is not super - it needs to have Global Scope',
56+
self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT => 'Column configurable_variations: Attribute with code ' .
57+
'"%s" is not super - it needs to be Input Type of Dropdown, Visual Swatch or Text Swatch',
58+
self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER => 'Column configurable_variations: Attribute with code ' .
59+
'"%s" is not super',
60+
self::ERROR_INVALID_OPTION_VALUE => 'Column configurable_variations: Invalid option value for attribute "%s"',
4661
self::ERROR_INVALID_WEBSITE => 'Invalid website code for super attribute',
4762
self::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations',
4863
self::ERROR_UNIDENTIFIABLE_VARIATION => 'Configurable variation "%s" is unidentifiable',
@@ -289,10 +304,11 @@ protected function _isParticularAttributesValid(array $rowData, $rowNum)
289304
{
290305
if (!empty($rowData['_super_attribute_code'])) {
291306
$superAttrCode = $rowData['_super_attribute_code'];
292-
293307
if (!$this->_isAttributeSuper($superAttrCode)) {
294-
// check attribute superity
295-
$this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER, $rowNum, $superAttrCode);
308+
// Identify reason why attribute is not super:
309+
if (!$this->identifySuperAttributeError($superAttrCode, $rowNum)) {
310+
$this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER, $rowNum, $superAttrCode);
311+
}
296312
return false;
297313
} elseif (isset($rowData['_super_attribute_option']) && strlen($rowData['_super_attribute_option'])) {
298314
$optionKey = strtolower($rowData['_super_attribute_option']);
@@ -305,6 +321,66 @@ protected function _isParticularAttributesValid(array $rowData, $rowNum)
305321
return true;
306322
}
307323

324+
/**
325+
* Identify exactly why a super attribute code is not super.
326+
*
327+
* @param string $superAttrCode
328+
* @param int $rowNum
329+
* @return bool
330+
*/
331+
private function identifySuperAttributeError($superAttrCode, $rowNum)
332+
{
333+
// This attribute code is not a super attribute. Need to give a clearer message why?
334+
$reasonFound = false;
335+
$codeExists = false;
336+
337+
// Does this attribute code exist?
338+
$sourceAttribute = $this->doesSuperAttributeExist($superAttrCode);
339+
if (is_array($sourceAttribute)) {
340+
$codeExists = true;
341+
// Does attribute have the correct settings?
342+
if (isset($sourceAttribute['is_global']) && $sourceAttribute['is_global'] !== '1') {
343+
$this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_GLOBAL_SCOPE, $rowNum, $superAttrCode);
344+
$reasonFound = true;
345+
} elseif (isset($sourceAttribute['type']) && $sourceAttribute['type'] !== 'select') {
346+
$this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_NOT_TYPE_SELECT, $rowNum, $superAttrCode);
347+
$reasonFound = true;
348+
}
349+
}
350+
351+
if ($codeExists === false) {
352+
$this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST, $rowNum, $superAttrCode);
353+
$reasonFound = true;
354+
}
355+
356+
return $reasonFound;
357+
}
358+
359+
/**
360+
* Does the super attribute exist in the current attribute set?
361+
*
362+
* @param string $superAttrCode
363+
* @return array
364+
*/
365+
private function doesSuperAttributeExist($superAttrCode)
366+
{
367+
$returnAttributeArray = null;
368+
if (is_array(self::$commonAttributesCache)) {
369+
$filteredAttribute = array_filter(
370+
self::$commonAttributesCache,
371+
function ($element) use ($superAttrCode) {
372+
return $element['code'] == $superAttrCode;
373+
}
374+
);
375+
376+
// Return the first element of the filtered array (if found).
377+
if (count($filteredAttribute)) {
378+
$returnAttributeArray = array_shift($filteredAttribute);
379+
}
380+
}
381+
return $returnAttributeArray;
382+
}
383+
308384
/**
309385
* Array of SKU to array of super attribute values for all products.
310386
*

0 commit comments

Comments
 (0)