I have 2 migrate classes - ProductsNewMigrate
and ProductsUpdateMigrate
.
1) ProductsNewMigrate
runs initially, adding products from a CSV file into Drupal. I can confirm this works correctly, the new products are created and a migrate map is set up in the database.
2) ProductsUpdateMigrate
is required to import another CSV (exactly the same structure as in 1.) but with the updated product data originally migrated via ProductsNewMigrate
.
I just can't get the Update migrate to work.
I receive the error:
array_flip(): Can only flip STRING and INTEGER values
When looking at the migrate map table for this Migration - migrate_map_productsupdate
..
I notice sourceid1
is set to the SKU - which is correct. However, destid1
and destid2
(product_id and product_revision respectively) are both null values - which could be causing this?
Edit: Also receive the warning message: "product_id" was used as destination field in "sku" mapping but is not in list of destination fields
when viewing the migrate page!
See the code below:
Code:
class ProductsUpdateMigration extends CustomMigration {
public function __construct() {
parent::__construct();
$this->description = t('Import new products from CSV');
$csvfile = "/drupal/products_updated.csv";
$columns = array(
0 => array('sku', 'Product SKU'),
1 => array('title', 'Product title'),
2 => array('colour_specific', 'Product colour specific'),
3 => array('price_group', 'Price Group'),
4 => array('composition', 'Product Composition'),
5 => array('width', 'Width'),
8 => array('price', 'Product Price'),
);
$this->map = new MigrateSQLMap($this->machineName,
array(
'sku' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'SKU/newref',
'alias' => 'p',
)
),
MigrateDestinationEntityAPI::getKeySchema('commerce_product')
);
$this->source = new MigrateSourceCSV($csvfile, $columns, array('header_rows' => 1));
$this->destination = new MigrateDestinationEntityAPI('commerce_product', 'blinds');
$this->systemOfRecord = Migration::DESTINATION;
// print_r($this);
// Mapped fields
$this->addFieldMapping('product_id', 'sku')
->sourceMigration('ProductsNew');
$this->addFieldMapping('title', 'title');
$this->addFieldMapping('commerce_stock')
->defaultValue(5);
$this->addFieldMapping('field_blinds_colour_specific', 'colour_specific');
$this->addFieldMapping('field_blinds_composition', 'composition');
$this->addFieldMapping('field_blinds_width', 'width');
$this->addFieldMapping('commerce_price', 'price');
$this->addFieldMapping('field_blinds_price_group', 'price_group');
$this->addFieldMapping('type')
->defaultValue('blinds');
}
public function prepareRow($current_row) {
$colours = explode(';', $current_row->colour_specific);
// // print '<pre>';
// // print_r($colours);
// // print '</pre>';
$current_row->colour_specific = $colours;
// $current_row->migrate_map_destid1 = 62;
// $current_row->migrate_map_destid2 = 67;
print_r($current_row);
return TRUE;
}
public function prepare($entity, stdClass $row) {
}
}