|
6 | 6 | namespace Magento\AdvancedPricingImportExport\Model\Export;
|
7 | 7 |
|
8 | 8 | use Magento\Framework\App\Filesystem\DirectoryList;
|
| 9 | +use Magento\Framework\File\Csv; |
9 | 10 | use Magento\TestFramework\Indexer\TestCase;
|
10 | 11 | use Magento\TestFramework\Helper\Bootstrap;
|
11 | 12 | use Magento\Framework\Filesystem;
|
|
19 | 20 |
|
20 | 21 | /**
|
21 | 22 | * Advanced pricing test
|
| 23 | + * |
| 24 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
22 | 25 | */
|
23 | 26 | class AdvancedPricingTest extends TestCase
|
24 | 27 | {
|
@@ -161,6 +164,110 @@ public function testExportMultipleWebsites()
|
161 | 164 | }
|
162 | 165 | }
|
163 | 166 |
|
| 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 | + |
164 | 271 | /**
|
165 | 272 | * @param string $csvFile
|
166 | 273 | * @return string
|
|
0 commit comments