Skip to content

Commit 2a5dd78

Browse files
committed
Merge remote-tracking branch 'origin/MC-20419' into 2.3-develop-pr89
2 parents 10f401e + 1f10d38 commit 2a5dd78

File tree

3 files changed

+199
-0
lines changed

3 files changed

+199
-0
lines changed

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

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\AdvancedPricingImportExport\Model\Export;
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\File\Csv;
910
use Magento\TestFramework\Indexer\TestCase;
1011
use Magento\TestFramework\Helper\Bootstrap;
1112
use Magento\Framework\Filesystem;
@@ -19,6 +20,8 @@
1920

2021
/**
2122
* Advanced pricing test
23+
*
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2225
*/
2326
class AdvancedPricingTest extends TestCase
2427
{
@@ -161,6 +164,110 @@ public function testExportMultipleWebsites()
161164
}
162165
}
163166

167+
/**
168+
* Export and Import of Advanced Pricing with different Price Types.
169+
*
170+
* @magentoDataFixture Magento/Catalog/_files/two_simple_products_with_tier_price.php
171+
* @return void
172+
*/
173+
public function testExportImportOfAdvancedPricing(): void
174+
{
175+
$csvfile = uniqid('importexport_') . '.csv';
176+
$exportContent = $this->exportData($csvfile);
177+
$this->assertContains(
178+
'second_simple,"All Websites [USD]","ALL GROUPS",10.0000,3.00,Discount',
179+
$exportContent
180+
);
181+
$this->assertContains(
182+
'simple,"All Websites [USD]",General,5.0000,95.000000,Fixed',
183+
$exportContent
184+
);
185+
$this->updateTierPriceDataInCsv($csvfile);
186+
$this->importData($csvfile);
187+
188+
/** @var ProductRepositoryInterface $productRepository */
189+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
190+
$firstProductTierPrices = $productRepository->get('simple')->getTierPrices();
191+
$secondProductTierPrices = $productRepository->get('second_simple')->getTierPrices();
192+
193+
$this->assertSame(
194+
['0', '1'],
195+
[
196+
$firstProductTierPrices[0]->getExtensionAttributes()->getWebsiteId(),
197+
$firstProductTierPrices[0]->getCustomerGroupId(),
198+
]
199+
);
200+
201+
$this->assertEquals(
202+
['5.0000', '90.000000'],
203+
[
204+
$firstProductTierPrices[0]->getQty(),
205+
$firstProductTierPrices[0]->getValue(),
206+
],
207+
'',
208+
0.1
209+
);
210+
211+
$this->assertSame(
212+
['0', \Magento\Customer\Model\Group::CUST_GROUP_ALL],
213+
[
214+
$secondProductTierPrices[0]->getExtensionAttributes()->getWebsiteId(),
215+
$secondProductTierPrices[0]->getCustomerGroupId(),
216+
]
217+
);
218+
219+
$this->assertEquals(
220+
['5.00', '10.0000'],
221+
[
222+
$secondProductTierPrices[0]->getExtensionAttributes()->getPercentageValue(),
223+
$secondProductTierPrices[0]->getQty(),
224+
],
225+
'',
226+
0.1
227+
);
228+
}
229+
230+
/**
231+
* Update tier price data in CSV.
232+
*
233+
* @param string $csvfile
234+
* @return void
235+
*/
236+
private function updateTierPriceDataInCsv(string $csvfile): void
237+
{
238+
$csvNewData = [
239+
0 => [
240+
0 => 'sku',
241+
1 => 'tier_price_website',
242+
2 => 'tier_price_customer_group',
243+
3 => 'tier_price_qty',
244+
4 => 'tier_price',
245+
5 => 'tier_price_value_type',
246+
],
247+
1 => [
248+
0 => 'simple',
249+
1 => 'All Websites [USD]',
250+
2 => 'General',
251+
3 => '5',
252+
4 => '90',
253+
5 => 'Fixed',
254+
],
255+
2 => [
256+
0 => 'second_simple',
257+
1 => 'All Websites [USD]',
258+
2 => 'ALL GROUPS',
259+
3 => '10',
260+
4 => '5',
261+
5 => 'Discount',
262+
],
263+
];
264+
265+
/** @var Csv $csv */
266+
$csv = $this->objectManager->get(Csv::class);
267+
$varDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR);
268+
$csv->appendData($varDirectory->getAbsolutePath($csvfile), $csvNewData);
269+
}
270+
164271
/**
165272
* @param string $csvFile
166273
* @return string
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
/** @var \Magento\TestFramework\ObjectManager $objectManager */
9+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
10+
11+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
12+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
13+
14+
/** @var $product \Magento\Catalog\Model\Product */
15+
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
16+
$product->isObjectNew(true);
17+
18+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
19+
->setAttributeSetId($product->getDefaultAttributeSetId())
20+
->setWebsiteIds([1])
21+
->setName('Simple Product')
22+
->setSku('simple')
23+
->setPrice(100)
24+
->setWeight(1)
25+
->setTierPrice([0 => ['website_id' => 0, 'cust_group' => 1, 'price_qty' => 5, 'price' => 95]])
26+
->setMetaTitle('meta title')
27+
->setMetaKeyword('meta keyword')
28+
->setMetaDescription('meta description')
29+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
30+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
31+
->setCanSaveCustomOptions(true)
32+
->setStockData(
33+
[
34+
'qty' => 10,
35+
'is_in_stock' => 1,
36+
'manage_stock' => 1,
37+
]
38+
);
39+
$productRepository->save($product);
40+
$product->unsetData()->setOrigData();
41+
42+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
43+
->setAttributeSetId($product->getDefaultAttributeSetId())
44+
->setWebsiteIds([1])
45+
->setName('Second Simple Product')
46+
->setSku('second_simple')
47+
->setPrice(200)
48+
->setWeight(1)
49+
->setTierPrice(
50+
[
51+
0 => [
52+
'website_id' => 0,
53+
'cust_group' => \Magento\Customer\Model\Group::CUST_GROUP_ALL,
54+
'price_qty' => 10,
55+
'price' => 3,
56+
'percentage_value' => 3,
57+
],
58+
]
59+
)
60+
->setMetaTitle('meta title')
61+
->setMetaKeyword('meta keyword')
62+
->setMetaDescription('meta description')
63+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
64+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
65+
->setCanSaveCustomOptions(true)
66+
->setStockData(
67+
[
68+
'qty' => 10,
69+
'is_in_stock' => 1,
70+
'manage_stock' => 1,
71+
]
72+
);
73+
74+
$productRepository->save($product);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
9+
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
10+
11+
foreach (['simple', 'second_simple'] as $sku) {
12+
try {
13+
$product = $productRepository->get($sku, false, null, true);
14+
$productRepository->delete($product);
15+
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
16+
//Product already removed
17+
}
18+
}

0 commit comments

Comments
 (0)