Skip to content

Commit

Permalink
Merge pull request #170 from magento-nord/MAGETWO-51988
Browse files Browse the repository at this point in the history
[NORD] MAGETWO-51988 (bugfix)
  • Loading branch information
balex13 authored Jul 25, 2016
2 parents 84e6776 + ba0d0c5 commit 6474bc8
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ protected function _getWebsiteCode($websiteId)
{
$storeName = ($websiteId == 0)
? ImportAdvancedPricing::VALUE_ALL_WEBSITES
: $this->_storeManager->getWebsite($websiteId)->getName();
: $this->_storeManager->getWebsite($websiteId)->getCode();
$currencyCode = '';
if ($websiteId == 0) {
$currencyCode = $this->_storeManager->getWebsite($websiteId)->getBaseCurrencyCode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,85 @@ public function testExport()

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

$this->exportData($csvfile);
$this->importData($csvfile);

while ($index > 0) {
$index--;
$newPricingData = $this->objectManager->create(\Magento\Catalog\Model\Product::class)
->load($ids[$index])
->getTierPrices();
$this->assertEquals(count($origPricingData[$index]), count($newPricingData));
$this->assertEqualsOtherThanSkippedAttributes($origPricingData[$index], $newPricingData, []);
}
}

/**
* @magentoAppArea adminhtml
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
* @magentoConfigFixture current_store catalog/price/scope 1
* @magentoDataFixture Magento/AdvancedPricingImportExport/_files/product_with_second_website.php
*/
public function testExportMultipleWebsites()
{
$productRepository = $this->objectManager->create(
\Magento\Catalog\Api\ProductRepositoryInterface::class
);
$index = 0;
$ids = [];
$origPricingData = [];
$skus = ['AdvancedPricingSimple 1', 'AdvancedPricingSimple 2'];
while (isset($skus[$index])) {
$ids[$index] = $productRepository->get($skus[$index])->getId();
$origPricingData[$index] = $this->objectManager->create(\Magento\Catalog\Model\Product::class)
->load($ids[$index])
->getTierPrices();
$index++;
}

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

$exportContent = $this->exportData($csvfile);
$this->assertContains(
'"AdvancedPricingSimple 2",test,"ALL GROUPS",3.0000,5.0000',
$exportContent
);
$this->importData($csvfile);

while ($index > 0) {
$index--;
$newPricingData = $this->objectManager->create(\Magento\Catalog\Model\Product::class)
->load($ids[$index])
->getTierPrices();
$this->assertEquals(count($origPricingData[$index]), count($newPricingData));
$this->assertEqualsOtherThanSkippedAttributes($origPricingData[$index], $newPricingData, []);
}
}

/**
* @param string $csvFile
* @return string
*/
private function exportData($csvFile)
{
$this->model->setWriter(
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\ImportExport\Model\Export\Adapter\Csv::class,
['fileSystem' => $this->fileSystem, 'destination' => $csvfile]
['fileSystem' => $this->fileSystem, 'destination' => $csvFile]
)
);
$this->assertNotEmpty($this->model->export());
$exportContent = $this->model->export();
$this->assertNotEmpty($exportContent);

return $exportContent;
}

/**
* @param string $csvFile
*/
private function importData($csvFile)
{
/** @var \Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing $importModel */
$importModel = $this->objectManager->create(
\Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing::class
Expand All @@ -75,7 +146,7 @@ public function testExport()
$source = $this->objectManager->create(
\Magento\ImportExport\Model\Import\Source\Csv::class,
[
'file' => $csvfile,
'file' => $csvFile,
'directory' => $directory
]
);
Expand All @@ -90,18 +161,9 @@ public function testExport()

$this->assertTrue(
$errors->getErrorsCount() == 0,
'Advanced Pricing import error, imported from file:' . $csvfile
'Advanced Pricing import error, imported from file:' . $csvFile
);
$importModel->importData();

while ($index > 0) {
$index--;
$newPricingData = $this->objectManager->create(\Magento\Catalog\Model\Product::class)
->load($ids[$index])
->getTierPrices();
$this->assertEquals(count($origPricingData[$index]), count($newPricingData));
$this->assertEqualsOtherThanSkippedAttributes($origPricingData[$index], $newPricingData, []);
}
}

private function assertEqualsOtherThanSkippedAttributes($expected, $actual, $skippedAttributes)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
require dirname(dirname(__DIR__)) . '/Store/_files/website.php';
require 'create_products.php';

/** @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository */
$attributeRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(Magento\Catalog\Api\ProductAttributeRepositoryInterface::class);
$groupPriceAttribute = $attributeRepository->get('tier_price')
->setScope(Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE);
$attributeRepository->save($groupPriceAttribute);

$productModel->setWebsiteIds(array_merge($productModel->getWebsiteIds(), [(int)$website->getId()]));
$productModel->setTierPrice(
[
[
'website_id' => $website->getId(),
'cust_group' => \Magento\Customer\Model\Group::CUST_GROUP_ALL,
'price_qty' => 3,
'price' => 5
]
]
);
$productModel->save();

0 comments on commit 6474bc8

Please sign in to comment.