ProductVariationTypeTrait.php in Commerce Migrate 3.1.x
File
modules/ubercart/src/Plugin/migrate/source/ProductVariationTypeTrait.php
View source
<?php
namespace Drupal\commerce_migrate_ubercart\Plugin\migrate\source;
use Drupal\migrate\Row;
trait ProductVariationTypeTrait {
public function prepareRow(Row $row) {
if ($this
->getModuleHandler()
->moduleExists('commerce_shipping')) {
$row
->setSourceProperty('has_dimensions', FALSE);
$row
->setSourceProperty('shippable', FALSE);
$current_type = $row
->getSourceProperty('type');
$query = $this
->select('node', 'n')
->fields('n')
->condition('type', $current_type);
$query
->leftJoin('uc_products', 'uc', 'n.nid = uc.nid AND n.vid=uc.vid');
$or = $query
->orConditionGroup()
->condition('length', 0, '!=')
->condition('width', 0, '!=')
->condition('height', 0, '!=');
$query
->condition($or);
$num_rows = $query
->countQuery()
->execute()
->fetchField();
if ($num_rows) {
$row
->setSourceProperty('has_dimensions', TRUE);
}
$query = $this
->select('node', 'n')
->fields('n')
->condition('type', $current_type);
$query
->leftJoin('uc_products', 'uc', 'n.nid = uc.nid AND n.vid=uc.vid');
$query
->condition('weight', 0, '!=');
$num_rows = $query
->countQuery()
->execute()
->fetchField();
if ($num_rows) {
$row
->setSourceProperty('shippable', TRUE);
}
}
return parent::prepareRow($row);
}
public function fields() {
$fields = [];
if ($this
->getModuleHandler()
->moduleExists('commerce_shipping')) {
$fields = [
'has_dimensions' => $this
->t('Set if this type has dimensions'),
'shippable' => $this
->t('Set if this type is shippable'),
];
}
return parent::fields() + $fields;
}
}