Skip to content

Commit

Permalink
Merge pull request magento#3303 from magento-helix/MAGETWO-94670
Browse files Browse the repository at this point in the history
[helix] MAGETWO-94670: Product Export fails
  • Loading branch information
duhon authored Oct 16, 2018
2 parents 448770c + 3121973 commit c19d876
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
* @param \Magento\Framework\App\ResourceConnection $resource
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
* @param \Magento\ImportExport\Model\Export\ConfigInterface $exportConfig
* @param \Magento\Catalog\Model\ResourceModel\ProductFactory $productFactory
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $attrSetColFactory
Expand All @@ -361,9 +361,10 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
* @param \Magento\Catalog\Model\ResourceModel\Product\Option\CollectionFactory $optionColFactory
* @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeColFactory
* @param Product\Type\Factory $_typeFactory
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
* @param ProductEntity\LinkTypeProvider $linkTypeProvider
* @param RowCustomizerInterface $rowCustomizer
* @param array $dateAttrCodes
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand Down Expand Up @@ -517,10 +518,13 @@ protected function getMediaGallery(array $productIds)
if (empty($productIds)) {
return [];
}

$productEntityJoinField = $this->getProductEntityLinkField();

$select = $this->_connection->select()->from(
['mgvte' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value_to_entity')],
[
"mgvte.{$this->getProductEntityLinkField()}",
"mgvte.$productEntityJoinField",
'mgvte.value_id'
]
)->joinLeft(
Expand All @@ -532,22 +536,22 @@ protected function getMediaGallery(array $productIds)
]
)->joinLeft(
['mgv' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value')],
'(mg.value_id = mgv.value_id)',
"(mg.value_id = mgv.value_id) and (mgvte.$productEntityJoinField = mgv.$productEntityJoinField)",
[
'mgv.label',
'mgv.position',
'mgv.disabled',
'mgv.store_id'
]
)->where(
"mgvte.{$this->getProductEntityLinkField()} IN (?)",
"mgvte.$productEntityJoinField IN (?)",
$productIds
);

$rowMediaGallery = [];
$stmt = $this->_connection->query($select);
while ($mediaRow = $stmt->fetch()) {
$rowMediaGallery[$mediaRow[$this->getProductEntityLinkField()]][] = [
$rowMediaGallery[$mediaRow[$productEntityJoinField]][] = [
'_media_attribute_id' => $mediaRow['attribute_id'],
'_media_image' => $mediaRow['filename'],
'_media_label' => $mediaRow['label'],
Expand Down Expand Up @@ -689,6 +693,8 @@ protected function updateDataWithCategoryColumns(&$dataRow, &$rowCategories, $pr
}

/**
* Get header columns
*
* {@inheritdoc}
*/
public function _getHeaderColumns()
Expand Down Expand Up @@ -748,6 +754,8 @@ protected function _getExportMainAttrCodes()
}

/**
* Get entity collection
*
* {@inheritdoc}
*/
protected function _getEntityCollection($resetCollection = false)
Expand Down Expand Up @@ -818,9 +826,8 @@ protected function paginateCollection($page, $pageSize)
}

/**
* Export process
*
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function export()
{
Expand Down Expand Up @@ -854,7 +861,11 @@ public function export()
}

/**
* {@inheritdoc}
* Apply filter to collection and add not skipped attributes to select.
*
* @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection
* @return \Magento\Eav\Model\Entity\Collection\AbstractCollection
*
* @since 100.2.0
*/
protected function _prepareEntityCollection(\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection)
Expand Down Expand Up @@ -916,11 +927,10 @@ protected function getExportData()
}

/**
* Load products' data from the collection
* and filter it (if needed).
* Load products' data from the collection and filter it (if needed).
*
* @return array Keys are product IDs, values arrays with keys as store IDs
* and values as store-specific versions of Product entity.
* @return array Keys are product IDs, values arrays with keys as store ID
* and values as store-specific versions of Product entity.
*/
protected function loadCollection(): array
{
Expand Down

0 comments on commit c19d876

Please sign in to comment.