Skip to content

Commit a3ff3c6

Browse files
author
Leonid Poluyanov
committed
Merge remote-tracking branch 'origin/MAGETWO-37726' into MAGETWO-37985
2 parents 6c40c3b + bcffd63 commit a3ff3c6

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

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

Lines changed: 20 additions & 12 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,13 @@ 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+
}
678686
return $this->_entityCollection;
679687
}
680688

@@ -735,23 +743,23 @@ protected function paginateCollection($page, $pageSize)
735743
/**
736744
* Export process
737745
*
738-
* @see https://jira.corp.x.com/browse/MAGETWO-7894
739746
* @return string
740747
*/
741748
public function export()
742749
{
743750
//Execution time may be very long
744751
set_time_limit(0);
745752

746-
$this->_prepareEntityCollection($this->_getEntityCollection());
747-
$this->_getEntityCollection()->setOrder('has_options', 'asc');
748-
$this->_getEntityCollection()->setStoreId(Store::DEFAULT_STORE_ID);
749753
$writer = $this->getWriter();
750754
$page = 0;
751755
while (true) {
752756
++$page;
757+
$entityCollection = $this->_getEntityCollection(true);
758+
$entityCollection->setOrder('has_options', 'asc');
759+
$entityCollection->setStoreId(Store::DEFAULT_STORE_ID);
760+
$this->_prepareEntityCollection($entityCollection);
753761
$this->paginateCollection($page, $this->getItemsPerPage());
754-
if ($this->_getEntityCollection()->count() == 0) {
762+
if ($entityCollection->count() == 0) {
755763
break;
756764
}
757765
$exportData = $this->getExportData();
@@ -761,7 +769,7 @@ public function export()
761769
foreach ($exportData as $dataRow) {
762770
$writer->writeRow($dataRow);
763771
}
764-
if ($this->_getEntityCollection()->getCurPage() >= $this->_getEntityCollection()->getLastPageNumber()) {
772+
if ($entityCollection->getCurPage() >= $entityCollection->getLastPageNumber()) {
765773
break;
766774
}
767775
}

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)