Skip to content

Instantly share code, notes, and snippets.

@lsolesen
Last active August 29, 2015 14:00
Show Gist options
  • Save lsolesen/11382613 to your computer and use it in GitHub Desktop.
Save lsolesen/11382613 to your computer and use it in GitHub Desktop.
Create product discount for commerce kickstart 2.x
<?php
class CommerceKickstartDiscounts extends CommerceKickstartMigration {
public function __construct() {
parent::__construct();
$this->description = t('Import discounts.');
// Create a map object for tracking the relationships between source rows
$this->map = new MigrateSQLMap($this->machineName,
array(
'label' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
),
MigrateDestinationEntityAPI::getKeySchema('commerce_discount', 'product_discount')
);
// Create a MigrateSource object.
$this->source = new MigrateSourceCSV(drupal_get_path('module', 'commerce_kickstart_migrate') . '/import/discounts.csv', $this->csvcolumns(), array('header_rows' => 1));
$this->destination = new MigrateDestinationEntityAPI('commerce_discount', 'product_discount');
// We need to figure out the field mapping correctly to commerce_discount
$this->addFieldMapping('label', 'label');
$this->addFieldMapping('component_title', 'title');
$this->addFieldMapping('commerce_discount_fields[inline_conditions][und][0][condition_name]', 'condition_name');
$this->addFieldMapping('commerce_discount_fields[inline_conditions][und][0][condition_settings][type]', 'type');
$this->addFieldMapping('commerce_discount_fields[commerce_discount_offer][und][form][type]', 'offer');
$this->addFieldMapping('[commerce_percentage][und][0][value]', 'value');
}
function csvcolumns() {
$columns[0] = array('label', 'Label');
$columns[1] = array('title', 'Title');
$columns[2] = array('condition_name', 'Condition name');
$columns[3] = array('type', 'Type');
$columns[4] = array('offer', 'Offer');
$columns[5] = array('value', 'Value');
return $columns;
}
}
Label Title Condition name Type Offer Value
25% on all bags SAVE 25% on bags commerce_product_has_type bags_cases percentage 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment