Skip to content

Commit ddebd16

Browse files
Dmitry KologrivovA-Komar
authored andcommitted
MAGNIMEX-145: Added customization of images' array
1 parent 32d4459 commit ddebd16

File tree

1 file changed

+8
-14
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import

1 file changed

+8
-14
lines changed

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,6 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
362362
*/
363363
protected $_imagesArrayKeys = ['_media_image', 'image', 'small_image', 'thumbnail'];
364364

365-
/**
366-
* Column names that holds images files names from bunch
367-
*
368-
* @var string[]
369-
*/
370-
protected $_imagesArrayKeysFromBunch = ['base_image', 'small_image', 'thumbnail_image', 'additional_images'];
371-
372365
/**
373366
* Permanent entity columns.
374367
*
@@ -1330,9 +1323,9 @@ protected function _saveProducts()
13301323
$this->websitesCache[$rowSku] = [];
13311324
// 2. Product-to-Website phase
13321325
if (!empty($rowData[self::COL_PRODUCT_WEBSITES])) {
1333-
$websiteIds = explode($this->getMultipleValueSeparator(), $rowData[self::COL_PRODUCT_WEBSITES]);
1334-
foreach ($websiteIds as $websiteId) {
1335-
$websiteId = $this->storeResolver->getWebsiteCodeToId($rowData[self::COL_PRODUCT_WEBSITES]);
1326+
$websiteCodes = explode($this->getMultipleValueSeparator(), $rowData[self::COL_PRODUCT_WEBSITES]);
1327+
foreach ($websiteCodes as $websiteCode) {
1328+
$websiteId = $this->storeResolver->getWebsiteCodeToId($websiteCode);
13361329
$this->websitesCache[$rowSku][$websiteId] = true;
13371330
}
13381331
}
@@ -1667,10 +1660,11 @@ protected function getMediaGalleryData($bunch)
16671660
{
16681661
$allImagesFromBunch = [];
16691662
foreach ($bunch as $rowData) {
1670-
foreach ($this->_imagesArrayKeysFromBunch as $image) {
1663+
$rowData = $this->_customFieldsMapping($rowData);
1664+
foreach ($this->_imagesArrayKeys as $image) {
16711665
$dispersionPath =
16721666
\Magento\Framework\File\Uploader::getDispretionPath($rowData[$image]);
1673-
$importImages = explode(",", $rowData[$image]);
1667+
$importImages = explode($this->getMultipleValueSeparator(), $rowData[$image]);
16741668
foreach ($importImages as $importImage) {
16751669
$imageSting = mb_strtolower(
16761670
$dispersionPath . '/' . preg_replace('/[^a-z0-9\._-]+/i', '', $importImage)
@@ -1768,13 +1762,13 @@ protected function getMediaGalleryData($bunch)
17681762
}
17691763
if (!empty($rowData[self::COL_MEDIA_IMAGE]) && is_array($rowData[self::COL_MEDIA_IMAGE])) {
17701764
$position = array_search($mediaImage, $mediaGalleryImages);
1771-
foreach ($rowData[self::COL_MEDIA_IMAGE] as $media_image) {
1765+
foreach ($rowData[self::COL_MEDIA_IMAGE] as $mediaImage) {
17721766
$mediaGallery[$rowSku][] = [
17731767
'attribute_id' => $this->getMediaGalleryAttributeId(),
17741768
'label' => isset($mediaGalleryLabels[$position]) ? $mediaGalleryLabels[$position] : '',
17751769
'position' => $position,
17761770
'disabled' => '',
1777-
'value' => $media_image,
1771+
'value' => $mediaImage,
17781772
];
17791773
}
17801774
}

0 commit comments

Comments
 (0)