You are here

public function CommerceExampleProductLineItemMigration::__construct in Commerce Migrate 7

General initialization of a Migration object.

Overrides CommerceMigrateExampleMigration::__construct

File

commerce_migrate_example/migrations/product_line_item.inc, line 15
Import line items of the "product" type.

Class

CommerceExampleProductLineItemMigration
Class CommerceExampleProductLineItemMigration.

Code

public function __construct(array $arguments) {
  parent::__construct($arguments);
  $this
    ->buildMap(MigrateDestinationEntityAPI::getKeySchema('commerce_line_item'));
  $this
    ->setDescription(t('Import commerce line items with products from CSV file (with no header).'));
  $this
    ->setDestination(new MigrateDestinationEntityAPI('commerce_line_item', 'product'));
  $this
    ->addFieldMapping('order_id', 'order_number')
    ->sourceMigration('CommerceExampleOrder');
  $this
    ->addFieldMapping('line_item_label', 'title');
  $this
    ->addFieldMapping('commerce_unit_price', 'price');
  $this
    ->addFieldMapping('commerce_unit_price:currency_code', 'currency_code')
    ->defaultValue(commerce_default_currency());
  $this
    ->addFieldMapping('commerce_unit_price:components:shipping', 'price')
    ->callbacks(array(
    $this,
    'priceComponentShipping',
  ));
  $this
    ->addFieldMapping('type', 'sku')
    ->callbacks(array(
    $this,
    'type',
  ));
  $this
    ->addFieldMapping('commerce_product', 'sku')
    ->sourceMigration('CommerceExampleProduct')
    ->callbacks(array(
    $this,
    'shouldProductBeAttached',
  ));
  $this
    ->addFieldMapping('created')
    ->defaultValue(time());
  $this
    ->addFieldMapping('quantity')
    ->defaultValue(5);
  $this
    ->addUnmigratedDestinations(array(
    'commerce_display_path',
    // Total always calculated automatically.
    'commerce_total:currency_code',
    'commerce_total',
    'order',
    'path',
  ));
  $this
    ->addUnmigratedSources(array(
    'image',
    'description',
  ));
}