Skip to content

Instantly share code, notes, and snippets.

@claudiu-cristea
Created September 19, 2014 10:09
Show Gist options
  • Save claudiu-cristea/d87db7d38002dda60127 to your computer and use it in GitHub Desktop.
Save claudiu-cristea/d87db7d38002dda60127 to your computer and use it in GitHub Desktop.
$this->map = new MigrateSQLMap($this->machineName,
array(
'sku' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'delta' => array(
'type' = 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Type of ticket',
),
),
MigrateDestinationEntityAPI::getKeySchema('commerce_product')
);
...
public function prepareRow($row) {
...
$row->delta = 0;
...
}
...
public function prepare($entity, stdClass $row) {
for ($delta = 1; $delta <= 7, $delta++) {
$variant = entity_create('commerce_product', array(
'sku' => $row->wathever,
...
'property' => $row->foo,
...
));
commerce_product_save($variant);
$source = clone $row;
$source->delta = $delta;
$this->map->saveIDMapping($source, array($variant->sku));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment