Skip to content

Commit c19d876

Browse files
authored
Merge pull request #3303 from magento-helix/MAGETWO-94670
[helix] MAGETWO-94670: Product Export fails
2 parents 448770c + 3121973 commit c19d876

File tree

1 file changed

+24
-14
lines changed
  • app/code/Magento/CatalogImportExport/Model/Export

1 file changed

+24
-14
lines changed

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

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
352352
* @param \Magento\Framework\App\ResourceConnection $resource
353353
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
354354
* @param \Psr\Log\LoggerInterface $logger
355-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
355+
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
356356
* @param \Magento\ImportExport\Model\Export\ConfigInterface $exportConfig
357357
* @param \Magento\Catalog\Model\ResourceModel\ProductFactory $productFactory
358358
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $attrSetColFactory
@@ -361,9 +361,10 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
361361
* @param \Magento\Catalog\Model\ResourceModel\Product\Option\CollectionFactory $optionColFactory
362362
* @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeColFactory
363363
* @param Product\Type\Factory $_typeFactory
364-
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
365-
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
364+
* @param ProductEntity\LinkTypeProvider $linkTypeProvider
365+
* @param RowCustomizerInterface $rowCustomizer
366366
* @param array $dateAttrCodes
367+
* @throws \Magento\Framework\Exception\LocalizedException
367368
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
368369
*/
369370
public function __construct(
@@ -517,10 +518,13 @@ protected function getMediaGallery(array $productIds)
517518
if (empty($productIds)) {
518519
return [];
519520
}
521+
522+
$productEntityJoinField = $this->getProductEntityLinkField();
523+
520524
$select = $this->_connection->select()->from(
521525
['mgvte' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value_to_entity')],
522526
[
523-
"mgvte.{$this->getProductEntityLinkField()}",
527+
"mgvte.$productEntityJoinField",
524528
'mgvte.value_id'
525529
]
526530
)->joinLeft(
@@ -532,22 +536,22 @@ protected function getMediaGallery(array $productIds)
532536
]
533537
)->joinLeft(
534538
['mgv' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value')],
535-
'(mg.value_id = mgv.value_id)',
539+
"(mg.value_id = mgv.value_id) and (mgvte.$productEntityJoinField = mgv.$productEntityJoinField)",
536540
[
537541
'mgv.label',
538542
'mgv.position',
539543
'mgv.disabled',
540544
'mgv.store_id'
541545
]
542546
)->where(
543-
"mgvte.{$this->getProductEntityLinkField()} IN (?)",
547+
"mgvte.$productEntityJoinField IN (?)",
544548
$productIds
545549
);
546550

547551
$rowMediaGallery = [];
548552
$stmt = $this->_connection->query($select);
549553
while ($mediaRow = $stmt->fetch()) {
550-
$rowMediaGallery[$mediaRow[$this->getProductEntityLinkField()]][] = [
554+
$rowMediaGallery[$mediaRow[$productEntityJoinField]][] = [
551555
'_media_attribute_id' => $mediaRow['attribute_id'],
552556
'_media_image' => $mediaRow['filename'],
553557
'_media_label' => $mediaRow['label'],
@@ -689,6 +693,8 @@ protected function updateDataWithCategoryColumns(&$dataRow, &$rowCategories, $pr
689693
}
690694

691695
/**
696+
* Get header columns
697+
*
692698
* {@inheritdoc}
693699
*/
694700
public function _getHeaderColumns()
@@ -748,6 +754,8 @@ protected function _getExportMainAttrCodes()
748754
}
749755

750756
/**
757+
* Get entity collection
758+
*
751759
* {@inheritdoc}
752760
*/
753761
protected function _getEntityCollection($resetCollection = false)
@@ -818,9 +826,8 @@ protected function paginateCollection($page, $pageSize)
818826
}
819827

820828
/**
821-
* Export process
822-
*
823829
* @return string
830+
* @throws \Magento\Framework\Exception\LocalizedException
824831
*/
825832
public function export()
826833
{
@@ -854,7 +861,11 @@ public function export()
854861
}
855862

856863
/**
857-
* {@inheritdoc}
864+
* Apply filter to collection and add not skipped attributes to select.
865+
*
866+
* @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection
867+
* @return \Magento\Eav\Model\Entity\Collection\AbstractCollection
868+
*
858869
* @since 100.2.0
859870
*/
860871
protected function _prepareEntityCollection(\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection)
@@ -916,11 +927,10 @@ protected function getExportData()
916927
}
917928

918929
/**
919-
* Load products' data from the collection
920-
* and filter it (if needed).
930+
* Load products' data from the collection and filter it (if needed).
921931
*
922-
* @return array Keys are product IDs, values arrays with keys as store IDs
923-
* and values as store-specific versions of Product entity.
932+
* @return array Keys are product IDs, values arrays with keys as store ID
933+
* and values as store-specific versions of Product entity.
924934
*/
925935
protected function loadCollection(): array
926936
{

0 commit comments

Comments
 (0)