Skip to content

Commit a48f295

Browse files
ENGCOM-4566: Prevent duplicate variation error during import of configurable products with numerical SKUs #21917
2 parents 8b6da4b + 2eb42ab commit a48f295

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ protected function _parseVariations($rowData)
596596
$additionalRow['_super_attribute_position'] = $position;
597597
$additionalRows[] = $additionalRow;
598598
$additionalRow = [];
599-
$position += 1;
599+
$position ++;
600600
}
601601
} else {
602602
throw new LocalizedException(
@@ -937,7 +937,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
937937
}
938938
foreach ($dataWithExtraVirtualRows as $option) {
939939
if (isset($option['_super_products_sku'])) {
940-
if (in_array($option['_super_products_sku'], $skus)) {
940+
if (in_array($option['_super_products_sku'], $skus, true)) {
941941
$error = true;
942942
$this->_entityModel->addRowError(
943943
sprintf(

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,83 @@ public function testIsRowValid()
616616
}
617617
}
618618

619+
public function testRowValidationForNumericalSkus()
620+
{
621+
// Set _attributes to avoid error in Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType.
622+
$this->setPropertyValue($this->configurable, '_attributes', [
623+
'Default' => [],
624+
]);
625+
// Avoiding errors about attributes not being super
626+
$this->setPropertyValue(
627+
$this->configurable,
628+
'_superAttributes',
629+
[
630+
'testattr2' => [
631+
'options' => [
632+
'attr2val1' => 1,
633+
'attr2val2' => 2,
634+
]
635+
],
636+
]
637+
);
638+
639+
$rowValidationDataProvider = $this->rowValidationDataProvider();
640+
641+
// Checking that variations with duplicate sku are invalid
642+
$result = $this->configurable->isRowValid($rowValidationDataProvider['duplicateProduct'], 0);
643+
$this->assertFalse($result);
644+
645+
// Checking that variations with SKUs that are the same when interpreted as number,
646+
// but different when interpreted as string are valid
647+
$result = $this->configurable->isRowValid($rowValidationDataProvider['nonDuplicateProduct'], 0);
648+
$this->assertTrue($result);
649+
}
650+
651+
/**
652+
* @return array
653+
*/
654+
public function rowValidationDataProvider()
655+
{
656+
return [
657+
'duplicateProduct' => [
658+
'sku' => 'configurableNumericalSkuDuplicateVariation',
659+
'store_view_code' => null,
660+
'attribute_set_code' => 'Default',
661+
'product_type' => 'configurable',
662+
'name' => 'Configurable Product with duplicate numerical SKUs in variations',
663+
'product_websites' => 'website_1',
664+
'configurable_variation_labels' => 'testattr2=Select Configuration',
665+
'configurable_variations' => 'sku=1234.1,'
666+
. 'testattr2=attr2val1,'
667+
. 'display=1|sku=1234.1,'
668+
. 'testattr2=attr2val1,'
669+
. 'display=0',
670+
'_store' => null,
671+
'_attribute_set' => 'Default',
672+
'_type' => 'configurable',
673+
'_product_websites' => 'website_1',
674+
],
675+
'nonDuplicateProduct' => [
676+
'sku' => 'configurableNumericalSkuNonDuplicateVariation',
677+
'store_view_code' => null,
678+
'attribute_set_code' => 'Default',
679+
'product_type' => 'configurable',
680+
'name' => 'Configurable Product with different numerical SKUs in variations',
681+
'product_websites' => 'website_1',
682+
'configurable_variation_labels' => 'testattr2=Select Configuration',
683+
'configurable_variations' => 'sku=1234.10,'
684+
. 'testattr2=attr2val1,'
685+
. 'display=1|sku=1234.1,'
686+
. 'testattr2=attr2val2,'
687+
. 'display=0',
688+
'_store' => null,
689+
'_attribute_set' => 'Default',
690+
'_type' => 'configurable',
691+
'_product_websites' => 'website_1',
692+
]
693+
];
694+
}
695+
619696
/**
620697
* Set object property value.
621698
*

0 commit comments

Comments
 (0)