Skip to content

Commit 5ebcd73

Browse files
committed
ACP2E-3735: Incorrect filtered Data in Product Export for Multi-Store Setup
1 parent 239d499 commit 5ebcd73

File tree

2 files changed

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

2 files changed

+43
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,10 +1096,11 @@ protected function getExportData()
10961096
protected function loadCollection(): array
10971097
{
10981098
$data = [];
1099-
$collection = $this->_getEntityCollection();
11001099
foreach (array_keys($this->_storeIdToCode) as $storeId) {
1100+
$collection = $this->_getEntityCollection(true);
11011101
$collection->setOrder('entity_id', 'asc');
11021102
$collection->setStoreId($storeId);
1103+
$this->_prepareEntityCollection($collection);
11031104
$collection->load();
11041105
foreach ($collection as $itemId => $item) {
11051106
$data[$itemId][$storeId] = $item;
@@ -1129,6 +1130,9 @@ protected function collectRawData()
11291130
*/
11301131
foreach ($items as $itemId => $itemByStore) {
11311132
foreach ($this->_storeIdToCode as $storeId => $storeCode) {
1133+
if (!key_exists($storeId, $itemByStore)) {
1134+
continue;
1135+
}
11321136
$item = $itemByStore[$storeId];
11331137
$additionalAttributes = [];
11341138
$productLinkId = $item->getData($this->getProductEntityLinkField());

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Magento\Catalog\Api\CategoryRepositoryInterface;
1212
use Magento\Catalog\Api\ProductRepositoryInterface;
13+
use Magento\Catalog\Model\Product\Visibility;
1314
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection as ProductAttributeCollection;
1415
use Magento\Catalog\Observer\SwitchPriceAttributeScopeOnConfigChange;
1516
use Magento\Catalog\Test\Fixture\Attribute as AttributeFixture;
@@ -747,6 +748,43 @@ public function testExportProductWithTwoWebsites(): void
747748
$switchPriceScope->execute($observer);
748749
}
749750

751+
/**
752+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
753+
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
754+
* @magentoDbIsolation disabled
755+
* @magentoAppArea adminhtml
756+
*
757+
* @return void
758+
*/
759+
public function testFilterForNonDefaultStore(): void
760+
{
761+
$secondStoreCode = 'fixture_second_store';
762+
763+
/** @var \Magento\Store\Model\Store $store */
764+
$store = $this->objectManager->create(\Magento\Store\Model\Store::class);
765+
$secondStore = $store->load($secondStoreCode);
766+
767+
/** @var \Magento\Catalog\Model\Product\Action $productAction */
768+
$productAction = $this->objectManager->create(\Magento\Catalog\Model\Product\Action::class);
769+
770+
$this->model->setWriter(
771+
$this->objectManager->create(
772+
\Magento\ImportExport\Model\Export\Adapter\Csv::class
773+
)
774+
);
775+
776+
$product = $this->productRepository->get('simple');
777+
$productId = $product->getId();
778+
$productAction->updateWebsites([$productId], [$secondStore->getWebsiteId()], 'add');
779+
$product->setStoreId($secondStore->getId());
780+
$product->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE);
781+
$product->setName($product->getName() . ' ' . $secondStoreCode);
782+
$this->productRepository->save($product);
783+
784+
$exportData = $this->doExport(['visibility' => Visibility::VISIBILITY_BOTH]);
785+
$this->assertStringNotContainsString($product->getName(), $exportData);
786+
}
787+
750788
/**
751789
* Verify that "stock status" filter correctly applies to export result
752790
*

0 commit comments

Comments
 (0)