Skip to content

Commit 231bfa2

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-83820' into 2.3-develop-pr13
2 parents aa30a4c + 8632bc5 commit 231bfa2

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Api\Data\ProductInterface;
1212
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
1313
use Magento\Framework\EntityManager\MetadataPool;
14+
use Magento\Framework\Exception\LocalizedException;
1415

1516
/**
1617
* Importing configurable products
@@ -32,6 +33,8 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
3233

3334
const ERROR_DUPLICATED_VARIATIONS = 'duplicatedVariations';
3435

36+
const ERROR_UNIDENTIFIABLE_VARIATION = 'unidentifiableVariation';
37+
3538
/**
3639
* Validation failure message template definitions
3740
*
@@ -42,6 +45,7 @@ class Configurable extends \Magento\CatalogImportExport\Model\Import\Product\Typ
4245
self::ERROR_INVALID_OPTION_VALUE => 'Invalid option value for attribute "%s"',
4346
self::ERROR_INVALID_WEBSITE => 'Invalid website code for super attribute',
4447
self::ERROR_DUPLICATED_VARIATIONS => 'SKU %s contains duplicated variations',
48+
self::ERROR_UNIDENTIFIABLE_VARIATION => 'Configurable variation "%s" is unidentifiable',
4549
];
4650

4751
/**
@@ -469,13 +473,14 @@ protected function _processSuperData()
469473
* @param array $rowData
470474
*
471475
* @return array
476+
* @throws LocalizedException
472477
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
473478
* @SuppressWarnings(PHPMD.NPathComplexity)
474479
*/
475480
protected function _parseVariations($rowData)
476481
{
477482
$additionalRows = [];
478-
if (!isset($rowData['configurable_variations'])) {
483+
if (empty($rowData['configurable_variations'])) {
479484
return $additionalRows;
480485
}
481486
$variations = explode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $rowData['configurable_variations']);
@@ -488,7 +493,8 @@ protected function _parseVariations($rowData)
488493
$nameAndValue = explode(ImportProduct::PAIR_NAME_VALUE_SEPARATOR, $nameAndValue);
489494
if (!empty($nameAndValue)) {
490495
$value = isset($nameAndValue[1]) ? trim($nameAndValue[1]) : '';
491-
$fieldName = trim($nameAndValue[0]);
496+
// Ignoring field names' case.
497+
$fieldName = strtolower(trim($nameAndValue[0]));
492498
if ($fieldName) {
493499
$fieldAndValuePairs[$fieldName] = $value;
494500
}
@@ -509,8 +515,18 @@ protected function _parseVariations($rowData)
509515
$additionalRow = [];
510516
$position += 1;
511517
}
518+
} else {
519+
throw new LocalizedException(
520+
__(
521+
sprintf(
522+
$this->_messageTemplates[self::ERROR_UNIDENTIFIABLE_VARIATION],
523+
$variation
524+
)
525+
)
526+
);
512527
}
513528
}
529+
514530
return $additionalRows;
515531
}
516532

@@ -821,7 +837,14 @@ protected function configurableInBunch($bunch)
821837
public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
822838
{
823839
$error = false;
824-
$dataWithExtraVirtualRows = $this->_parseVariations($rowData);
840+
try {
841+
$dataWithExtraVirtualRows = $this->_parseVariations($rowData);
842+
} catch (LocalizedException $exception) {
843+
$this->_entityModel->addRowError($exception->getMessage(), $rowNum);
844+
845+
return false;
846+
}
847+
825848
$skus = [];
826849
$rowData['price'] = isset($rowData['price']) && $rowData['price'] ? $rowData['price'] : '0.00';
827850
if (!empty($dataWithExtraVirtualRows)) {
@@ -845,6 +868,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
845868
}
846869
$error |= !parent::isRowValid($option, $rowNum, $isNewProduct);
847870
}
871+
848872
return !$error;
849873
}
850874

app/code/Magento/ConfigurableImportExport/Test/Unit/Model/Import/Product/Type/ConfigurableTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,56 @@ public function testIsRowValid()
560560
'_type' => 'configurable',
561561
'_product_websites' => 'website_1',
562562
];
563+
// Checking that variations' field names are case-insensitive with this
564+
// product.
565+
$caseInsensitiveSKU = 'configurableskuI22CaseInsensitive';
566+
$caseInsensitiveProduct = [
567+
'sku' => $caseInsensitiveSKU,
568+
'store_view_code' => null,
569+
'attribute_set_code' => 'Default',
570+
'product_type' => 'configurable',
571+
'name' => 'Configurable Product 21',
572+
'product_websites' => 'website_1',
573+
'configurable_variation_labels' => 'testattr2=Select Color, testattr3=Select Size',
574+
'configurable_variations' => 'SKU=testconf2-attr2val1-testattr3v1,'
575+
. 'testattr2=attr2val1,'
576+
. 'testattr3=testattr3v1,'
577+
. 'display=1|sku=testconf2-attr2val1-testattr3v2,'
578+
. 'testattr2=attr2val1,'
579+
. 'testattr3=testattr3v2,'
580+
. 'display=0',
581+
'_store' => null,
582+
'_attribute_set' => 'Default',
583+
'_type' => 'configurable',
584+
'_product_websites' => 'website_1',
585+
];
563586
$bunch[] = $badProduct;
587+
$bunch[] = $caseInsensitiveProduct;
564588
// Set _attributes to avoid error in Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType.
565589
$this->setPropertyValue($this->configurable, '_attributes', [
566590
$badProduct[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [],
567591
]);
592+
// Avoiding errors about attributes not being super
593+
$this->setPropertyValue(
594+
$this->configurable,
595+
'_superAttributes',
596+
[
597+
'testattr2' => ['options' => ['attr2val1' => 1]],
598+
'testattr3' => [
599+
'options' => [
600+
'testattr3v2' => 1,
601+
'testattr3v1' => 1,
602+
],
603+
],
604+
]
605+
);
568606

569607
foreach ($bunch as $rowData) {
570608
$result = $this->configurable->isRowValid($rowData, 0, !isset($this->_oldSku[$rowData['sku']]));
571609
$this->assertNotNull($result);
610+
if ($rowData['sku'] === $caseInsensitiveSKU) {
611+
$this->assertTrue($result);
612+
}
572613
}
573614
}
574615

0 commit comments

Comments
 (0)