Skip to content

Commit 04b6d5e

Browse files
author
Anna Bukatar
committed
ACP2E-984: Product export uses category names from the Dafault Store View scope
1 parent 2605796 commit 04b6d5e

File tree

2 files changed

+53
-0
lines changed
  • app/code/Magento/CatalogImportExport/Model/Export
  • dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export

2 files changed

+53
-0
lines changed

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ protected function initCategories()
470470
{
471471
$collection = $this->_categoryColFactory->create()->addNameToResult();
472472
/* @var $collection \Magento\Catalog\Model\ResourceModel\Category\Collection */
473+
$collection->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
473474
foreach ($collection as $category) {
474475
$structure = preg_split('#/+#', $category->getPath());
475476
$pathSize = count($structure);

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export/ProductTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@
99
namespace Magento\CatalogImportExport\Model\Export;
1010

1111
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Catalog\Api\CategoryRepositoryInterface;
1213
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection as ProductAttributeCollection;
1314
use Magento\Catalog\Observer\SwitchPriceAttributeScopeOnConfigChange;
15+
use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
16+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
1417
use Magento\CatalogImportExport\Model\Export\Product\Type\Simple as SimpleProductType;
1518
use Magento\CatalogInventory\Api\StockConfigurationInterface;
1619
use Magento\CatalogInventory\Api\StockItemRepositoryInterface;
1720
use Magento\CatalogInventory\Model\Stock\Item;
1821
use Magento\Framework\App\Config\ReinitableConfigInterface;
22+
use Magento\Store\Model\StoreManagerInterface;
23+
use Magento\Store\Test\Fixture\Store as StoreFixture;
24+
use Magento\TestFramework\Fixture\DataFixture;
25+
use Magento\TestFramework\Fixture\DataFixtureStorage;
26+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
27+
use Magento\TestFramework\Fixture\DbIsolation;
1928

2029
/**
2130
* @magentoDataFixtureBeforeTransaction Magento/Catalog/_files/enable_reindex_schedule.php
@@ -46,6 +55,21 @@ class ProductTest extends \PHPUnit\Framework\TestCase
4655
*/
4756
private $productRepository;
4857

58+
/**
59+
* @var CategoryRepositoryInterface
60+
*/
61+
private $categoryRepository;
62+
63+
/**
64+
* @var StoreManagerInterface
65+
*/
66+
private $storeManager;
67+
68+
/**
69+
* @var DataFixtureStorage
70+
*/
71+
private $fixtures;
72+
4973
/**
5074
* @var array
5175
*/
@@ -82,6 +106,9 @@ protected function setUp(): void
82106
\Magento\CatalogImportExport\Model\Export\Product::class
83107
);
84108
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
109+
$this->categoryRepository = $this->objectManager->create(CategoryRepositoryInterface::class);
110+
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
111+
$this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage();
85112
}
86113

87114
/**
@@ -789,4 +816,29 @@ private function doExport(array $filters = []): string
789816
);
790817
return $this->model->export();
791818
}
819+
820+
#[
821+
DbIsolation(true),
822+
DataFixture(StoreFixture::class, as: 'store2'),
823+
DataFixture(CategoryFixture::class, as: 'c1'),
824+
DataFixture(ProductFixture::class, ['category_ids' => ['$c1.id$']], 'p1'),
825+
]
826+
public function testExportCategoryPathHasAdminScopeNames(): void
827+
{
828+
$secondStoreId = $this->fixtures->get('store2')->getId();
829+
$categoryId = $this->fixtures->get('c1')->getId();
830+
$oldStoreId = $this->storeManager->getStore()->getId();
831+
$this->storeManager->setCurrentStore($secondStoreId);
832+
$category = $this->categoryRepository->get($categoryId, $secondStoreId);
833+
$category->setName('NewCategoryName');
834+
$this->categoryRepository->save($category);
835+
$this->storeManager->setCurrentStore($oldStoreId);
836+
$this->model->setWriter(
837+
$this->objectManager->create(
838+
\Magento\ImportExport\Model\Export\Adapter\Csv::class
839+
)
840+
);
841+
$exportData = $this->model->export();
842+
$this->assertStringNotContainsString('NewCategoryName', $exportData);
843+
}
792844
}

0 commit comments

Comments
 (0)