Skip to content

Commit 47b24df

Browse files
SarmisthaSarmistha
authored andcommitted
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-2902' into Tier4-Kings-PR-06-03-2024
2 parents 7286543 + d716c85 commit 47b24df

File tree

3 files changed

+74
-10
lines changed

3 files changed

+74
-10
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,9 +1912,7 @@ protected function _saveTitles(array $titles)
19121912
if (!isset($existingOptionIds[$optionId]) && count($storeInfo) > 0) {
19131913
$storeInfo = [Store::DEFAULT_STORE_ID => reset($storeInfo)] + $storeInfo;
19141914
}
1915-
//for use default
1916-
$uniqStoreInfo = array_unique($storeInfo);
1917-
foreach ($uniqStoreInfo as $storeId => $title) {
1915+
foreach ($storeInfo as $storeId => $title) {
19181916
$titleRows[] = ['option_id' => $optionId, 'store_id' => $storeId, 'title' => $title];
19191917
}
19201918
}

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

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
use Magento\Catalog\Helper\Data as CatalogConfig;
1414
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
1515
use Magento\CatalogImportExport\Model\Import\ProductTestBase;
16+
use Magento\Framework\Exception\LocalizedException;
17+
use Magento\Framework\Exception\NoSuchEntityException;
18+
use Magento\Framework\Exception\StateException;
1619
use Magento\ImportExport\Helper\Data as ImportExportConfig;
1720
use Magento\Store\Model\ScopeInterface;
1821
use Magento\Store\Model\StoreManagerInterface;
1922
use Magento\Store\Test\Fixture\Store as StoreFixture;
2023
use Magento\TestFramework\Fixture\AppIsolation;
2124
use Magento\TestFramework\Fixture\Config;
2225
use Magento\TestFramework\Fixture\DataFixture;
26+
use Magento\TestFramework\Helper\Bootstrap;
2327

2428
/**
2529
* Integration test for \Magento\CatalogImportExport\Model\Import\Product class.
@@ -90,7 +94,7 @@ public function testSaveCustomOptions(string $importFile, string $sku, int $expe
9094
$importModel->importData();
9195

9296
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
93-
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
97+
$productRepository = Bootstrap::getObjectManager()->create(
9498
\Magento\Catalog\Api\ProductRepositoryInterface::class
9599
);
96100
$product = $productRepository->get($sku);
@@ -187,17 +191,17 @@ public function testSaveCustomOptionsWithMultipleStoreViews(
187191
array $expected
188192
) {
189193
$expected = $this->getFullExpectedOptions($expected);
190-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
194+
$objectManager = Bootstrap::getObjectManager();
191195
/** @var StoreManagerInterface $storeManager */
192196
$storeManager = $objectManager->get(StoreManagerInterface::class);
193197
$pathToFile = __DIR__ . '/../_files/' . $importFile;
194198
$importModel = $this->createImportModel($pathToFile);
195199
$errors = $importModel->validateData();
196200
$this->assertTrue($errors->getErrorsCount() == 0, 'Import File Validation Failed');
197201
$importModel->importData();
198-
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
202+
/** @var ProductRepositoryInterface $productRepository */
199203
$productRepository = $objectManager->get(
200-
\Magento\Catalog\Api\ProductRepositoryInterface::class
204+
ProductRepositoryInterface::class
201205
);
202206
$actual = [];
203207
foreach ($expected as $sku => $storesData) {
@@ -982,9 +986,9 @@ public function testImportCustomOptions(string $importFile, string $sku1, string
982986
$this->assertTrue($errors->getErrorsCount() == 0);
983987
$importModel->importData();
984988

985-
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
986-
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
987-
\Magento\Catalog\Api\ProductRepositoryInterface::class
989+
/** @var ProductRepositoryInterface $productRepository */
990+
$productRepository = Bootstrap::getObjectManager()->create(
991+
ProductRepositoryInterface::class
988992
);
989993
$product1 = $productRepository->get($sku1);
990994

@@ -1025,4 +1029,64 @@ public function getCustomOptionDataProvider(): array
10251029
],
10261030
];
10271031
}
1032+
1033+
/**
1034+
* Tests import product custom options with multiple uploads.
1035+
*
1036+
* @dataProvider getProductCustomOptionDataProvider
1037+
* @param string $importFile
1038+
* @param string $sku
1039+
* @param int $uploadCount
1040+
* @throws LocalizedException
1041+
* @throws NoSuchEntityException
1042+
* @throws StateException
1043+
*/
1044+
public function testImportProductCustomOptionsOnMultipleUploads(
1045+
string $importFile,
1046+
string $sku,
1047+
int $uploadCount
1048+
): void {
1049+
$pathToFile = __DIR__ . '/../_files/' . $importFile;
1050+
1051+
for ($count = 0; $count < $uploadCount; $count++) {
1052+
$productImportModel = $this->createImportModel($pathToFile);
1053+
$errors = $productImportModel->validateData();
1054+
$this->assertTrue($errors->getErrorsCount() == 0);
1055+
$productImportModel->importData();
1056+
}
1057+
1058+
/** @var ProductRepositoryInterface $productRepository */
1059+
$productRepository = Bootstrap::getObjectManager()->create(
1060+
ProductRepositoryInterface::class
1061+
);
1062+
$product = $productRepository->get($sku);
1063+
1064+
$this->assertInstanceOf(\Magento\Catalog\Model\Product::class, $product);
1065+
$options = $product->getOptionInstance()->getProductOptions($product);
1066+
1067+
$expectedData = $this->getExpectedOptionsData($pathToFile, 'default');
1068+
$expectedOptions = $expectedData['options'];
1069+
1070+
$this->assertCount(count($expectedOptions), $options);
1071+
1072+
// Cleanup imported products
1073+
try {
1074+
$this->productRepository->delete($product);
1075+
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
1076+
}
1077+
}
1078+
1079+
/**
1080+
* @return array
1081+
*/
1082+
public function getProductCustomOptionDataProvider(): array
1083+
{
1084+
return [
1085+
[
1086+
'importFile' => 'product_with_custom_options_and_multiple_uploads.csv',
1087+
'sku' => 'p1',
1088+
'uploadCount' => 2,
1089+
],
1090+
];
1091+
}
10281092
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,store_view_code,attribute_set_code,product_type,custom_options
2+
p1,default,Default,simple,"name=Option One,type=multiple,required=0,price=2.000000,sku=1,max_characters=0,file_extension=,image_size_x=0,image_size_y=0,price_type=fixed,option_title=One|name=Option One,type=multiple,required=0,price=2.000000,sku=2,max_characters=0,file_extension=,image_size_x=0,image_size_y=0,price_type=fixed,option_title=Two|name=Option Two,type=multiple,required=0,price=3.000000,sku=3,max_characters=0,file_extension=,image_size_x=0,image_size_y=0,price_type=fixed,option_title=Three|name=Option Two,type=multiple,required=0,price=4.000000,sku=4,max_characters=0,file_extension=,image_size_x=0,image_size_y=0,price_type=fixed,option_title=Four"

0 commit comments

Comments
 (0)