You are here

function _commerce_migrate_commerce_get_attributes in Commerce Migrate 3.0.x

Same name and namespace in other branches
  1. 8.2 modules/commerce/commerce_migrate_commerce.module \_commerce_migrate_commerce_get_attributes()
  2. 3.1.x modules/commerce/commerce_migrate_commerce.module \_commerce_migrate_commerce_get_attributes()

Get the fields that are commerce product attributes.

Commerce 1 product attributes use taxonomy term reference fields with select options.

Return value

array An array of taxonomy vocabularies that are product attributes..

See also

https://drupalcommerce.org/user-guide/product-attributes-variations

1 call to _commerce_migrate_commerce_get_attributes()
commerce_migrate_commerce_migration_plugins_alter in modules/commerce/commerce_migrate_commerce.module
Implements hook_migration_plugins_alter().

File

modules/commerce/commerce_migrate_commerce.module, line 309
Contains commerce_migrate_commerce.module.

Code

function _commerce_migrate_commerce_get_attributes() {
  $source_plugin = MigrationDeriverTrait::getSourcePlugin('d7_field_instance');
  $attributes = [];
  foreach ($source_plugin as $row) {
    if ($row
      ->getSourceProperty('entity_type') == 'commerce_product' && $row
      ->getSourceProperty('type') == 'taxonomy_term_reference' && $row
      ->getSourceProperty('widget')['type'] == 'options_select') {

      // Get all bundles for this field.
      $field_definition = $row
        ->getSourceProperty('field_definition');
      $data = unserialize($field_definition['data']);
      foreach ($data['settings']['allowed_values'] as $allowed_value) {
        $attributes[] = $allowed_value['vocabulary'];
      }
    }
  }
  return array_unique($attributes);
}