Image.php in Commerce Migrate 8.2
File
modules/magento/src/Plugin/migrate/source/magento2/Image.php
View source
<?php
namespace Drupal\commerce_migrate_magento\Plugin\migrate\source\magento2;
use Drupal\migrate_source_csv\Plugin\migrate\source\CSV;
class Image extends CSV {
public function initializeIterator() {
$file = parent::initializeIterator();
return $this
->getYield($file);
}
public function getYield(\Generator $file) {
$image_types = [
[
'base_image',
'base_image_label',
],
[
'small_image',
'small_image_label',
],
[
'thumbnail_image',
'thumbnail_image_label',
],
[
'swatch_image',
'swatch_image_label',
],
];
foreach ($file as $row) {
foreach ($image_types as $image_type) {
$new_row = [];
$new_row['sku'] = trim($row['sku']);
if (!empty($row[$image_type[0]])) {
$new_row['image'] = trim($row[$image_type[0]]);
$new_row['label'] = trim($row[$image_type[1]]);
(yield $new_row);
}
}
$additional_images = explode(',', $row['additional_images']);
$additional_image_labels = explode(',', $row['additional_image_labels']);
foreach ($additional_images as $index => $value) {
$new_row = [];
$new_row['sku'] = trim($row['sku']);
$new_row['image'] = trim($value);
if (isset($additional_image_labels[$index])) {
$new_row['label'] = trim($additional_image_labels[$index]);
}
(yield $new_row);
}
}
}
}
Classes
Name |
Description |
Image |
Yields each image and sku. |