Skip to content

Commit 6b3a159

Browse files
author
Mohan Ahuja
committed
ACP2E-841: Advanced Pricing Import status message shows wrong count products number of updates
- Adding integration test
1 parent 8fe5f58 commit 6b3a159

File tree

4 files changed

+239
-23
lines changed

4 files changed

+239
-23
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ protected function saveAndReplaceAdvancedPrices()
397397
$listSku = [];
398398
$tierPrices = [];
399399
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
400-
$bunchTierPrices = [];
401400
foreach ($bunch as $rowNum => $rowData) {
402401
if (!$this->validateRow($rowData, $rowNum)) {
403402
$this->addRowError(ValidatorInterface::ERROR_SKU_IS_EMPTY, $rowNum);
@@ -410,9 +409,8 @@ protected function saveAndReplaceAdvancedPrices()
410409

411410
$rowSku = $rowData[self::COL_SKU];
412411
$listSku[] = $rowSku;
413-
414412
if (!empty($rowData[self::COL_TIER_PRICE_WEBSITE])) {
415-
$tierPrice = [
413+
$tierPrices[$rowSku][] = [
416414
'all_groups' => $rowData[self::COL_TIER_PRICE_CUSTOMER_GROUP] == self::VALUE_ALL_GROUPS,
417415
'customer_group_id' => $this->getCustomerGroupId(
418416
$rowData[self::COL_TIER_PRICE_CUSTOMER_GROUP]
@@ -424,23 +422,19 @@ protected function saveAndReplaceAdvancedPrices()
424422
? $rowData[self::COL_TIER_PRICE] : null,
425423
'website_id' => $this->getWebSiteId($rowData[self::COL_TIER_PRICE_WEBSITE])
426424
];
427-
$bunchTierPrices[$rowSku][] = $tierPrice;
428-
$tierPrices[$rowSku][] = $tierPrice;
429425
}
430426
}
427+
}
431428

432-
if (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {
433-
$this->processCountExistingPrices($bunchTierPrices, self::TABLE_TIER_PRICE)
434-
->processCountNewPrices($bunchTierPrices);
429+
if (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {
430+
$this->processCountExistingPrices($tierPrices, self::TABLE_TIER_PRICE)
431+
->processCountNewPrices($tierPrices);
435432

436-
$this->saveProductPrices($bunchTierPrices, self::TABLE_TIER_PRICE);
437-
if ($listSku) {
438-
$this->setUpdatedAt($listSku);
439-
}
433+
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE);
434+
if ($listSku) {
435+
$this->setUpdatedAt($listSku);
440436
}
441-
}
442-
443-
if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
437+
} elseif (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
444438
if ($listSku) {
445439
$this->processCountNewPrices($tierPrices);
446440
if ($this->deleteProductTierPrices(array_unique($listSku), self::TABLE_TIER_PRICE)) {
@@ -653,12 +647,7 @@ protected function processCountNewPrices(array $tierPrices)
653647
foreach ($tierPrices as $productPrices) {
654648
$this->countItemsCreated += count($productPrices);
655649
}
656-
657-
if ($this->countItemsCreated >= $this->countItemsUpdated) {
658-
$this->countItemsCreated -= $this->countItemsUpdated;
659-
} else {
660-
$this->countItemsCreated = 0;
661-
}
650+
$this->countItemsCreated -= $this->countItemsUpdated;
662651

663652
return $this;
664653
}

dev/tests/integration/testsuite/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricingTest.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ private function doImport(
335335
string $file,
336336
string $directoryCode = DirectoryList::ROOT,
337337
string $behavior = Import::BEHAVIOR_APPEND,
338-
bool $validateOnly = false
338+
bool $validateOnly = false,
339+
string $entity = 'advanced_pricing'
339340
): ProcessingErrorAggregatorInterface {
340341
/** @var Filesystem $filesystem */
341342
$filesystem = $this->objectManager->create(Filesystem::class);
@@ -351,7 +352,7 @@ private function doImport(
351352
->setParameters(
352353
[
353354
'behavior' => $behavior,
354-
'entity' => 'advanced_pricing'
355+
'entity' => $entity
355356
]
356357
)
357358
->validateData();
@@ -426,4 +427,37 @@ private function generateImportFile(array $data): string
426427
$stream->close();
427428
return $varDir->getAbsolutePath($tmpFilename);
428429
}
430+
431+
/**
432+
* @magentoAppArea adminhtml
433+
*/
434+
public function testImportAddUpdateCounts()
435+
{
436+
$this->model = $this->objectManager->create(\Magento\CatalogImportExport\Model\Import\Product::class);
437+
438+
// Import product data from CSV file
439+
$productFilePath = __DIR__ . '/_files/import_catalog_product.csv';
440+
$errors = $this->doImport($productFilePath, DirectoryList::ROOT, Import::BEHAVIOR_ADD_UPDATE, true, 'catalog_product');
441+
$this->assertEquals(0, $errors->getErrorsCount(), 'Product import validation error');
442+
$this->model->importData();
443+
444+
$this->assertEquals(64, $this->model->getCreatedItemsCount(), 'Products create item count');
445+
$this->assertEquals(0, $this->model->getUpdatedItemsCount(), 'Products update item count');
446+
447+
// Import advance pricing data from CSV file
448+
$this->model = $this->objectManager->create(
449+
\Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing::class
450+
);
451+
$pathToFile = __DIR__ . '/_files/import_advanced_pricing_for_additional_attributes_products.csv';
452+
$errors = $this->doImport($pathToFile, DirectoryList::ROOT, Import::BEHAVIOR_ADD_UPDATE, true);
453+
$this->assertEquals(0, $errors->getErrorsCount(), 'Advanced pricing import validation error');
454+
$this->model->importData();
455+
456+
$this->assertEquals(127, $this->model->getCreatedItemsCount(), 'Advance pricing create count1');
457+
$this->assertEquals(0, $this->model->getUpdatedItemsCount(), 'Advance pricing update count1');
458+
459+
$this->doImport($pathToFile, DirectoryList::ROOT, Import::BEHAVIOR_ADD_UPDATE);
460+
$this->assertEquals(0, $this->model->getCreatedItemsCount(), 'Advance pricing create count2');
461+
$this->assertEquals(127, $this->model->getUpdatedItemsCount(), 'Advance pricing update count2');
462+
}
429463
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
sku,tier_price_website,tier_price_customer_group,tier_price_qty,tier_price,tier_price_value_type
2+
test-sample,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
3+
test-sample,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
4+
test-sample,"All Websites [USD]",General,2.0000,10.000000,Fixed
5+
test-sample,"All Websites [USD]",General,3.0000,15.00,Discount
6+
test-sample-1,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
7+
test-sample-1,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
8+
test-sample-1,"All Websites [USD]",General,2.0000,10.000000,Fixed
9+
test-sample-1,"All Websites [USD]",General,3.0000,15.00,Discount
10+
test-sample-Blue-34,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
11+
test-sample-Blue-34,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
12+
test-sample-Blue-34,"All Websites [USD]",General,2.0000,10.000000,Fixed
13+
test-sample-Blue-34,"All Websites [USD]",General,3.0000,15.00,Discount
14+
test-sample-Blue-36,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
15+
test-sample-Blue-36,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
16+
test-sample-Blue-36,"All Websites [USD]",General,2.0000,10.000000,Fixed
17+
test-sample-Blue-36,"All Websites [USD]",General,3.0000,15.00,Discount
18+
test-sample-Blue-38,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
19+
test-sample-Blue-38,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
20+
test-sample-Blue-38,"All Websites [USD]",General,2.0000,10.000000,Fixed
21+
test-sample-Blue-38,"All Websites [USD]",General,3.0000,15.00,Discount
22+
test-sample-Blue-39,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
23+
test-sample-Blue-39,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
24+
test-sample-Blue-39,"All Websites [USD]",General,2.0000,10.000000,Fixed
25+
test-sample-Blue-39,"All Websites [USD]",General,3.0000,15.00,Discount
26+
test-sample-Blue-42,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
27+
test-sample-Blue-42,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
28+
test-sample-Blue-42,"All Websites [USD]",General,2.0000,10.000000,Fixed
29+
test-sample-Blue-42,"All Websites [USD]",General,3.0000,15.00,Discount
30+
test-sample-Blue-44,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
31+
test-sample-Blue-44,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
32+
test-sample-Blue-44,"All Websites [USD]",General,2.0000,10.000000,Fixed
33+
test-sample-Blue-44,"All Websites [USD]",General,3.0000,15.00,Discount
34+
test-sample-Green-34,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
35+
test-sample-Green-34,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
36+
test-sample-Green-34,"All Websites [USD]",General,2.0000,10.000000,Fixed
37+
test-sample-Green-34,"All Websites [USD]",General,3.0000,15.00,Discount
38+
test-sample-Green-36,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
39+
test-sample-Green-36,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
40+
test-sample-Green-36,"All Websites [USD]",General,2.0000,10.000000,Fixed
41+
test-sample-Green-36,"All Websites [USD]",General,3.0000,15.00,Discount
42+
test-sample-Green-38,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
43+
test-sample-Green-38,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
44+
test-sample-Green-38,"All Websites [USD]",General,2.0000,10.000000,Fixed
45+
test-sample-Green-38,"All Websites [USD]",General,3.0000,15.00,Discount
46+
test-sample-Green-39,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
47+
test-sample-Green-39,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
48+
test-sample-Green-39,"All Websites [USD]",General,2.0000,10.000000,Fixed
49+
test-sample-Green-39,"All Websites [USD]",General,3.0000,15.00,Discount
50+
test-sample-Green-42,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
51+
test-sample-Green-42,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
52+
test-sample-Green-42,"All Websites [USD]",General,2.0000,10.000000,Fixed
53+
test-sample-Green-42,"All Websites [USD]",General,3.0000,15.00,Discount
54+
test-sample-Green-44,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
55+
test-sample-Green-44,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
56+
test-sample-Green-44,"All Websites [USD]",General,2.0000,10.000000,Fixed
57+
test-sample-Green-44,"All Websites [USD]",General,3.0000,15.00,Discount
58+
test-sample-Orange-34,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
59+
test-sample-Orange-34,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
60+
test-sample-Orange-34,"All Websites [USD]",General,2.0000,10.000000,Fixed
61+
test-sample-Orange-34,"All Websites [USD]",General,3.0000,15.00,Discount
62+
test-sample-Orange-36,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
63+
test-sample-Orange-36,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
64+
test-sample-Orange-36,"All Websites [USD]",General,2.0000,10.000000,Fixed
65+
test-sample-Orange-36,"All Websites [USD]",General,3.0000,15.00,Discount
66+
test-sample-Orange-38,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
67+
test-sample-Orange-38,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
68+
test-sample-Orange-38,"All Websites [USD]",General,2.0000,10.000000,Fixed
69+
test-sample-Orange-38,"All Websites [USD]",General,3.0000,15.00,Discount
70+
test-sample-Orange-39,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
71+
test-sample-Orange-39,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
72+
test-sample-Orange-39,"All Websites [USD]",General,2.0000,10.000000,Fixed
73+
test-sample-Orange-39,"All Websites [USD]",General,3.0000,15.00,Discount
74+
test-sample-Orange-42,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
75+
test-sample-Orange-42,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
76+
test-sample-Orange-42,"All Websites [USD]",General,2.0000,10.000000,Fixed
77+
test-sample-Orange-42,"All Websites [USD]",General,3.0000,15.00,Discount
78+
test-sample-Orange-44,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
79+
test-sample-Orange-44,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
80+
test-sample-Orange-44,"All Websites [USD]",General,2.0000,10.000000,Fixed
81+
test-sample-Orange-44,"All Websites [USD]",General,3.0000,15.00,Discount
82+
test-sample-Red-34,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
83+
test-sample-Red-34,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
84+
test-sample-Red-34,"All Websites [USD]",General,2.0000,10.000000,Fixed
85+
test-sample-Red-36,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
86+
test-sample-Red-36,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
87+
test-sample-Red-36,"All Websites [USD]",General,2.0000,10.000000,Fixed
88+
test-sample-Red-36,"All Websites [USD]",General,3.0000,15.00,Discount
89+
test-sample-Red-38,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
90+
test-sample-Red-38,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
91+
test-sample-Red-38,"All Websites [USD]",General,2.0000,10.000000,Fixed
92+
test-sample-Red-38,"All Websites [USD]",General,3.0000,15.00,Discount
93+
test-sample-Red-39,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
94+
test-sample-Red-39,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
95+
test-sample-Red-39,"All Websites [USD]",General,2.0000,10.000000,Fixed
96+
test-sample-Red-39,"All Websites [USD]",General,3.0000,15.00,Discount
97+
test-sample-Red-42,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
98+
test-sample-Red-42,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
99+
test-sample-Red-42,"All Websites [USD]",General,2.0000,10.000000,Fixed
100+
test-sample-Red-42,"All Websites [USD]",General,3.0000,15.00,Discount
101+
test-sample-Red-44,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
102+
test-sample-Red-44,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
103+
test-sample-Red-44,"All Websites [USD]",General,2.0000,10.000000,Fixed
104+
test-sample-Red-44,"All Websites [USD]",General,3.0000,15.00,Discount
105+
test-sample-Yellow-34,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
106+
test-sample-Yellow-34,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
107+
test-sample-Yellow-34,"All Websites [USD]",General,2.0000,10.000000,Fixed
108+
test-sample-Yellow-34,"All Websites [USD]",General,3.0000,15.00,Discount
109+
test-sample-Yellow-36,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
110+
test-sample-Yellow-36,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
111+
test-sample-Yellow-36,"All Websites [USD]",General,2.0000,10.000000,Fixed
112+
test-sample-Yellow-36,"All Websites [USD]",General,3.0000,15.00,Discount
113+
test-sample-Yellow-38,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
114+
test-sample-Yellow-38,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
115+
test-sample-Yellow-38,"All Websites [USD]",General,2.0000,10.000000,Fixed
116+
test-sample-Yellow-38,"All Websites [USD]",General,3.0000,15.00,Discount
117+
test-sample-Yellow-39,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
118+
test-sample-Yellow-39,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
119+
test-sample-Yellow-39,"All Websites [USD]",General,2.0000,10.000000,Fixed
120+
test-sample-Yellow-39,"All Websites [USD]",General,3.0000,15.00,Discount
121+
test-sample-Yellow-42,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
122+
test-sample-Yellow-42,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
123+
test-sample-Yellow-42,"All Websites [USD]",General,2.0000,10.000000,Fixed
124+
test-sample-Yellow-42,"All Websites [USD]",General,3.0000,15.00,Discount
125+
test-sample-Yellow-44,"All Websites [USD]","ALL GROUPS",2.0000,10.000000,Fixed
126+
test-sample-Yellow-44,"All Websites [USD]","ALL GROUPS",3.0000,15.00,Discount
127+
test-sample-Yellow-44,"All Websites [USD]",General,2.0000,10.000000,Fixed
128+
test-sample-Yellow-44,"All Websites [USD]",General,3.0000,15.00,Discount

0 commit comments

Comments
 (0)