Skip to content

Commit 50dcdf5

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-3735' into PR_2025_05_16
2 parents 147e077 + c7f00eb commit 50dcdf5

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,13 +1004,13 @@ public function export()
10041004
++$page;
10051005
$entityCollection = $this->_getEntityCollection(true);
10061006
$entityCollection->setOrder('entity_id', 'asc');
1007-
$entityCollection->setStoreId(Store::DEFAULT_STORE_ID);
10081007
$this->_prepareEntityCollection($entityCollection);
10091008
$this->paginateCollection($page, $this->getItemsPerPage());
1010-
if ($entityCollection->count() == 0) {
1009+
1010+
$exportData = $this->getExportData();
1011+
if ($exportData == null || count($exportData) == 0) {
10111012
break;
10121013
}
1013-
$exportData = $this->getExportData();
10141014
if ($page == 1) {
10151015
$writer->setHeaderCols($this->_getHeaderColumns());
10161016
}
@@ -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());

app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,16 +342,12 @@ public function testExportCountZeroBreakInternalCalls()
342342
$this->product->expects($this->once())->method('getItemsPerPage')->willReturn($itemsPerPage);
343343
$this->product->expects($this->once())->method('paginateCollection')->with($page, $itemsPerPage);
344344
$this->abstractCollection->expects($this->once())->method('setOrder')->with('entity_id', 'asc');
345-
$this->abstractCollection->expects($this->once())->method('setStoreId')->with(Store::DEFAULT_STORE_ID);
346-
347-
$this->abstractCollection->expects($this->once())->method('count')->willReturn(0);
348345

349346
$this->abstractCollection->expects($this->never())->method('getCurPage');
350347
$this->abstractCollection->expects($this->never())->method('getLastPageNumber');
351348
$this->product->expects($this->never())->method('_getHeaderColumns');
352349
$this->writer->expects($this->never())->method('setHeaderCols');
353350
$this->writer->expects($this->never())->method('writeRow');
354-
$this->product->expects($this->never())->method('getExportData');
355351
$this->product->expects($this->never())->method('_customFieldsMapping');
356352

357353
$this->writer->expects($this->once())->method('getContents');
@@ -373,9 +369,6 @@ public function testExportCurPageEqualToLastBreakInternalCalls()
373369
$this->product->expects($this->once())->method('getItemsPerPage')->willReturn($itemsPerPage);
374370
$this->product->expects($this->once())->method('paginateCollection')->with($page, $itemsPerPage);
375371
$this->abstractCollection->expects($this->once())->method('setOrder')->with('entity_id', 'asc');
376-
$this->abstractCollection->expects($this->once())->method('setStoreId')->with(Store::DEFAULT_STORE_ID);
377-
378-
$this->abstractCollection->expects($this->once())->method('count')->willReturn(1);
379372

380373
$this->abstractCollection->expects($this->once())->method('getCurPage')->willReturn($curPage);
381374
$this->abstractCollection->expects($this->once())->method('getLastPageNumber')->willReturn($lastPage);

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)