You are here

csv_example_product.yml in Commerce Migrate 3.1.x

modules/csv_example/migrations/csv_example_product.yml

File

modules/csv_example/migrations/csv_example_product.yml
View source
  1. # Import a product.
  2. #
  3. # Import a product with up to 2 taxonomy vocabularies, and single valued and
  4. # multi valued entity reference fields. The product type is 'default'.
  5. #
  6. # If any of the field values do not exist in the source, processing for that
  7. # item is skipped, the remaining data is still imported.
  8. #
  9. # To modify
  10. #
  11. # Destination site configuration:
  12. # - Same requirements as the taxonomy_term migration.
  13. # - Same requirements as the paragraph_tab migration.
  14. # - Same requirements as the csv_video migration.
  15. # - Same requirements as the csv_product_variation migration.
  16. # - Install the Paragraph Module.
  17. #
  18. id: csv_example_product
  19. label: Products
  20. migration_group: commerce_migrate_csv_example
  21. migration_tags:
  22. - Commerce CSV
  23. - Content
  24. source:
  25. # Uses a custom source plugin, based on the CSV source plugin in
  26. # migrate_source_csv, that will build an array of product variation ids as
  27. # well as trim the input from the source CSV.
  28. plugin: csv_example_product
  29. # Change the path and filename to match your source CSV file.
  30. path: 'public://import/example-products.csv'
  31. # Change the enclosure character to suit your source CVS file.
  32. enclosure: "\""
  33. # Change the number of header rows to suit your source CVS file.
  34. header_offset: 0
  35. # The key field for this migration. List many column names as needed to create
  36. # a unique key for your migration. These keys are also used when a
  37. # migration_lookup process is needed with this migration.
  38. ids: [title]
  39. # Define some constants for use in the process pipeline.
  40. constants:
  41. video_embed_prefix: '<iframe width="560" height="315" src="'
  42. video_embed_suffix: ' frameborder="0" allowfullscreen></iframe>'
  43. # Gives each column a field name for use in the process pipeline and a label.
  44. # This is a complete list of columns in the example spreadsheet. Each
  45. # migration only needs to define the columns that it will use.
  46. fields:
  47. - name: title
  48. label: Title
  49. - name: sku
  50. label: SKU
  51. - name: status
  52. label: Status
  53. - name: product_type
  54. label: Product type
  55. - name: description
  56. label: Description
  57. - name: product_variation_type
  58. label: Product variation type
  59. - name: sell_price
  60. label: Sell price
  61. - name: vocabulary_name1
  62. label: Vocabulary1
  63. - name: term1
  64. label: Vocabulary value1
  65. - name: vocabulary_name2
  66. label: Vocabulary2
  67. - name: term2
  68. label: Vocabulary value2
  69. - name: vocabulary_name3
  70. label: Vocabulary3
  71. - name: term3
  72. label: Vocabulary value3
  73. - name: attribute_name1
  74. label: Attribute name1
  75. - name: attribute_value1
  76. label: Attribute value1
  77. - name: attribute_name2
  78. label: Attribute name2
  79. - name: attribute_value2
  80. label: Attribute value2
  81. - name: attribute_name3
  82. label: Attribute name3
  83. - name: attribute_value3
  84. label: Attribute value3
  85. - name: attribute_name4
  86. label: Attribute name4
  87. - name: attribute_value4
  88. label: Attribute value4
  89. - name: related1
  90. label: SKU of Related item 1
  91. - name: related2
  92. label: SKU of Related item 2
  93. - name: related3
  94. label: SKU of Related item 3
  95. - name: image1
  96. label: Image 1
  97. - name: image2
  98. label: Image 2
  99. - name: image3
  100. label: Image 3
  101. - name: video1
  102. label: Video 1
  103. - name: thumbnail1
  104. label: Thumbnail 1
  105. - name: video2
  106. label: Video 2
  107. - name: thumbnail2
  108. label: Thumbnail 2
  109. - name: video3
  110. label: Video 3
  111. - name: thumbnail3
  112. label: Thumbnail 3
  113. - name: tab_title1
  114. label: Tab title 1
  115. - name: tab_content1
  116. label: Tab content 1
  117. - name: tab_cta1
  118. label: Associated tab CTA 1
  119. - name: tab_title2
  120. label: Tab title 2
  121. - name: tab_content2
  122. label: Tab content 2
  123. - name: tab_cta2
  124. label: Associated tab CTA 2
  125. - name: cta_title1
  126. label: CTA title 1
  127. - name: cta_link1
  128. label: CTA link 1
  129. - name: cta_image1
  130. label: CTA product image 1
  131. - name: cta_title2
  132. label: CTA title 2
  133. - name: cta_link2
  134. label: CTA link 2
  135. - name: cta_image2
  136. label: CTA product image 2
  137. process:
  138. # Product type set to 'default'.
  139. type:
  140. plugin: default_value
  141. default_value: default
  142. # UID set to 1.
  143. uid:
  144. plugin: default_value
  145. default_value: 1
  146. # Use the title provided in the CSV as the title.
  147. title: title
  148. # Use the description provided in the CSV as the value for the body field.
  149. body/value: description
  150. # Use status provided in the CSV as the status for this product.
  151. status: status
  152. # Use store 1 as the default store.
  153. stores/target_id:
  154. plugin: default_value
  155. default_value: 1
  156. # Taxonomy vocabulary 'Category'.
  157. # Entity reference field, multi-valued.
  158. field_category:
  159. -
  160. plugin: skip_on_empty
  161. source: term1
  162. method: process
  163. -
  164. plugin: migration_lookup
  165. migration: csv_example_taxonomy_term
  166. source:
  167. - vocabulary_name1
  168. - term1
  169. # Taxonomy vocabulary 'Season'.
  170. # Entity reference field, multi-valued.
  171. field_season:
  172. -
  173. plugin: skip_on_empty
  174. source: term2
  175. method: process
  176. -
  177. plugin: migration_lookup
  178. migration: csv_example_taxonomy_term
  179. source:
  180. - vocabulary_name2
  181. - term2
  182. # Use a custom process plugin to get all the variations for this product.
  183. variations:
  184. plugin: migration_lookup
  185. migration: csv_example_product_variation
  186. source: variation_sku
  187. # A list of suggested products is created in two steps. First, get the three possible related items from the source
  188. # and use a custom process plugin to build an array of related producs, excluding any empty values.
  189. suggested_product:
  190. plugin: csv_example_suggested_products
  191. source:
  192. - related1
  193. - related2
  194. - related3
  195. # Second, use the array created above to populate the suggested products field. The sub_process plugin will execute
  196. # the migration_lookup for each value in the array.
  197. # Entity reference field, unlimited values.
  198. field_suggested_products:
  199. plugin: sub_process
  200. source: '@suggested_product'
  201. process:
  202. target_id:
  203. plugin: migration_lookup
  204. migration: csv_example_product
  205. source: '0'
  206. # The video field is a single valued entity reference revision field. It requires a target_id and revision_id. These
  207. # are obtained by using the migration_lookup process plugin with the input being the title of the video to migrate.
  208. # The output from migration_lookup will be the destination id for that migration, in this case, the target_id and the
  209. # target_revision_id. These can be extracted from the array and put in the correct field value. And, of course, skip
  210. # the processing of the video if the video was not migrated.
  211. field_product_video/target_id:
  212. -
  213. plugin: migration_lookup
  214. migration: csv_example_paragraph_product_video
  215. no_stub: true
  216. source:
  217. - title
  218. -
  219. plugin: skip_on_empty
  220. method: process
  221. -
  222. plugin: extract
  223. index:
  224. - '0'
  225. # See comment above for 'field_product_video/target_id:'
  226. field_product_video/target_revision_id:
  227. -
  228. plugin: migration_lookup
  229. migration: csv_example_paragraph_product_video
  230. no_stub: true
  231. source:
  232. - title
  233. -
  234. plugin: skip_on_empty
  235. method: process
  236. -
  237. plugin: extract
  238. index:
  239. - '1'
  240. combination_tab:
  241. plugin: get
  242. source:
  243. - tab_title1
  244. - tab_title2
  245. # Paragraph field.
  246. field_tab:
  247. -
  248. plugin: migration_lookup
  249. migration: csv_example_paragraph_tab
  250. no_stub: true
  251. source: '@combination_tab'
  252. -
  253. plugin: skip_on_empty
  254. method: process
  255. -
  256. plugin: sub_process
  257. process:
  258. target_id: '0'
  259. target_revision_id: '1'
  260. combination_cta:
  261. plugin: get
  262. source:
  263. - cta_title1
  264. - cta_title2
  265. # Paragraph field.
  266. # Entity reference revisions, Single value
  267. field_desc_cta:
  268. -
  269. plugin: migration_lookup
  270. migration: csv_example_paragraph_cta
  271. no_stub: true
  272. source: '@combination_cta'
  273. -
  274. plugin: skip_on_empty
  275. method: process
  276. -
  277. plugin: sub_process
  278. process:
  279. target_id: '0'
  280. target_revision_id: '1'
  281. destination:
  282. plugin: 'entity:commerce_product'
  283. migration_dependencies:
  284. required:
  285. - csv_example_taxonomy_term
  286. - csv_example_paragraph_with_paragraph_reference
  287. - csv_example_video
  288. - csv_example_product_variation