public function MigrateDestinationCommerceProductType::import in Commerce Migrate 7
Import a single product type.
Parameters
stdClass $product_type: Generic object, refilled with any fields mapped in the Migration.
stdClass $row: Raw source data object - passed through to prepare/complete handlers.
Return value
array|bool Array of product type machine names if successful. FALSE on failure.
Throws
Overrides MigrateDestination::import
File
- plugins/
destinations/ commerce_product_type.inc, line 73 - Support for commerce product types.
Class
- MigrateDestinationCommerceProductType
- Destination class implementing migration into commerce product types.
Code
public function import(stdClass $product_type, stdClass $row) {
$migration = Migration::currentMigration();
// Updating previously-migrated content?
if (isset($row->migrate_map_destid1)) {
if (isset($product_type->type)) {
if ($product_type->type != $row->migrate_map_destid1) {
throw new MigrateException(t("Incoming id !id and map destination id !destid1 don't match", array(
'!id' => $product_type->type,
'!destid1' => $row->migrate_map_destid1,
)));
}
}
else {
$product_type->type = $row->migrate_map_destid1;
}
}
if ($migration
->getSystemOfRecord() == Migration::DESTINATION) {
if (!isset($product_type->type)) {
throw new MigrateException(t('System-of-record is DESTINATION, but no destination id provided'));
}
// Load the type that's being updated, update its values, then
// substitute the passed in type with that one.
$old_product_type = commerce_product_type_load($product_type->type);
foreach ($product_type as $field => $value) {
$old_product_type->{$field} = $product_type->{$field};
}
$product_type = $old_product_type;
}
$this
->prepare($product_type, $row);
migrate_instrument_start('commerce_product_type_save');
// Convert the object to an array and initialize default values.
$product_type_array = (array) $product_type;
$product_type_array += commerce_product_ui_product_type_new();
// Skip reset (3rd argument) to avoid menu rebuild.
$status = commerce_product_ui_product_type_save($product_type_array, TRUE, TRUE);
// Allow other modules the opportunity to add to the product type.
module_invoke_all('commerce_migrate_ubercart_product_type_created', $product_type);
migrate_instrument_stop('commerce_product_type_save');
$this
->complete($product_type, $row);
$return = $status ? array(
$product_type->type,
) : FALSE;
return $return;
}