Skip to content

Commit 3a0599d

Browse files
author
Tadhg Bowe
committed
import-export-improvements #82 : configurable variations - not a super attribute error message improvements - code styling fixes
1 parent a76e3a3 commit 3a0599d

File tree

1 file changed

+26
-19
lines changed
  • app/code/Magento/ConfigurableImportExport/Model/Import/Product/Type

1 file changed

+26
-19
lines changed

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

+26-19
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,27 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
4141

4242
const ERROR_UNIDENTIFIABLE_VARIATION = 'unidentifiableVariation';
4343

44-
// @codingStandardsIgnoreStart
4544
/**
4645
* Validation failure message template definitions
4746
*
4847
* @var array
4948
*
50-
* Note: Many of these messages exceed maximum limit of 120 characters. Ignore from coding standards.
49+
* Note: Some of these messages exceed maximum limit of 120 characters per line. Split up accordingly.
5150
*/
5251
protected $_messageTemplates = [
53-
self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST => 'Column configurable_variations: Attribute with code "%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 "%s" is not super - it needs to have Global Scope',
55-
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',
56-
self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER => 'Column configurable_variations: Attribute with code "%s" is not super',
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',
5760
self::ERROR_INVALID_OPTION_VALUE => 'Column configurable_variations: Invalid option value for attribute "%s"',
5861
self::ERROR_INVALID_WEBSITE => 'Invalid website code for super attribute',
5962
self::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations',
6063
self::ERROR_UNIDENTIFIABLE_VARIATION => 'Configurable variation "%s" is unidentifiable',
6164
];
62-
// @codingStandardsIgnoreEnd
6365

6466
/**
6567
* Column names that holds values with particular meaning.
@@ -304,7 +306,7 @@ protected function _isParticularAttributesValid(array $rowData, $rowNum)
304306
$superAttrCode = $rowData['_super_attribute_code'];
305307
if (!$this->_isAttributeSuper($superAttrCode)) {
306308
// Identify reason why attribute is not super:
307-
if (!$this->_identifySuperAttributeError($superAttrCode, $rowNum)) {
309+
if (!$this->identifySuperAttributeError($superAttrCode, $rowNum)) {
308310
$this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_IS_NOT_SUPER, $rowNum, $superAttrCode);
309311
}
310312
return false;
@@ -326,31 +328,36 @@ protected function _isParticularAttributesValid(array $rowData, $rowNum)
326328
* @param int $rowNum
327329
* @return bool
328330
*/
329-
protected function _identifySuperAttributeError($superAttrCode, $rowNum)
331+
private function identifySuperAttributeError($superAttrCode, $rowNum)
330332
{
331333
// This attribute code is not a super attribute. Need to give a clearer message why?
332334
$reasonFound = false;
333335

334336
$codeExists = false;
335337
$codeNotGlobal = false;
336338
$codeNotTypeSelect = false;
337-
// Does this attribute code exist? Does is have the correct settings?
338-
$commonAttributes = self::$commonAttributesCache;
339-
foreach ($commonAttributes as $attributeRow) {
340-
if ($attributeRow['code'] == $superAttrCode) {
341-
$codeExists = true;
339+
// Does this attribute code exist? Does it have the correct settings?
340+
$filterAttribute = array_filter(
341+
self::$commonAttributesCache,
342+
function ($element) use($superAttrCode) {
343+
return $element['code'] == $superAttrCode;
344+
}
345+
);
342346

343-
if ($attributeRow['is_global'] !== '1') {
347+
if (is_array($filterAttribute) && count($filterAttribute)) {
348+
$codeExists = true;
349+
// Examine the first element of the filtered array
350+
$sourceAttribute = array_shift($filterAttribute);
351+
if (is_array($sourceAttribute)) {
352+
if (isset($sourceAttribute['is_global']) && $sourceAttribute['is_global'] !== '1') {
344353
$codeNotGlobal = true;
345-
} elseif ($attributeRow['type'] !== 'select') {
354+
} elseif (isset($sourceAttribute['type']) && $sourceAttribute['type'] !== 'select') {
346355
$codeNotTypeSelect = true;
347356
}
348-
349-
break;
350357
}
351358
}
352359

353-
if ($codeExists == false) {
360+
if ($codeExists === false) {
354361
$this->_entityModel->addRowError(self::ERROR_ATTRIBUTE_CODE_DOES_NOT_EXIST, $rowNum, $superAttrCode);
355362
$reasonFound = true;
356363
} elseif ($codeNotGlobal == true) {

0 commit comments

Comments
 (0)