Skip to content

Commit 356c92b

Browse files
author
Yaroslav Onischenko
committed
MAGETWO-51988: Exported advanced price file is incorrect if Multiple Website
1 parent 5e16608 commit 356c92b

File tree

3 files changed

+104
-14
lines changed

3 files changed

+104
-14
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ protected function _getWebsiteCode($websiteId)
395395
{
396396
$storeName = ($websiteId == 0)
397397
? ImportAdvancedPricing::VALUE_ALL_WEBSITES
398-
: $this->_storeManager->getWebsite($websiteId)->getName();
398+
: $this->_storeManager->getWebsite($websiteId)->getCode();
399+
$currencyCode = '';
399400
if ($websiteId == 0) {
400401
$currencyCode = $this->_storeManager->getWebsite($websiteId)->getBaseCurrencyCode();
401402
}

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

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,85 @@ public function testExport()
5959

6060
$csvfile = uniqid('importexport_') . '.csv';
6161

62+
$this->exportData($csvfile);
63+
$this->importData($csvfile);
64+
65+
while ($index > 0) {
66+
$index--;
67+
$newPricingData = $this->objectManager->create(\Magento\Catalog\Model\Product::class)
68+
->load($ids[$index])
69+
->getTierPrices();
70+
$this->assertEquals(count($origPricingData[$index]), count($newPricingData));
71+
$this->assertEqualsOtherThanSkippedAttributes($origPricingData[$index], $newPricingData, []);
72+
}
73+
}
74+
75+
/**
76+
* @magentoAppArea adminhtml
77+
* @magentoDbIsolation enabled
78+
* @magentoAppIsolation enabled
79+
* @magentoConfigFixture current_store catalog/price/scope 1
80+
* @magentoDataFixture Magento/AdvancedPricingImportExport/_files/product_with_second_website.php
81+
*/
82+
public function testExportMultipleWebsites()
83+
{
84+
$productRepository = $this->objectManager->create(
85+
\Magento\Catalog\Api\ProductRepositoryInterface::class
86+
);
87+
$index = 0;
88+
$ids = [];
89+
$origPricingData = [];
90+
$skus = ['AdvancedPricingSimple 1', 'AdvancedPricingSimple 2'];
91+
while (isset($skus[$index])) {
92+
$ids[$index] = $productRepository->get($skus[$index])->getId();
93+
$origPricingData[$index] = $this->objectManager->create(\Magento\Catalog\Model\Product::class)
94+
->load($ids[$index])
95+
->getTierPrices();
96+
$index++;
97+
}
98+
99+
$csvfile = uniqid('importexport_') . '.csv';
100+
101+
$exportContent = $this->exportData($csvfile);
102+
$this->assertContains(
103+
'"AdvancedPricingSimple 2",test,"ALL GROUPS",3.0000,5.0000',
104+
$exportContent
105+
);
106+
$this->importData($csvfile);
107+
108+
while ($index > 0) {
109+
$index--;
110+
$newPricingData = $this->objectManager->create(\Magento\Catalog\Model\Product::class)
111+
->load($ids[$index])
112+
->getTierPrices();
113+
$this->assertEquals(count($origPricingData[$index]), count($newPricingData));
114+
$this->assertEqualsOtherThanSkippedAttributes($origPricingData[$index], $newPricingData, []);
115+
}
116+
}
117+
118+
/**
119+
* @param string $csvFile
120+
* @return string
121+
*/
122+
private function exportData($csvFile)
123+
{
62124
$this->model->setWriter(
63125
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
64126
\Magento\ImportExport\Model\Export\Adapter\Csv::class,
65-
['fileSystem' => $this->fileSystem, 'destination' => $csvfile]
127+
['fileSystem' => $this->fileSystem, 'destination' => $csvFile]
66128
)
67129
);
68-
$this->assertNotEmpty($this->model->export());
130+
$exportContent = $this->model->export();
131+
$this->assertNotEmpty($exportContent);
132+
133+
return $exportContent;
134+
}
69135

136+
/**
137+
* @param string $csvFile
138+
*/
139+
private function importData($csvFile)
140+
{
70141
/** @var \Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing $importModel */
71142
$importModel = $this->objectManager->create(
72143
\Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing::class
@@ -75,7 +146,7 @@ public function testExport()
75146
$source = $this->objectManager->create(
76147
\Magento\ImportExport\Model\Import\Source\Csv::class,
77148
[
78-
'file' => $csvfile,
149+
'file' => $csvFile,
79150
'directory' => $directory
80151
]
81152
);
@@ -90,18 +161,9 @@ public function testExport()
90161

91162
$this->assertTrue(
92163
$errors->getErrorsCount() == 0,
93-
'Advanced Pricing import error, imported from file:' . $csvfile
164+
'Advanced Pricing import error, imported from file:' . $csvFile
94165
);
95166
$importModel->importData();
96-
97-
while ($index > 0) {
98-
$index--;
99-
$newPricingData = $this->objectManager->create(\Magento\Catalog\Model\Product::class)
100-
->load($ids[$index])
101-
->getTierPrices();
102-
$this->assertEquals(count($origPricingData[$index]), count($newPricingData));
103-
$this->assertEqualsOtherThanSkippedAttributes($origPricingData[$index], $newPricingData, []);
104-
}
105167
}
106168

107169
private function assertEqualsOtherThanSkippedAttributes($expected, $actual, $skippedAttributes)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
require dirname(dirname(__DIR__)) . '/Store/_files/website.php';
7+
require 'create_products.php';
8+
9+
/** @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository */
10+
$attributeRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
11+
->get(Magento\Catalog\Api\ProductAttributeRepositoryInterface::class);
12+
$groupPriceAttribute = $attributeRepository->get('tier_price')
13+
->setScope(Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE);
14+
$attributeRepository->save($groupPriceAttribute);
15+
16+
$productModel->setWebsiteIds(array_merge($productModel->getWebsiteIds(), [(int)$website->getId()]));
17+
$productModel->setTierPrice(
18+
[
19+
[
20+
'website_id' => $website->getId(),
21+
'cust_group' => \Magento\Customer\Model\Group::CUST_GROUP_ALL,
22+
'price_qty' => 3,
23+
'price' => 5
24+
]
25+
]
26+
);
27+
$productModel->save();

0 commit comments

Comments
 (0)