Skip to content

Commit 2973d33

Browse files
committed
ACP2E-2902: Add/Update Import on Products Duplicating Customizable Options
1 parent 78f4036 commit 2973d33

File tree

2 files changed

+75
-7
lines changed

2 files changed

+75
-7
lines changed

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

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
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;
20+
use Magento\ImportExport\Model\Import;
1721
use Magento\Store\Model\ScopeInterface;
1822
use Magento\Store\Model\StoreManagerInterface;
1923
use Magento\Store\Test\Fixture\Store as StoreFixture;
2024
use Magento\TestFramework\Fixture\AppIsolation;
2125
use Magento\TestFramework\Fixture\Config;
2226
use Magento\TestFramework\Fixture\DataFixture;
27+
use Magento\TestFramework\Helper\Bootstrap;
2328

2429
/**
2530
* Integration test for \Magento\CatalogImportExport\Model\Import\Product class.
@@ -90,7 +95,7 @@ public function testSaveCustomOptions(string $importFile, string $sku, int $expe
9095
$importModel->importData();
9196

9297
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
93-
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
98+
$productRepository = Bootstrap::getObjectManager()->create(
9499
\Magento\Catalog\Api\ProductRepositoryInterface::class
95100
);
96101
$product = $productRepository->get($sku);
@@ -187,17 +192,17 @@ public function testSaveCustomOptionsWithMultipleStoreViews(
187192
array $expected
188193
) {
189194
$expected = $this->getFullExpectedOptions($expected);
190-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
195+
$objectManager = Bootstrap::getObjectManager();
191196
/** @var StoreManagerInterface $storeManager */
192197
$storeManager = $objectManager->get(StoreManagerInterface::class);
193198
$pathToFile = __DIR__ . '/../_files/' . $importFile;
194199
$importModel = $this->createImportModel($pathToFile);
195200
$errors = $importModel->validateData();
196201
$this->assertTrue($errors->getErrorsCount() == 0, 'Import File Validation Failed');
197202
$importModel->importData();
198-
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
203+
/** @var ProductRepositoryInterface $productRepository */
199204
$productRepository = $objectManager->get(
200-
\Magento\Catalog\Api\ProductRepositoryInterface::class
205+
ProductRepositoryInterface::class
201206
);
202207
$actual = [];
203208
foreach ($expected as $sku => $storesData) {
@@ -982,9 +987,9 @@ public function testImportCustomOptions(string $importFile, string $sku1, string
982987
$this->assertTrue($errors->getErrorsCount() == 0);
983988
$importModel->importData();
984989

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

@@ -1025,4 +1030,65 @@ public function getCustomOptionDataProvider(): array
10251030
],
10261031
];
10271032
}
1033+
1034+
/**
1035+
* Tests import product custom options with multiple uploads.
1036+
*
1037+
* @dataProvider getProductCustomOptionDataProvider
1038+
* @param string $importFile
1039+
* @param string $sku
1040+
* @param int $uploadCount
1041+
* @throws LocalizedException
1042+
* @throws NoSuchEntityException
1043+
* @throws StateException
1044+
*/
1045+
#[
1046+
Config(CatalogConfig::XML_PATH_PRICE_SCOPE, CatalogConfig::PRICE_SCOPE_WEBSITE, ScopeInterface::SCOPE_STORE),
1047+
DataFixture(StoreFixture::class, ['code' => 'secondstore']),
1048+
]
1049+
public function testImportProductCustomOptionsOnMultipleUploads(string $importFile, string $sku, int $uploadCount): void
1050+
{
1051+
$pathToFile = __DIR__ . '/../_files/' . $importFile;
1052+
1053+
for($count = 0; $count < $uploadCount; $count++) {
1054+
$productImportModel = $this->createImportModel($pathToFile);
1055+
$errors = $productImportModel->validateData();
1056+
$this->assertTrue($errors->getErrorsCount() == 0);
1057+
$productImportModel->importData();
1058+
}
1059+
1060+
/** @var ProductRepositoryInterface $productRepository */
1061+
$productRepository = Bootstrap::getObjectManager()->create(
1062+
ProductRepositoryInterface::class
1063+
);
1064+
$product = $productRepository->get($sku);
1065+
1066+
$this->assertInstanceOf(\Magento\Catalog\Model\Product::class, $product);
1067+
$options = $product->getOptionInstance()->getProductOptions($product);
1068+
1069+
$expectedData = $this->getExpectedOptionsData($pathToFile, 'secondstore');
1070+
$expectedOptions = $expectedData['options'];
1071+
1072+
$this->assertCount(count($expectedOptions), $options);
1073+
1074+
// Cleanup imported products
1075+
try {
1076+
$this->productRepository->delete($product);
1077+
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
1078+
}
1079+
}
1080+
1081+
/**
1082+
* @return array
1083+
*/
1084+
public function getProductCustomOptionDataProvider(): array
1085+
{
1086+
return [
1087+
[
1088+
'importFile' => 'product_with_custom_options_and_multiple_uploads.csv',
1089+
'sku' => 'simple',
1090+
'uploadCount' => 2,
1091+
],
1092+
];
1093+
}
10281094
}
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+
simple,secondstore,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)