commerce_export-8.x-1.0-alpha1/config/install/migrate_plus.migration.import_product.yml

config/install/migrate_plus.migration.import_product.yml
# Import a product.
#
# Import a product with up to 2 taxonomy vocabularies, and single valued and
# multi valued entity reference fields. The product type is 'default'.
#
# If any of the field values do not exist in the source, processing for that
# item is skipped, the remaining data is still imported.
#
# To modify
#
# Destination site configuration:
#   - Same requirements as the taxonomy_term migration.
#   - Same requirements as the paragraph_tab migration.
#   - Same requirements as the import_video migration.
#   - Same requirements as the import_product_variation migration.
#   - Install the Paragraph Module.
#
id: import_product
label: Products
migration_group: commerce_export
source:
  # Uses a custom source plugin, based on the CSV source plugin in migrate_source_csv, that will build an array of
  # product variation ids as well as trim the input from the source CSV.
  plugin: product_csv
  # Change the path and filename to match your source CSV file.
  path: 'public://import/product.csv'
  # Change the number of header rows to suit your source CVS file.
  header_row_count: 1
  # Change the enclosure character to suit your source CVS file.
  enclosure: '"'
  # The key field for this migration. List many column names as needed to create a unique key for your migration.
  # These keys are also used whan a migration_lookup process is needed with this migration.
  keys:
    - title
  # Define some constants for use in the process pipeline.
  constants:
    video_embed_prefix: '<iframe width="560" height="315" src="'
    video_embed_suffix: ' frameborder="0" allowfullscreen></iframe>'
  # Gives each column a field name for use in the process pipeline and a label.
  # This is a complete list of columns in the example spreadsheet. Each
  # migration only needs to define the columns that it will use.
  column_names:
    0:
      title: Title
    1:
      sku: SKU
    2:
      status: Status
    3:
      product_type: 'Product type'
    4:
      description: Description
    5:
      product_variation_type: 'Product variation type'
    6:
      sell_price: 'Sell price'
    7:
      vocabulary_name1: 'Vocabulary1'
    8:
      term1: 'Vocabulary value1'
    9:
      vocabulary_name2: 'Vocabulary2'
    10:
      term2: 'Vocabulary value2'
    11:
      vocabulary_name3: 'Vocabulary3'
    12:
      term3: 'Vocabulary value3'
    13:
      attribute_name1: 'Attribute name1'
    14:
      attribute_value1: 'Attribute value1'
    15:
      attribute_name2: 'Attribute name2'
    16:
      attribute_value2: 'Attribute value2'
    17:
      attribute_name3: 'Attribute name3'
    18:
      attribute_value3: 'Attribute value3'
    19:
      attribute_name4: 'Attribute name4'
    20:
      attribute_value4: 'Attribute value4'
    21:
      related1: 'SKU of Related item 1'
    22:
      related2: 'SKU of Related item 2'
    23:
      related3: 'SKU of Related item 3'
    24:
      image1: 'Image 1'
    25:
      image2: 'Image 2'
    26:
      image3: 'Image 3'
    27:
      video1: 'Video 1'
    28:
      thumbnail1: 'Thumbnail 1'
    29:
      video2: 'Video 2'
    30:
      thumbnail2: 'Thumbnail 2'
    31:
      video3: 'Video 3'
    32:
      thumbnail3: 'Thumbnail 3'
    33:
      tab_title1: 'Tab title 1'
    34:
      tab_content1: 'Tab content 1'
    35:
      tab_cta1: 'Associated tab CTA 1'
    36:
      tab_title2: 'Tab title 2'
    37:
      tab_content2: 'Tab content 2'
    38:
      tab_cta2: 'Associated tab CTA 2'
    39:
      cta_title1: 'CTA title 1'
    40:
      cta_link1: 'CTA link 1'
    41:
      cta_image1: 'CTA product image 1'
    42:
      cta_title2: 'CTA title 2'
    43:
      cta_link2: 'CTA link 2'
    44:
      cta_image2: 'CTA product image 2'
process:
  # Product type set to 'default'.
  type:
    plugin: default_value
    default_value: default
  # UID set to 1.
  uid:
    plugin: default_value
    default_value: 1
  # Use the title provided in the CSV as the title.
  title: title
  # Use the description provided in the CSV as the value for the body field.
  body/value: description
  # Use status provided in the CSV as the status for this product.
  status: status
  # Use store 1 as the default store.
  stores/target_id:
    plugin: default_value
    default_value: 1
  # Taxonomy vocabulary 'Category'.
  # Entity reference field, multi-valued.
  field_category:
    -
      plugin: skip_on_empty
      source: term1
      method: process
    -
      plugin: migration_lookup
      migration: import_taxonomy_term
      source:
        - vocabulary_name1
        - term1
  # Taxonomy vocabulary 'Season'.
  # Entity reference field, multi-valued.
  field_season:
    -
      plugin: skip_on_empty
      source: term2
      method: process
    -
      plugin: migration_lookup
      migration: import_taxonomy_term
      source:
        - vocabulary_name2
        - term2
  # Use a custom process plugin to get all the variations for this product.
  variations:
    plugin: migration_lookup
    migration: import_product_variation
    source: variation_sku
  # A list of suggested products is created in two steps. First, get the three possible related items from the source
  # and use a custom process plugin to build an array of related producs, excluding any empty values.
  suggested_product:
    plugin: suggested_products
    source:
      - related1
      - related2
      - related3
  # Second, use the array created above to populate the suggested products field. The sub_process plugin will execute
  # the migration_lookup for each value in the array.
  # Entity reference field, unlimited values.
  field_suggested_products:
    plugin: sub_process
    source: '@suggested_product'
    process:
      target_id:
        plugin: migration_lookup
        migration: import_product
        source: '0'
  # The video field is a single valued entity reference revision field. It requires a target_id and revision_id. These
  # are obtained by using the migration_lookup process plugin with the input being the title of the video to migrate.
  # The output from migration_lookup will be the destination id for that migration, in this case, the target_id and the
  # target_revision_id. These can be extracted from the array and put in the correct field value. And, of course, skip
  # the processing of the video if the video was not migrated.
  field_product_video/target_id:
    -
      plugin: migration_lookup
      migration: import_paragraph_product_video
      no_stub: true
      source:
        - title
    -
      plugin: skip_on_empty
      method: process
    -
      plugin: extract
      index:
        - '0'
  # See comment above for 'field_product_video/target_id:'
  field_product_video/target_revision_id:
    -
      plugin: migration_lookup
      migration: import_paragraph_product_video
      no_stub: true
      source:
        - title
    -
      plugin: skip_on_empty
      method: process
    -
      plugin: extract
      index:
        - '1'
  combination_tab:
    plugin: get
    source:
      - tab_title1
      - tab_title2
  # Paragraph field.
  field_tab:
    -
      plugin: migration_lookup
      migration: import_paragraph_tab
      no_stub: true
      source: '@combination_tab'
    -
      plugin: skip_on_empty
      method: process
    -
      plugin: sub_process
      process:
        target_id: '0'
        target_revision_id: '1'
  combination_cta:
    plugin: get
    source:
      - cta_title1
      - cta_title2
  # Paragraph field.
  # Entity reference revisions, Single value
  field_desc_cta:
    -
      plugin: migration_lookup
      migration: import_paragraph_cta
      no_stub: true
      source: '@combination_cta'
    -
      plugin: skip_on_empty
      method: process
    -
      plugin: sub_process
      process:
        target_id: '0'
        target_revision_id: '1'
destination:
  plugin: 'entity:commerce_product'
migration_dependencies:
  required:
    - import_taxonomy_term
    - import_paragraph_tab
    - import_video
    - import_product_variation

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc