Field.php in Commerce Migrate 3.0.x
File
modules/commerce/src/Plugin/migrate/source/commerce1/Field.php
View source
<?php
namespace Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1;
use Drupal\field\Plugin\migrate\source\d7\Field as CoreField;
class Field extends CoreField {
protected function initializeIterator() {
$results = $this
->prepareQuery()
->execute()
->fetchAll();
$query = $this
->select('commerce_product_type', 'pt')
->fields('pt', [
'type',
]);
$product_node_types = $query
->execute()
->fetchCol();
$new_rows = [];
foreach ($results as &$result) {
$result['commerce1_entity_type'] = $result['entity_type'];
if ($result['entity_type'] === 'node') {
$instances = $this
->select('field_config_instance', 'fci')
->fields('fci')
->condition('field_name', $result['field_name'])
->condition('entity_type', $result['entity_type'])
->execute()
->fetchAll();
$i = 0;
foreach ($instances as $instance) {
if (in_array($instance['bundle'], $product_node_types)) {
$i++;
}
}
if ($i > 0) {
if ($i == count($instances)) {
$result['commerce1_entity_type'] = 'product_display';
}
else {
$new_row = $result;
$new_row['commerce1_entity_type'] = 'product_display';
$new_row['entity_type'] = 'product_display';
$new_rows[] = $new_row;
}
}
}
}
foreach ($new_rows as $new_row) {
array_push($results, $new_row);
}
return new \ArrayIterator($results);
}
}
Classes
Name |
Description |
Field |
The field source class. |