Fixed commerce product reference field handler for Migrate

Public

Current MigrateCommerceProductReferenceFieldHandler provided by commerce_migrate.module doesn't support multiple references, this custom handler class fixes this problem.

</> CopyGet raw version
php
  1. class CustomMigrateCommerceProductReferenceFieldHandler extends MigrateFieldHandler {
  2. public function __construct() {
  3. $this->registerTypes(array('commerce_product_reference'));
  4. }
  5. public function prepare($entity, array $field_info, array $instance, array $values) {
  6. $migration = Migration::currentMigration();
  7. $arguments = (isset($values['arguments']))? $values['arguments']: array();
  8. $language = $this->getFieldLanguage($entity, $field_info, $arguments);
  9. // Setup the standard Field API array for saving.
  10. $delta = 0;
  11. if(!is_array(reset($values))) {
  12. $values = array($values);
  13. }
  14. foreach (array_filter($values) as $value) {
  15. $return[$language][$delta]['product_id'] = reset($value);
  16. $delta++;
  17. }
  18. if (!isset($return)) {
  19. $return = NULL;
  20. }
  21. return $return;
  22. }
  23. }