Skip to content

Commit 99c09fb

Browse files
author
Denys Rudchenko
committed
MAGETWO-37726: Incorrect export result on medium profile
1 parent d70ae0c commit 99c09fb

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
123123
*/
124124
protected $_attributeTypes = [];
125125

126+
/**
127+
* Product collection
128+
*
129+
* @var \Magento\Catalog\Model\Resource\Product\CollectionFactory
130+
*/
131+
protected $_entityCollectionFactory;
132+
126133
/**
127134
* Product collection
128135
*
@@ -231,7 +238,7 @@ public function __construct(
231238
\Magento\Framework\App\Resource $resource,
232239
\Magento\Store\Model\StoreManagerInterface $storeManager,
233240
\Psr\Log\LoggerInterface $logger,
234-
\Magento\Catalog\Model\Resource\Product\Collection $collection,
241+
\Magento\Catalog\Model\Resource\Product\CollectionFactory $collectionFactory,
235242
\Magento\ImportExport\Model\Export\ConfigInterface $exportConfig,
236243
\Magento\Catalog\Model\Resource\ProductFactory $productFactory,
237244
\Magento\Eav\Model\Resource\Entity\Attribute\Set\CollectionFactory $attrSetColFactory,
@@ -243,7 +250,7 @@ public function __construct(
243250
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
244251
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
245252
) {
246-
$this->_entityCollection = $collection;
253+
$this->_entityCollectionFactory = $collectionFactory;
247254
$this->_exportConfig = $exportConfig;
248255
$this->_logger = $logger;
249256
$this->_productFactory = $productFactory;
@@ -669,12 +676,16 @@ protected function setHeaderColumns($customOptionsData, $stockItemRows)
669676
}
670677

671678
/**
672-
* Get product collection
673-
*
674-
* @return \Magento\Catalog\Model\Resource\Product\Collection
679+
* {@inheritdoc}
675680
*/
676-
protected function _getEntityCollection()
681+
protected function _getEntityCollection($resetCollection = false)
677682
{
683+
if ($resetCollection || empty($this->_entityCollection)) {
684+
$this->_entityCollection = $this->_entityCollectionFactory->create();
685+
$this->_entityCollection->setOrder('has_options', 'asc');
686+
$this->_entityCollection->setStoreId(Store::DEFAULT_STORE_ID);
687+
688+
}
678689
return $this->_entityCollection;
679690
}
680691

@@ -735,21 +746,18 @@ protected function paginateCollection($page, $pageSize)
735746
/**
736747
* Export process
737748
*
738-
* @see https://jira.corp.x.com/browse/MAGETWO-7894
739749
* @return string
740750
*/
741751
public function export()
742752
{
743753
//Execution time may be very long
744754
set_time_limit(0);
745755

746-
$this->_prepareEntityCollection($this->_getEntityCollection());
747-
$this->_getEntityCollection()->setOrder('has_options', 'asc');
748-
$this->_getEntityCollection()->setStoreId(Store::DEFAULT_STORE_ID);
749756
$writer = $this->getWriter();
750757
$page = 0;
751758
while (true) {
752759
++$page;
760+
$this->_prepareEntityCollection($this->_getEntityCollection(true));
753761
$this->paginateCollection($page, $this->getItemsPerPage());
754762
if ($this->_getEntityCollection()->count() == 0) {
755763
break;

app/code/Magento/ImportExport/Model/Export/Entity/AbstractEntity.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ abstract protected function _getHeaderColumns();
190190
/**
191191
* Get entity collection
192192
*
193+
* @param bool $resetCollection
193194
* @return \Magento\Framework\Data\Collection\Db
194195
*/
195-
abstract protected function _getEntityCollection();
196+
abstract protected function _getEntityCollection($resetCollection = false);
196197

197198
/**
198199
* Get attributes codes which are appropriate for export.

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,22 @@ public function testExport()
7070
*/
7171
public function testExportStockItemAttributesAreFilled()
7272
{
73-
$filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
73+
$fileWrite = $this->getMock('Magento\Framework\Filesystem\File\Write', [], [], '', false);
7474
$directoryMock = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
75-
76-
$filesystemMock->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($directoryMock));
77-
7875
$directoryMock->expects($this->any())->method('getParentDirectory')->will($this->returnValue('some#path'));
79-
8076
$directoryMock->expects($this->any())->method('isWritable')->will($this->returnValue(true));
81-
8277
$directoryMock->expects($this->any())->method('isFile')->will($this->returnValue(true));
83-
8478
$directoryMock->expects(
8579
$this->any()
8680
)->method(
8781
'readFile'
8882
)->will(
8983
$this->returnValue('some string read from file')
9084
);
85+
$directoryMock->expects($this->once())->method('openFile')->will($this->returnValue($fileWrite));
86+
87+
$filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
88+
$filesystemMock->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($directoryMock));
9189

9290
$exportAdapter = new \Magento\ImportExport\Model\Export\Adapter\Csv($filesystemMock);
9391

0 commit comments

Comments
 (0)