Skip to content

Commit fb625cf

Browse files
committed
Merge remote-tracking branch 'magento-l3/ACP2E-2028' into AUG102023_PR_pradeep
2 parents c67ff43 + ed8f4d1 commit fb625cf

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,19 +1332,23 @@ protected function _importData()
13321332
$parentCount = [];
13331333
$childCount = [];
13341334
$optionsToRemove = [];
1335+
$optionCount = $valueCount = 0;
13351336
foreach ($bunch as $rowNumber => $rowData) {
13361337
$rowSku = !empty($rowData[self::COLUMN_SKU])
13371338
? mb_strtolower($rowData[self::COLUMN_SKU])
13381339
: '';
13391340

1341+
$multiRowData = $this->_getMultiRowFormat($rowData);
13401342
if ($rowSku !== $prevRowSku) {
13411343
$nextOptionId = $optionId ?? $nextOptionId;
13421344
$nextValueId = $valueId ?? $nextValueId;
13431345
$prevRowSku = $rowSku;
1346+
} elseif (count($multiRowData) === 0) {
1347+
$nextOptionId += $optionCount;
1348+
$nextValueId += $valueCount;
13441349
}
13451350
$optionId = $nextOptionId;
13461351
$valueId = $nextValueId;
1347-
$multiRowData = $this->_getMultiRowFormat($rowData);
13481352
if (!empty($rowData[self::COLUMN_SKU]) && $this->skuStorage->has($rowData[self::COLUMN_SKU])) {
13491353
$productData = $this->skuStorage->get($rowData[self::COLUMN_SKU]);
13501354
$this->_rowProductId = $productData[$this->getProductEntityLinkField()];
@@ -1360,6 +1364,7 @@ protected function _importData()
13601364
}
13611365
}
13621366

1367+
$optionCount = $valueCount = 0;
13631368
foreach ($multiRowData as $combinedData) {
13641369
foreach ($rowData as $key => $field) {
13651370
$combinedData[$key] = $field;
@@ -1378,6 +1383,7 @@ protected function _importData()
13781383
);
13791384
if ($optionData) {
13801385
$options[$optionData['option_id']] = $optionData;
1386+
$optionCount++;
13811387
}
13821388
$this->_collectOptionTypeData(
13831389
$combinedData,
@@ -1389,6 +1395,7 @@ protected function _importData()
13891395
$parentCount,
13901396
$childCount
13911397
);
1398+
$valueCount++;
13921399

13931400
$this->_collectOptionTitle($combinedData, $prevOptionId, $titles);
13941401
}

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest/ProductOptionsTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,4 +958,71 @@ private function getFullExpectedOptions(array $expected): array
958958
}
959959
return $expected;
960960
}
961+
962+
/**
963+
* Tests import products with custom options.
964+
*
965+
* @dataProvider getCustomOptionDataProvider
966+
* @param string $importFile
967+
* @param string $sku1
968+
* @param string $sku2
969+
*
970+
* @return void
971+
*/
972+
#[
973+
Config(CatalogConfig::XML_PATH_PRICE_SCOPE, CatalogConfig::PRICE_SCOPE_WEBSITE, ScopeInterface::SCOPE_STORE),
974+
DataFixture(StoreFixture::class, ['code' => 'secondstore']),
975+
]
976+
public function testImportCustomOptions(string $importFile, string $sku1, string $sku2): void
977+
{
978+
$pathToFile = __DIR__ . '/../_files/' . $importFile;
979+
$importModel = $this->createImportModel($pathToFile);
980+
$errors = $importModel->validateData();
981+
982+
$this->assertTrue($errors->getErrorsCount() == 0);
983+
$importModel->importData();
984+
985+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
986+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
987+
\Magento\Catalog\Api\ProductRepositoryInterface::class
988+
);
989+
$product1 = $productRepository->get($sku1);
990+
991+
$this->assertInstanceOf(\Magento\Catalog\Model\Product::class, $product1);
992+
$options = $product1->getOptionInstance()->getProductOptions($product1);
993+
994+
$expectedData = $this->getExpectedOptionsData($pathToFile);
995+
$expectedData = $this->mergeWithExistingData($expectedData, $options);
996+
$actualData = $this->getActualOptionsData($options);
997+
998+
// assert of equal type+titles
999+
$expectedOptions = $expectedData['options'];
1000+
// we need to save key values
1001+
$actualOptions = $actualData['options'];
1002+
sort($expectedOptions);
1003+
sort($actualOptions);
1004+
$this->assertSame($expectedOptions, $actualOptions);
1005+
1006+
// assert of options data
1007+
$this->assertCount(count($expectedData['data']), $actualData['data']);
1008+
$this->assertCount(count($expectedData['values']), $actualData['values']);
1009+
1010+
$this->productRepository->delete($product1);
1011+
$product2 = $productRepository->get($sku2);
1012+
$this->productRepository->delete($product2);
1013+
}
1014+
1015+
/**
1016+
* @return array
1017+
*/
1018+
public function getCustomOptionDataProvider(): array
1019+
{
1020+
return [
1021+
[
1022+
'importFile' => 'multi_store_products_with_custom_options.csv',
1023+
'sku1' => 'simple',
1024+
'sku2' => 'simple2',
1025+
],
1026+
];
1027+
}
9611028
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sku,website_code,store_view_code,attribute_set_code,product_type,name,description,short_description,weight,product_online,visibility,product_websites,categories,price,special_price,special_price_from_date,special_price_to_date,tax_class_name,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,additional_images,additional_image_labels,configurable_variation_labels,configurable_variations,bundle_price_type,bundle_sku_type,bundle_weight_type,bundle_values,downloadble_samples,downloadble_links,associated_skus,related_skus,crosssell_skus,upsell_skus,custom_options,additional_attributes,manage_stock,is_in_stock,qty,out_of_stock_qty,is_qty_decimal,allow_backorders,min_cart_qty,max_cart_qty,notify_on_stock_below,qty_increments,enable_qty_increments,is_decimal_divided,new_from_date,new_to_date,gift_message_available,created_at,updated_at,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_price,msrp_display_actual_price_type,map_enabled
2+
simple,base,,Default,simple,New Product,,,9,1,"Catalog, Search",base,,10,,,,Taxable Goods,new-product,,,,,,,,,,,,,,,,,,,,,,,,"name=Test Field Title,type=field,required=1,sku=1-text,price=100.000000|name=Test Date and Time Title,type=date_time,required=1,sku=2-date,price=200.000000|name=Test Select,type=drop_down,required=1,sku=3-1-select,price=310.000000,option_title=Select Option 1|name=Test Select,type=drop_down,required=1,sku=3-2-select,price=320.000000,option_title=Select Option 2|name=Test Checkbox,type=checkbox,required=1,sku=4-1-select,price=410.000000,option_title=Checkbox Option 1|name=Test Checkbox,type=checkbox,required=1,sku=4-2-select,price=420.000000,option_title=Checkbox Option 2|name=Test Radio,type=radio,required=1,sku=5-1-radio,price=510.000000,option_title=Radio Option 1|name=Test Radio,type=radio,required=1,sku=5-2-radio,price=520.000000,option_title=Radio Option 2",,1,1,999,0,0,0,1,10000,1,1,0,0,,,,,,,,,,,Block after Info Column,,,
3+
simple,,secondstore,Default,simple,New Product 2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
4+
simple2,base,,Default,simple,Simple 2,,,9,1,"Catalog, Search",base,,10,,,,Taxable Goods,,,,,,,,,,,,,,,,,,,,,,,,,"name=Option 1,type=drop_down,required=1,sku=option1value1,price=1.2,option_title=Option 1 Value 1|name=Option 1,type=drop_down,required=1,sku=option1value2,price=1.4,option_title=Option 1 Value 2",,1,1,999,0,0,0,1,10000,1,1,0,0,,,,,,,,,,,Block after Info Column,,,
5+
simple2,,secondstore,Default,simple,Simple 2-2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,999,0,0,0,1,10000,1,1,0,0,,,,,,,,,,,,,,

0 commit comments

Comments
 (0)