Commit 8074fc50 authored by Matt Glaman's avatar Matt Glaman

Merge pull request #122 from mglaman/commerce-kickstart-migrate-update

Update Migrate API integration
parents 439609f4 c6a7c2df
......@@ -35,6 +35,7 @@ projects[commerce_autosku][download][type] = git
projects[commerce_autosku][download][revision] = 562b9a5
projects[commerce_autosku][download][branch] = 7.x-1.x
projects[commerce_migrate][version] = 1.1
projects[commerce_migrate][patch][1931302] = https://www.drupal.org/files/commerce_products_source_migration-1931302-2.patch
projects[commerce_discount][version] = 1.x-dev
projects[commerce_discount][download][type] = git
projects[commerce_discount][download][revision] = 7a78225
......@@ -101,7 +102,7 @@ projects[token][patch][] = "http://drupal.org/files/token-token_asort_tokens-171
projects[eva][version] = 1.2
projects[message][version] = 1.10
projects[message_notify][version] = 2.5
projects[migrate][version] = 2.5
projects[migrate][version] = 2.8
projects[migrate_extras][version] = 2.5
projects[migrate_extras][patch][] = "http://drupal.org/files/migrate_extras-fix-destid2-array-1951904-4.patch"
projects[date][version] = 2.8
......
......@@ -2,13 +2,19 @@
/**
* @file
* Migrations for commerce_kickstart_blog.
* Migrations for commerce_kickstart_blog.
*/
/**
* Class CommerceKickstartBlogPost.
*/
class CommerceKickstartBlogPost extends CommerceKickstartMigration {
public function __construct() {
parent::__construct();
/**
* {@inheritdoc}
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import blog-post nodes.');
$this->dependencies = array('CommerceKickstartPages');
......@@ -48,7 +54,13 @@ class CommerceKickstartBlogPost extends CommerceKickstartMigration {
$this->addFieldMapping('uid', 'uid')->defaultValue(1);
}
function csvcolumns() {
/**
* Returns CSV header mappings.
*
* @return mixed
* Array of mappings.
*/
public function csvcolumns() {
// "Title", "Images", "Tags", "Body"
$columns[0] = array('title', 'Title');
$columns[1] = array('images', 'Images');
......
......@@ -2,13 +2,19 @@
/**
* @file
* Migrations for commerce_kickstart_lite_product.
* Migrations for commerce_kickstart_lite_product.
*/
/**
* Class CommerceKickstartProduct.
*/
class CommerceKickstartProduct extends CommerceKickstartMigration {
public function __construct() {
parent::__construct();
/**
* {@inheritdoc}
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import products.');
// Create a map object for tracking the relationships between source rows
......@@ -20,7 +26,7 @@ class CommerceKickstartProduct extends CommerceKickstartMigration {
'not null' => TRUE,
),
),
MigrateDestinationEntityAPI::getKeySchema('commerce_product', 'product')
MigrateDestinationEntityAPI::getKeySchema('commerce_product')
);
// Create a MigrateSource object.
......@@ -43,7 +49,13 @@ class CommerceKickstartProduct extends CommerceKickstartMigration {
$this->addFieldMapping('language', 'language');
}
function csvcolumns() {
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
public function csvcolumns() {
$columns[0] = array('title', 'Title');
$columns[1] = array('sku', 'SKU');
$columns[2] = array('price', 'Price');
......@@ -52,24 +64,38 @@ class CommerceKickstartProduct extends CommerceKickstartMigration {
return $columns;
}
function fields() {
/**
* Returns mapping for fields.
*
* @return array
* Array of fields names and description.
*/
public function fields() {
return array(
'product_images' => 'An array of images, populated during prepareRow().',
);
}
function prepareRow($row) {
/**
* {@inheritdoc}
*/
public function prepareRow($row) {
$row->product_images = explode(', ', $row->images);
$row->uid = 1;
$row->language = LANGUAGE_NONE;
}
}
/**
* Class CommerceKickstartNode.
*/
class CommerceKickstartNode extends CommerceKickstartMigration {
public function __construct() {
parent::__construct();
/**
* {@inheritdoc}
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import product nodes.');
$this->dependencies = array(
......@@ -104,6 +130,9 @@ class CommerceKickstartNode extends CommerceKickstartMigration {
$this->addFieldMapping('field_product', 'skus');
}
/**
* {@inheritdoc}
*/
public function prepareRow($row) {
$products = array();
foreach (explode(', ', $row->sku) as $sku) {
......@@ -113,6 +142,12 @@ class CommerceKickstartNode extends CommerceKickstartMigration {
$row->skus = $products;
}
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
function csvcolumns() {
$columns[0] = array('title', 'Title');
$columns[1] = array('description', 'Description');
......
......@@ -2,13 +2,19 @@
/**
* @file
* Migrations for commerce_kickstart_merchandising.
* Migrations for commerce_kickstart_merchandising.
*/
/**
* Class CommerceKickstartAdPush.
*/
class CommerceKickstartAdPush extends CommerceKickstartMigration {
public function __construct() {
parent::__construct();
/**
* {@inheritdoc}
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import ad-push nodes.');
$this->softDependencies = array('CommerceKickstartPages');
......@@ -42,7 +48,13 @@ class CommerceKickstartAdPush extends CommerceKickstartMigration {
$this->addFieldMapping('uid', 'uid')->defaultValue(1);
}
function csvcolumns() {
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
public function csvcolumns() {
// "Title", "Tagline", "Link", "Images"
$columns[0] = array('title', 'Title');
$columns[1] = array('tagline', 'Tagline');
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains base migration classes used by other Commerce Kickstart modules.
* Contains base migration classes used by other Commerce Kickstart modules.
*/
/**
......@@ -10,21 +10,31 @@
*/
abstract class CommerceKickstartMigration extends Migration {
/**
* {@inheritdoc}
*/
public function processImport(array $options = array()) {
parent::processImport($options);
// Do not force menu rebuilding. Otherwise pathauto will try to rebuild
// in each node_insert invocation.
variable_set('menu_rebuild_needed', FALSE);
}
}
/**
* Class CommerceKickstartPages.
*/
class CommerceKickstartPages extends CommerceKickstartMigration {
public function __construct() {
parent::__construct();
/**
* {@inheritdoc}
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import pages nodes.');
// Create a map object for tracking the relationships between source rows
// Create a map object for tracking the relationships between source rows.
$this->map = new MigrateSQLMap($this->machineName,
array(
'title' => array(
......@@ -51,7 +61,13 @@ class CommerceKickstartPages extends CommerceKickstartMigration {
$this->addFieldMapping('is_new', 'is_new')->defaultValue(TRUE);
}
function csvcolumns() {
/**
* Returns CSV header mappings.
*
* @return mixed
* Array of mappings.
*/
public function csvcolumns() {
// "nid", "Title", "Path", "Body"
$columns[0] = array('nid', 'nid');
$columns[1] = array('title', 'Title');
......@@ -59,4 +75,5 @@ class CommerceKickstartPages extends CommerceKickstartMigration {
$columns[3] = array('body', 'Body');
return $columns;
}
}
......@@ -2,16 +2,22 @@
/**
* @file
* Migrations for commerce_kickstart_product.
* Migrations for commerce_kickstart_product.
*/
/**
* Class CommerceKickstartBagsCases.
*/
class CommerceKickstartBagsCases extends CommerceKickstartMigration {
public function __construct() {
parent::__construct();
/**
* {@inheritdoc}
*/
public function __construct($arguments = array()) {
parent::__construct($arguments);
$this->description = t('Import bags cases from CSV file.');
// Create a map object for tracking the relationships between source rows
// Create a map object for tracking the relationships between source rows.
$this->map = new MigrateSQLMap($this->machineName,
array(
'sku' => array(
......@@ -20,7 +26,7 @@ class CommerceKickstartBagsCases extends CommerceKickstartMigration {
'not null' => TRUE,
),
),
MigrateDestinationEntityAPI::getKeySchema('commerce_product', 'bags_cases')
MigrateDestinationEntityAPI::getKeySchema('commerce_product')
);
// Create a MigrateSource object.
......@@ -32,19 +38,19 @@ class CommerceKickstartBagsCases extends CommerceKickstartMigration {
$this->addFieldMapping('sku', 'sku');
$this->addFieldMapping('commerce_price', 'price');
// Size
// Size.
$this->addFieldMapping('field_bag_size', 'size');
$this->addFieldMapping('field_bag_size:create_term')
->defaultValue(TRUE);
// Images
// Images.
$this->addFieldMapping('field_images', 'product_images');
$this->addFieldMapping('field_images:file_replace')
->defaultValue(FILE_EXISTS_REPLACE);
$this->addFieldMapping('field_images:source_dir')
->defaultValue(drupal_get_path('module', 'commerce_kickstart_product') . '/import/images');
// Color
// Color.
$this->addFieldMapping('field_color', 'color');
$this->addFieldMapping('field_color:additional_field', 'hexadecimal');
$this->addFieldMapping('field_color:create_term')
......@@ -54,7 +60,13 @@ class CommerceKickstartBagsCases extends CommerceKickstartMigration {
$this->addFieldMapping('language', 'language');
}
function csvcolumns() {
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
public function csvcolumns() {
$columns[0] = array('title', 'Title');
$columns[1] = array('sku', 'SKU');
$columns[2] = array('color', 'Color');
......@@ -65,26 +77,42 @@ class CommerceKickstartBagsCases extends CommerceKickstartMigration {
return $columns;
}
function fields() {
/**
* Returns mapping for fields.
*
* @return array
* Array of fields names and description.
*/
public function fields() {
return array(
'product_images' => 'An array of images, populated during prepareRow().',
);
}
function prepareRow($row) {
/**
* {@inheritdoc}
*/
public function prepareRow($row) {
$row->product_images = explode(', ', $row->images);
$row->uid = 1;
$row->language = LANGUAGE_NONE;
}
}
/**
* Class CommerceKickstartDrinks.
*/
class CommerceKickstartDrinks extends CommerceKickstartMigration {
public function __construct() {
parent::__construct();
/**
* {@inheritdoc}
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import drinks from CSV file.');
// Create a map object for tracking the relationships between source rows
// Create a map object for tracking the relationships between source rows.
$this->map = new MigrateSQLMap($this->machineName,
array(
'sku' => array(
......@@ -105,14 +133,14 @@ class CommerceKickstartDrinks extends CommerceKickstartMigration {
$this->addFieldMapping('sku', 'sku');
$this->addFieldMapping('commerce_price', 'price');
// Images
// Images.
$this->addFieldMapping('field_images', 'product_images');
$this->addFieldMapping('field_images:file_replace')
->defaultValue(FILE_EXISTS_REPLACE);
$this->addFieldMapping('field_images:source_dir')
->defaultValue(drupal_get_path('module', 'commerce_kickstart_product') . '/import/images');
// Color
// Color.
$this->addFieldMapping('field_color', 'color');
$this->addFieldMapping('field_color:additional_field', 'hexadecimal');
$this->addFieldMapping('field_color:create_term')
......@@ -122,7 +150,13 @@ class CommerceKickstartDrinks extends CommerceKickstartMigration {
$this->addFieldMapping('language', 'language');
}
function csvcolumns() {
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
public function csvcolumns() {
// "Title","SKU","Color","Price","Images"
$columns[0] = array('title', 'Title');
$columns[1] = array('sku', 'SKU');
......@@ -133,26 +167,42 @@ class CommerceKickstartDrinks extends CommerceKickstartMigration {
return $columns;
}
function fields() {
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
public function fields() {
return array(
'product_images' => 'An array of images, populated during prepareRow().',
);
}
function prepareRow($row) {
/**
* {@inheritdoc}
*/
public function prepareRow($row) {
$row->product_images = explode(', ', $row->images);
$row->uid = 1;
$row->language = LANGUAGE_NONE;
}
}
/**
* Class CommerceKickstartHats.
*/
class CommerceKickstartHats extends CommerceKickstartMigration {
public function __construct() {
parent::__construct();
/**
* {@inheritdoc}
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import hats from CSV file.');
// Create a map object for tracking the relationships between source rows
// Create a map object for tracking the relationships between source rows.
$this->map = new MigrateSQLMap($this->machineName,
array(
'sku' => array(
......@@ -173,19 +223,19 @@ class CommerceKickstartHats extends CommerceKickstartMigration {
$this->addFieldMapping('sku', 'sku');
$this->addFieldMapping('commerce_price', 'price');
// Images
// Images.
$this->addFieldMapping('field_images', 'product_images');
$this->addFieldMapping('field_images:file_replace')
->defaultValue(FILE_EXISTS_REPLACE);
$this->addFieldMapping('field_images:source_dir')
->defaultValue(drupal_get_path('module', 'commerce_kickstart_product') . '/import/images');
// Size
// Size.
$this->addFieldMapping('field_hat_size', 'size');
$this->addFieldMapping('field_hat_size:create_term')
->defaultValue(TRUE);
// Color
// Color.
$this->addFieldMapping('field_color', 'color');
$this->addFieldMapping('field_color:additional_field', 'hexadecimal');
$this->addFieldMapping('field_color:create_term')
......@@ -195,7 +245,13 @@ class CommerceKickstartHats extends CommerceKickstartMigration {
$this->addFieldMapping('language', 'language');
}
function csvcolumns() {
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
public function csvcolumns() {
// "title","SKU","Color","Size","Price","Images"
$columns[0] = array('title', 'Title');
$columns[1] = array('sku', 'SKU');
......@@ -207,26 +263,42 @@ class CommerceKickstartHats extends CommerceKickstartMigration {
return $columns;
}
function fields() {
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
public function fields() {
return array(
'product_images' => 'An array of images, populated during prepareRow().',
);
}
function prepareRow($row) {
/**
* {@inheritdoc}
*/
public function prepareRow($row) {
$row->product_images = explode(', ', $row->images);
$row->uid = 1;
$row->language = LANGUAGE_NONE;
}
}
/**
* Class CommerceKickstartTops.
*/
class CommerceKickstartTops extends CommerceKickstartMigration {
public function __construct() {
parent::__construct();
/**
* {@inheritdoc}
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import tops from CSV file.');
// Create a map object for tracking the relationships between source rows
// Create a map object for tracking the relationships between source rows.
$this->map = new MigrateSQLMap($this->machineName,
array(
'sku' => array(
......@@ -247,19 +319,19 @@ class CommerceKickstartTops extends CommerceKickstartMigration {
$this->addFieldMapping('sku', 'sku');
$this->addFieldMapping('commerce_price', 'price');
// images
// Images.
$this->addFieldMapping('field_images', 'product_images');
$this->addFieldMapping('field_images:file_replace')
->defaultValue(FILE_EXISTS_REPLACE);
$this->addFieldMapping('field_images:source_dir')
->defaultValue(drupal_get_path('module', 'commerce_kickstart_product') . '/import/images');
// Size
// Size.
$this->addFieldMapping('field_top_size', 'size');
$this->addFieldMapping('field_top_size:create_term')
->defaultValue(TRUE);
// Color
// Color.
$this->addFieldMapping('field_color', 'color');
$this->addFieldMapping('field_color:additional_field', 'hexadecimal');
$this->addFieldMapping('field_color:create_term')
......@@ -269,7 +341,13 @@ class CommerceKickstartTops extends CommerceKickstartMigration {
$this->addFieldMapping('language', 'language');
}
function csvcolumns() {
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
public function csvcolumns() {
// "Title","SKU","Color","Size","Price","Images"
$columns[0] = array('title', 'Title');
$columns[1] = array('sku', 'SKU');
......@@ -281,26 +359,42 @@ class CommerceKickstartTops extends CommerceKickstartMigration {
return $columns;
}
function fields() {
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
public function fields() {
return array(
'product_images' => 'An array of images, populated during prepareRow().',
);
}
function prepareRow($row) {
/**
* {@inheritdoc}
*/
public function prepareRow($row) {
$row->product_images = explode(', ', $row->images);
$row->uid = 1;
$row->language = LANGUAGE_NONE;
}
}
/**
* Class CommerceKickstartShoes.
*/
class CommerceKickstartShoes extends CommerceKickstartMigration {
public function __construct() {
parent::__construct();
/**
* {@inheritdoc}
*/
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import shoes from CSV file.');
// Create a map object for tracking the relationships between source rows
// Create a map object for tracking the relationships between source rows.
$this->map = new MigrateSQLMap($this->machineName,
array(
'sku' => array(
......@@ -321,19 +415,19 @@ class CommerceKickstartShoes extends CommerceKickstartMigration {
$this->addFieldMapping('sku', 'sku');
$this->addFieldMapping('commerce_price', 'price');
// Images
// Images.
$this->addFieldMapping('field_images', 'product_images');
$this->addFieldMapping('field_images:file_replace')
->defaultValue(FILE_EXISTS_REPLACE);
$this->addFieldMapping('field_images:source_dir')
->defaultValue(drupal_get_path('module', 'commerce_kickstart_product') . '/import/images');
// Size
// Size.
$this->addFieldMapping('field_shoe_size', 'size');
$this->addFieldMapping('field_shoe_size:create_term')
->defaultValue(TRUE);
// Color
// Color.
$this->addFieldMapping('field_color', 'color');
$this->addFieldMapping('field_color:additional_field', 'hexadecimal');
$this->addFieldMapping('field_color:create_term')
......@@ -343,7 +437,13 @@ class CommerceKickstartShoes extends CommerceKickstartMigration {
$this->addFieldMapping('language', 'language');
}
function csvcolumns() {
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
public function csvcolumns() {
// "Title","SKU","Color","Size","Price","Images"
$columns[0] = array('title', 'Title');
$columns[1] = array('sku', 'SKU');
......@@ -355,26 +455,42 @@ class CommerceKickstartShoes extends CommerceKickstartMigration {
return $columns;
}
function fields() {
/**
* Maps CSV column headers.
*
* @return array
* Array of mappings
*/
public function fields() {
return array(
'product_images' => 'An array of images, populated during prepareRow().',