commerce_export-8.x-1.0-alpha1/config/install/migrate_plus.migration.import_product_variation.yml
config/install/migrate_plus.migration.import_product_variation.yml
# Import a product variation with up to 4 attribute values and 3 images.
#
# If any of the attributes or images do not exist in the source, processing
# for tha item is skipped, the remaining data is still imported.
#
# To modify
#
# Destination site configuration:
# - Same requirements a the import_image migration.
# - Same requirements a the import_attribute_value migration.
# - Install the Paragraph Module.
# - Create a product variation type with
# - Up to 4 attirbutes
# - An image field, field_product_image
# - An image field, field_product_image_2
# - An image field, field_product_image_3
#
id: import_product_variation
label: Product variations
migration_group: commerce_export
source:
plugin: product_variation_csv
path: 'public://import/product.csv'
header_row_count: 1
enclosure: '"'
keys:
- sku
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:
video2: 'video 2'
29:
video3: 'video 3'
process:
variation_id:
plugin: skip_on_empty
source: sku
method: row
sku: sku
title: title
# The currency code defaults to 'CAD'. If your data has only 1 currency code, then simply change the default value
# to that currency code. If multiple currencies are used, this will need to be changed to the name given to that
# that column of the input CSV.
currency_code:
plugin: default_value
default_value: CAD
price:
plugin: get_price
source:
- sell_price
- '@currency_code'
# The product variation type default to 'default'. For each product variation type, make a new migration and
# change the default value to the desired machine name.
type:
plugin: default_value
default_value: default
# Attributes are single valued entity reference fields migrated in name/id pairs. The attribute name must be a machine
# name of a certain formet.
attribute1_name:
plugin: machine_name
source: attribute_name1
attribute1_id:
plugin: migration_lookup
migration: import_attribute_value
source:
- '@attribute1_name'
- attribute_value1
attribute2_name:
plugin: machine_name
source: attribute_name2
attribute2_id:
plugin: migration_lookup
migration: import_attribute_value
source:
- '@attribute2_name'
- attribute_value2
attribute3_name:
plugin: machine_name
source: attribute_name3
attribute3_id:
plugin: migration_lookup
migration: import_attribute_value
source:
- '@attribute3_name'
- attribute_value3
attribute4_name:
plugin: machine_name
source: attribute_name4
attribute4_id:
plugin: migration_lookup
migration: import_attribute_value
source:
- '@attribute4_name'
- attribute_value4
attribute_destination:
plugin: attribute_destination
source:
- '@attribute1_name'
- '@attribute1_id'
- '@attribute2_name'
- '@attribute2_id'
- '@attribute3_name'
- '@attribute3_id'
- '@attribute4_name'
- '@attribute4_id'
# For each image field the processing for that image is skipped if there
# is no input and the rest of the row will continue to be processes.
# Image field, single value.
field_product_image:
-
plugin: skip_on_empty
source: image1
method: process
-
plugin: product_variation_file
source:
- sku
- image1
# Image field, single value.
field_product_image_2:
-
plugin: skip_on_empty
source: image2
method: process
-
plugin: product_variation_file
source:
- sku
- image2
# Image field, single value.
field_product_image_3:
-
plugin: skip_on_empty
source: image3
method: process
-
plugin: product_variation_file
source:
- sku
- image3
destination:
plugin: 'entity:commerce_product_variation'
migration_dependencies:
required:
- import_image
- import_attribute_value
