1 ---
2 products:
3 - product
4 ---
5
6 import { Card, Prerequisites, WorkflowDiagram } from "docs-ui"
7 import { Github } from "@medusajs/icons"
8
9 export const metadata = {
10 title: `How to Build Magento Data Migration Plugin`,
11 }
12
13 # {metadata.title}
14
15 In this tutorial, you'll learn how to build a [plugin](!docs!/learn/fundamentals/plugins) that migrates data, such as products, from Magento to Medusa.
16
17 <Note>
18
19 This guide has been revisited to support [Medusa v2.16.0](https://github.com/medusajs/medusa/releases/tag/v2.16.0) which introduced global product options.
20
21 </Note>
22
23 Magento is known for its customization capabilities. However, its monolithic architecture imposes limitations on business requirements, often forcing development teams to implement hacky workarounds. Over time, these customizations become challenging to maintain, especially as the business scales, leading to increased technical debt and slower feature delivery.
24
25 Medusa's modular architecture allows you to build a custom digital commerce platform that meets your business requirements without the limitations of a monolithic system. By migrating from Magento to Medusa, you can take advantage of Medusa's modern technology stack to build a scalable and flexible commerce platform that grows with your business.
26
27 By following this tutorial, you'll create a Medusa plugin that migrates data from a Magento server to a Medusa application in minimal time. You can re-use this plugin across multiple Medusa applications, allowing you to adopt Medusa across your projects.
28
29 ## Summary
30
31 <Prerequisites
32 items={[
33 {
34 text: "Magento 2.x with admin credentials.",
35 }
36 ]}
37 />
38
39 This tutorial will teach you how to:
40
41 - Install and set up a Medusa application project.
42 - Install and set up a Medusa plugin.
43 - Implement a Magento Module in the plugin to connect to Magento's APIs and retrieve products.
44 - This guide will only focus on migrating product data from Magento to Medusa. You can extend the implementation to migrate other data, such as customers, orders, and more.
45 - Trigger data migration from Magento to Medusa in a scheduled job.
46
47 You can follow this tutorial whether you're new to Medusa or an advanced Medusa developer.
48
49 ![Diagram showcasing the flow of migrating data from Magento to Medusa](https://res.cloudinary.com/dza7lstvk/image/upload/v1739360550/Medusa%20Resources/magento-summary_hsewci.jpg)
50
51 <Card
52 title="Example Repository"
53 text="Find the full code of the guide in this repository. The repository also includes additional features, such as triggering migrations from the Medusa Admin dashboard."
54 href="https://github.com/medusajs/examples/tree/main/migrate-from-magento"
55 icon={Github}
56 />
57
58 ---
59
60 ## Step 1: Install a Medusa Application
61
62 You'll first install a Medusa application that exposes core commerce features through REST APIs. You'll later install the Magento plugin in this application to test it out.
63
64 <Prerequisites items={[
65 {
66 text: "Node.js v20.19.0+ or v22.12.0+",
67 link: "https://nodejs.org/en/download"
68 },
69 {
70 text: "Git CLI tool",
71 link: "https://git-scm.com/downloads"
72 },
73 {
74 text: "PostgreSQL",
75 link: "https://www.postgresql.org/download/"
76 }
77 ]} />
78
79 Start by installing the Medusa application on your machine with the following command:
80
81 ```bash
82 npx create-medusa-app@latest
83 ```
84
85 You'll be asked for the project's name. You can also optionally choose to install the [Next.js Starter Storefront](../../../nextjs-starter/page.mdx).
86
87 Afterward, the installation process will start, which will install the Medusa application as a monorepository in a directory with your project's name. The backend is installed in the `apps/backend` directory. If you chose to install the Next.js Starter Storefront, it'll be in the `apps/storefront` directory.
88
89 Once the installation finishes successfully, the Medusa Admin dashboard will open with a form to create a new user. Enter the user's credentials and submit the form. Afterward, you can log in with the new user and explore the dashboard.
90
91 <Note title="Ran into Errors?">
92
93 Check out the [troubleshooting guides](../../../troubleshooting/create-medusa-app-errors/page.mdx) for help.
94
95 </Note>
96
97 <Note>
98
99 In this guide, all file paths of backend customizations are relative to the `apps/backend` directory of your Medusa project.
100
101 </Note>
102
103 ---
104
105 ## Step 2: Install a Medusa Plugin Project
106
107 A plugin is a package of reusable Medusa customizations that you can install in any Medusa application. You can add in the plugin [API Routes](!docs!/learn/fundamentals/api-routes), [Workflows](!docs!/learn/fundamentals/workflows), and other customizations, as you'll see in this guide. Afterward, you can test it out locally in a Medusa application, then publish it to npm to install and use it in any Medusa application.
108
109 <Note>
110
111 Refer to the [Plugins](!docs!/learn/fundamentals/plugins) documentation to learn more about plugins.
112
113 </Note>
114
115 A Medusa plugin is set up in a different project, giving you the flexibility in building and publishing it, while providing you with the tools to test it out locally in a Medusa application.
116
117 To create a new Medusa plugin project, run the following command in a directory different than that of the Medusa application:
118
119 ```bash npm2yarn
120 npx create-medusa-app@latest medusa-plugin-magento --plugin
121 ```
122
123 Where `medusa-plugin-magento` is the name of the plugin's directory and the name set in the plugin's `package.json`. So, if you wish to publish it to NPM later under a different name, you can change it here in the command or later in `package.json`.
124
125 Once the installation process is done, a new directory named `medusa-plugin-magento` will be created with the plugin project files.
126
127 ![Directory structure of a plugin project](https://res.cloudinary.com/dza7lstvk/image/upload/v1737019441/Medusa%20Book/project-dir_q4xtri.jpg)
128
129 ---
130
131 ## Step 3: Set up Plugin in Medusa Application
132
133 Before you start your development, you'll set up the plugin in the Medusa application you installed in the first step. This will allow you to test the plugin during your development process.
134
135 In the plugin's directory, run the following command to publish the plugin to the local package registry:
136
137 ```bash title="Plugin project"
138 npx medusa plugin:publish
139 ```
140
141 This command uses [Yalc](https://github.com/wclr/yalc) under the hood to publish the plugin to a local package registry. The plugin is published locally under the name you specified in `package.json`.
142
143 Next, you'll install the plugin in the Medusa application from the local registry.
144
145 <Note>
146
147 If you've installed your Medusa project before v2.3.1, you must install [yalc](https://github.com/wclr/yalc) as a development dependency first.
148
149 </Note>
150
151 Run the following command in the `apps/backend` directory to install the plugin:
152
153 ```bash title="Medusa application"
154 npx medusa plugin:add medusa-plugin-magento
155 ```
156
157 This command installs the plugin in the Medusa application from the local package registry.
158
159 Next, register the plugin in the `medusa-config.ts` file of the Medusa application:
160
161 ```ts title="medusa-config.ts"
162 module.exports = defineConfig({
163 // ...
164 plugins: [
165 {
166 resolve: "medusa-plugin-magento",
167 options: {
168 // TODO add options
169 },
170 },
171 ],
172 })
173 ```
174
175 You add the plugin to the array of plugins. Later, you'll pass options useful to retrieve data from Magento.
176
177 Finally, to ensure your plugin's changes are constantly published to the local registry, simplifying your testing process, keep the following command running in the plugin project during development:
178
179 ```bash title="Plugin project"
180 npx medusa plugin:develop
181 ```
182
183 ---
184
185 ## Step 4: Implement Magento Module
186
187 To connect to external applications in Medusa, you create a custom module. A module is a reusable package with functionalities related to a single feature or domain. Medusa integrates the module into your application without implications or side effects on your setup.
188
189 In this step, you'll create a Magento Module in the Magento plugin that connects to a Magento server's REST APIs and retrieves data, such as products.
190
191 <Note>
192
193 Refer to the [Modules](!docs!/learn/fundamentals/modules) documentation to learn more about modules.
194
195 </Note>
196
197 ### Create Module Directory
198
199 A module is created under the `src/modules` directory of your plugin. So, create the directory `src/modules/magento`.
200
201 ![Diagram showcasing the module directory to create](https://res.cloudinary.com/dza7lstvk/image/upload/v1739272368/magento-1_ikev4x.jpg)
202
203 ### Create Module's Service
204
205 You define a module's functionalities in a service. A service is a TypeScript or JavaScript class that the module exports. In the service's methods, you can connect to external systems or the database, which is useful if your module defines tables in the database.
206
207 In this section, you'll create the Magento Module's service that connects to Magento's REST APIs and retrieves data.
208
209 Start by creating the file `src/modules/magento/service.ts` in the plugin with the following content:
210
211 ![Diagram showcasing the service file to create](https://res.cloudinary.com/dza7lstvk/image/upload/v1739272483/magento-2_ajetpr.jpg)
212
213 ```ts title="src/modules/magento/service.ts"
214 type Options = {
215 baseUrl: string
216 storeCode?: string
217 username: string
218 password: string
219 migrationOptions?: {
220 imageBaseUrl?: string
221 }
222 }
223
224 export default class MagentoModuleService {
225 private options: Options
226
227 constructor({}, options: Options) {
228 this.options = {
229 ...options,
230 storeCode: options.storeCode || "default",
231 }
232 }
233 }
234 ```
235
236 You create a `MagentoModuleService` that has an `options` property to store the module's options. These options include:
237
238 - `baseUrl`: The base URL of the Magento server.
239 - `storeCode`: The store code of the Magento store, which is `default` by default.
240 - `username`: The username of a Magento admin user to authenticate with the Magento server.
241 - `password`: The password of the Magento admin user.
242 - `migrationOptions`: Additional options useful for migrating data, such as the base URL to use for product images.
243
244 The service's constructor accepts as a first parameter the [Module Container](!docs!/learn/fundamentals/modules/container), which allows you to access resources available for the module. As a second parameter, it accepts the module's options.
245
246 ### Add Authentication Logic
247
248 To authenticate with the Magento server, you'll add a method to the service that retrieves an access token from Magento using the username and password in the options. This access token is used in subsequent requests to the Magento server.
249
250 First, add the following property to the `MagentoModuleService` class:
251
252 ```ts title="src/modules/magento/service.ts"
253 export default class MagentoModuleService {
254 private accessToken: {
255 token: string
256 expiresAt: Date
257 }
258 // ...
259 }
260 ```
261
262 You add an `accessToken` property to store the access token and its expiration date. The access token Magento returns expires after four hours, so you store the expiration date to know when to refresh the token.
263
264 Next, add the following `authenticate` method to the `MagentoModuleService` class:
265
266 ```ts title="src/modules/magento/service.ts"
267 import { MedusaError } from "@medusajs/framework/utils"
268
269 export default class MagentoModuleService {
270 // ...
271 async authenticate() {
272 const response = await fetch(`${this.options.baseUrl}/rest/${this.options.storeCode}/V1/integration/admin/token`, {
273 method: "POST",
274 headers: {
275 "Content-Type": "application/json",
276 },
277 body: JSON.stringify({ username: this.options.username, password: this.options.password }),
278 })
279
280 const token = await response.text()
281
282 if (!response.ok) {
283 throw new MedusaError(MedusaError.Types.UNAUTHORIZED, `Failed to authenticate with Magento: ${token}`)
284 }
285
286 this.accessToken = {
287 token: token.replaceAll("\"", ""),
288 expiresAt: new Date(Date.now() + 4 * 60 * 60 * 1000), // 4 hours in milliseconds
289 }
290 }
291 }
292 ```
293
294 You create an `authenticate` method that sends a POST request to the Magento server's `/rest/{storeCode}/V1/integration/admin/token` endpoint, passing the username and password in the request body.
295
296 If the request is successful, you store the access token and its expiration date in the `accessToken` property. If the request fails, you throw a `MedusaError` with the error message returned by Magento.
297
298 Lastly, add an `isAccessTokenExpired` method that checks if the access token has expired:
299
300 ```ts title="src/modules/magento/service.ts"
301 export default class MagentoModuleService {
302 // ...
303 async isAccessTokenExpired(): Promise<boolean> {
304 return !this.accessToken || this.accessToken.expiresAt < new Date()
305 }
306 }
307 ```
308
309 In the `isAccessTokenExpired` method, you return a boolean indicating whether the access token has expired. You'll use this in later methods to check if you need to refresh the access token.
310
311 ### Retrieve Products from Magento
312
313 Next, you'll add a method that retrieves products from Magento. Due to limitations in Magento's API that makes it difficult to differentiate between simple products that don't belong to a configurable product and those that do, you'll only retrieve configurable products and their children. You'll also retrieve the configurable attributes of the product, such as color and size.
314
315 First, you'll add some types to represent a Magento product and its attributes. Create the file `src/modules/magento/types.ts` in the plugin with the following content:
316
317 ![Diagram showcasing the types file to create](https://res.cloudinary.com/dza7lstvk/image/upload/v1739346287/Medusa%20Resources/magento-3_fpghog.jpg)
318
319 ```ts title="src/modules/magento/types.ts"
320 export type MagentoProduct = {
321 id: number
322 sku: string
323 name: string
324 price: number
325 status: number
326 // not handling other types
327 type_id: "simple" | "configurable"
328 created_at: string
329 updated_at: string
330 extension_attributes: {
331 category_links: {
332 category_id: string
333 }[]
334 configurable_product_links?: number[]
335 configurable_product_options?: {
336 id: number
337 attribute_id: string
338 label: string
339 position: number
340 values: {
341 value_index: number
342 }[]
343 }[]
344 }
345 media_gallery_entries: {
346 id: number
347 media_type: string
348 label: string
349 position: number
350 disabled: boolean
351 types: string[]
352 file: string
353 }[]
354 custom_attributes: {
355 attribute_code: string
356 value: string
357 }[]
358 // added by module
359 children?: MagentoProduct[]
360 }
361
362 export type MagentoAttribute = {
363 attribute_code: string
364 attribute_id: number
365 default_frontend_label: string
366 options: {
367 label: string
368 value: string
369 }[]
370 }
371
372 export type MagentoPagination = {
373 search_criteria: {
374 filter_groups: [],
375 page_size: number
376 current_page: number
377 }
378 total_count: number
379 }
380
381 export type MagentoPaginatedResponse<TData> = {
382 items: TData[]
383 } & MagentoPagination
384 ```
385
386 You define the following types:
387
388 - `MagentoProduct`: Represents a product in Magento.
389 - `MagentoAttribute`: Represents an attribute in Magento.
390 - `MagentoPagination`: Represents the pagination information returned by Magento's API.
391 - `MagentoPaginatedResponse`: Represents a paginated response from Magento's API for a specific item type, such as products.
392
393 Next, add the `getProducts` method to the `MagentoModuleService` class:
394
395 ```ts title="src/modules/magento/service.ts"
396 export default class MagentoModuleService {
397 // ...
398 async getProducts(options?: {
399 currentPage?: number
400 pageSize?: number
401 }): Promise<{
402 products: MagentoProduct[]
403 attributes: MagentoAttribute[]
404 pagination: MagentoPagination
405 }> {
406 const { currentPage = 1, pageSize = 100 } = options || {}
407 const getAccessToken = await this.isAccessTokenExpired()
408 if (getAccessToken) {
409 await this.authenticate()
410 }
411
412 // TODO prepare query params
413 }
414 }
415 ```
416
417 The `getProducts` method receives an optional `options` object with the `currentPage` and `pageSize` properties. So far, you check if the access token has expired and, if so, retrieve a new one using the `authenticate` method.
418
419 Next, you'll prepare the query parameters to pass in the request that retrieves products. Replace the `TODO` with the following:
420
421 ```ts title="src/modules/magento/service.ts"
422 const searchQuery = new URLSearchParams()
423 // pass pagination parameters
424 searchQuery.append(
425 "searchCriteria[currentPage]",
426 currentPage?.toString() || "1"
427 )
428 searchQuery.append(
429 "searchCriteria[pageSize]",
430 pageSize?.toString() || "100"
431 )
432
433 // retrieve only configurable products
434 searchQuery.append(
435 "searchCriteria[filter_groups][1][filters][0][field]",
436 "type_id"
437 )
438 searchQuery.append(
439 "searchCriteria[filter_groups][1][filters][0][value]",
440 "configurable"
441 )
442 searchQuery.append(
443 "searchCriteria[filter_groups][1][filters][0][condition_type]",
444 "in"
445 )
446
447 // TODO send request to retrieve products
448 ```
449
450 You create a `searchQuery` object to store the query parameters to pass in the request. Then, you add the pagination parameters and the filter to retrieve only configurable products.
451
452 Next, you'll send the request to retrieve products from Magento. Replace the `TODO` with the following:
453
454 ```ts title="src/modules/magento/service.ts"
455 const { items: products, ...pagination }: MagentoPaginatedResponse<MagentoProduct> = await fetch(
456 `${this.options.baseUrl}/rest/${this.options.storeCode}/V1/products?${searchQuery}`,
457 {
458 headers: {
459 "Authorization": `Bearer ${this.accessToken.token}`,
460 },
461 }
462 ).then((res) => res.json())
463 .catch((err) => {
464 console.log(err)
465 throw new MedusaError(
466 MedusaError.Types.INVALID_DATA,
467 `Failed to get products from Magento: ${err.message}`
468 )
469 })
470
471 // TODO prepare products
472 ```
473
474 You send a `GET` request to the Magento server's `/rest/{storeCode}/V1/products` endpoint, passing the query parameters in the URL. You also pass the access token in the `Authorization` header.
475
476 Next, you'll prepare the retrieved products by retrieving their children, configurable attributes, and modifying their image URLs. Replace the `TODO` with the following:
477
478 ```ts title="src/modules/magento/service.ts"
479 const attributeIds: string[] = []
480
481 await promiseAll(
482 products.map(async (product) => {
483 // retrieve its children
484 product.children = await fetch(
485 `${this.options.baseUrl}/rest/${this.options.storeCode}/V1/configurable-products/${product.sku}/children`,
486 {
487 headers: {
488 "Authorization": `Bearer ${this.accessToken.token}`,
489 },
490 }
491 ).then((res) => res.json())
492 .catch((err) => {
493 throw new MedusaError(
494 MedusaError.Types.INVALID_DATA,
495 `Failed to get product children from Magento: ${err.message}`
496 )
497 })
498
499 product.media_gallery_entries = product.media_gallery_entries.map(
500 (entry) => ({
501 ...entry,
502 file: `${this.options.migrationOptions?.imageBaseUrl}${entry.file}`,
503 }
504 ))
505
506 attributeIds.push(...(
507 product.extension_attributes.configurable_product_options?.map(
508 (option) => option.attribute_id) || []
509 )
510 )
511 })
512 )
513
514 // TODO retrieve attributes
515 ```
516
517 You loop over the retrieved products and retrieve their children using the `/rest/{storeCode}/V1/configurable-products/{sku}/children` endpoint. You also modify the image URLs to use the base URL in the migration options, if provided.
518
519 In addition, you store the IDs of the configurable products' attributes in the `attributeIds` array. You'll add a method that retrieves these attributes.
520
521 Add the new method `getAttributes` to the `MagentoModuleService` class:
522
523 ```ts title="src/modules/magento/service.ts"
524 export default class MagentoModuleService {
525 // ...
526 async getAttributes({
527 ids,
528 }: {
529 ids: string[]
530 }): Promise<MagentoAttribute[]> {
531 const getAccessToken = await this.isAccessTokenExpired()
532 if (getAccessToken) {
533 await this.authenticate()
534 }
535
536 // filter by attribute IDs
537 const searchQuery = new URLSearchParams()
538 searchQuery.append(
539 "searchCriteria[filter_groups][0][filters][0][field]",
540 "attribute_id"
541 )
542 searchQuery.append(
543 "searchCriteria[filter_groups][0][filters][0][value]",
544 ids.join(",")
545 )
546 searchQuery.append(
547 "searchCriteria[filter_groups][0][filters][0][condition_type]",
548 "in"
549 )
550
551 const {
552 items: attributes,
553 }: MagentoPaginatedResponse<MagentoAttribute> = await fetch(
554 `${this.options.baseUrl}/rest/${this.options.storeCode}/V1/products/attributes?${searchQuery}`,
555 {
556 headers: {
557 "Authorization": `Bearer ${this.accessToken.token}`,
558 },
559 }
560 ).then((res) => res.json())
561 .catch((err) => {
562 throw new MedusaError(
563 MedusaError.Types.INVALID_DATA,
564 `Failed to get attributes from Magento: ${err.message}`
565 )
566 })
567
568 return attributes
569 }
570 }
571 ```
572
573 The `getAttributes` method receives an object with the `ids` property, which is an array of attribute IDs. You check if the access token has expired and, if so, retrieve a new one using the `authenticate` method.
574
575 Next, you prepare the query parameters to pass in the request to retrieve attributes. You send a `GET` request to the Magento server's `/rest/{storeCode}/V1/products/attributes` endpoint, passing the query parameters in the URL. You also pass the access token in the `Authorization` header.
576
577 Finally, you return the retrieved attributes.
578
579 Now, go back to the `getProducts` method and replace the `TODO` with the following:
580
581 ```ts title="src/modules/magento/service.ts"
582 const attributes = await this.getAttributes({ ids: attributeIds })
583
584 return { products, attributes, pagination }
585 ```
586
587 You retrieve the configurable products' attributes using the `getAttributes` method and return the products, attributes, and pagination information.
588
589 You'll use this method in a later step to retrieve products from Magento.
590
591 ### Export Module Definition
592
593 The final piece to a module is its definition, which you export in an `index.ts` file at its root directory. This definition tells Medusa the name of the module and its service.
594
595 So, create the file `src/modules/magento/index.ts` with the following content:
596
597 ![Diagram showcasing the module definition file to create](https://res.cloudinary.com/dza7lstvk/image/upload/v1739348316/Medusa%20Resources/magento-4_bmepvh.jpg)
598
599 ```ts title="src/modules/magento/index.ts"
600 import { Module } from "@medusajs/framework/utils"
601 import MagentoModuleService from "./service"
602
603 export const MAGENTO_MODULE = "magento"
604
605 export default Module(MAGENTO_MODULE, {
606 service: MagentoModuleService,
607 })
608 ```
609
610 You use the `Module` function from the Modules SDK to create the module's definition. It accepts two parameters:
611
612 1. The module's name, which is `magento`.
613 2. An object with a required property `service` indicating the module's service.
614
615 You'll later use the module's service to retrieve products from Magento.
616
617 ### Pass Options to Plugin
618
619 As mentioned earlier when you registered the plugin in the Medusa Application's `medusa-config.ts` file, you can pass options to the plugin. These options are then passed to the modules in the plugin.
620
621 So, add the following options to the plugin's registration in the `medusa-config.ts` file of the Medusa application:
622
623 ```ts title="medusa-config.ts"
624 module.exports = defineConfig({
625 // ...
626 plugins: [
627 {
628 resolve: "medusa-plugin-magento",
629 options: {
630 baseUrl: process.env.MAGENTO_BASE_URL,
631 username: process.env.MAGENTO_USERNAME,
632 password: process.env.MAGENTO_PASSWORD,
633 migrationOptions: {
634 imageBaseUrl: process.env.MAGENTO_IMAGE_BASE_URL,
635 },
636 },
637 },
638 ],
639 })
640 ```
641
642 You pass the options that you defined in the `MagentoModuleService`. Make sure to also set their environment variables in the `.env` file:
643
644 ```bash
645 MAGENTO_BASE_URL=https://magento.example.com
646 MAGENTO_USERNAME=admin
647 MAGENTO_PASSWORD=password
648 MAGENTO_IMAGE_BASE_URL=https://magento.example.com/pub/media/catalog/product
649 ```
650
651 Where:
652
653 - `MAGENTO_BASE_URL`: The base URL of the Magento server. It can also be a local URL, such as `http://localhost:8080`.
654 - `MAGENTO_USERNAME`: The username of a Magento admin user to authenticate with the Magento server.
655 - `MAGENTO_PASSWORD`: The password of the Magento admin user.
656 - `MAGENTO_IMAGE_BASE_URL`: The base URL to use for product images. Magento stores product images in the `pub/media/catalog/product` directory, so you can reference them directly or use a CDN URL. If the URLs of product images in the Medusa server already have a different base URL, you can omit this option.
657
658 <Note title="Tip">
659
660 Medusa supports integrating third-party services, such as [S3](../../../infrastructure-modules/file/s3/page.mdx), in a File Module Provider. Refer to the [File Module](../../../infrastructure-modules/file/page.mdx) documentation to find other module providers and how to create a custom provider.
661
662 </Note>
663
664 You can now use the Magento Module to migrate data, which you'll do in the next steps.
665
666 ---
667
668 ## Step 5: Build Product Migration Workflow
669
670 In this section, you'll add the feature to migrate products from Magento to Medusa. To implement this feature, you'll use a workflow.
671
672 A workflow is a series of queries and actions, called steps, that complete a task. You construct a workflow like you construct a function, but it's a special function that allows you to track its executions' progress, define roll-back logic, and configure other advanced features. Then, you execute the workflow from other customizations, such as in an API route or a scheduled job.
673
674 By implementing the migration feature in a workflow, you ensure that the data remains consistent and that the migration process can be rolled back if an error occurs.
675
676 <Note>
677
678 Refer to the [Workflows](!docs!/learn/fundamentals/workflows) documentation to learn more about workflows.
679
680 </Note>
681
682 ### Workflow Steps
683
684 The workflow you'll create will have the following steps:
685
686 <WorkflowDiagram
687 workflow={{
688 name: "migrateProductsFromMagentoWorkflow",
689 steps: [
690 {
691 type: "step",
692 name: "getMagentoProductsStep",
693 description: "Retrieve products from Magento using the Magento Module.",
694 depth: 1,
695 },
696 {
697 type: "step",
698 name: "useQueryGraphStep",
699 description: "Retrieve Medusa store details, which you'll need when creating the products.",
700 depth: 1,
701 link: "/references/helper-steps/useQueryGraphStep"
702 },
703 {
704 type: "step",
705 name: "useQueryGraphStep",
706 description: "Retrieve a shipping profile, which you'll associate the created products with.",
707 depth: 1,
708 link: "/references/helper-steps/useQueryGraphStep"
709 },
710 {
711 type: "step",
712 name: "useQueryGraphStep",
713 description: "Retrieve Magento products that are already in Medusa to update them, instead of creating them.",
714 depth: 1,
715 link: "/references/helper-steps/useQueryGraphStep"
716 },
717 {
718 type: "step",
719 name: "useQueryGraphStep",
720 description: "Retrieve existing product options from Medusa.",
721 depth: 1,
722 link: "/references/helper-steps/useQueryGraphStep"
723 },
724 {
725 type: "workflow",
726 name: "createProductOptionsWorkflow",
727 description: "Create missing product options in Medusa.",
728 depth: 1,
729 link: "/references/medusa-workflows/createProductOptionsWorkflow"
730 },
731 {
732 type: "workflow",
733 name: "createProductsWorkflow",
734 description: "Create products in the Medusa application.",
735 depth: 1,
736 link: "/references/medusa-workflows/createProductsWorkflow"
737 },
738 {
739 type: "workflow",
740 name: "updateProductsWorkflow",
741 description: "Update existing products in the Medusa application.",
742 depth: 1,
743 link: "/references/medusa-workflows/updateProductsWorkflow"
744 }
745 ]
746 }}
747 hideLegend
748 />
749
750 You only need to implement the `getMagentoProductsStep` step, which retrieves the products from Magento. The other steps and workflows are provided by Medusa's `@medusajs/medusa/core-flows` package.
751
752 ### getMagentoProductsStep
753
754 The first step of the workflow retrieves and returns the products from Magento.
755
756 In your plugin, create the file `src/workflows/steps/get-magento-products.ts` with the following content:
757
758 <Note>
759
760 If you get a type error on resolving the Magento Module, run the Medusa application once with the `npm run dev` or `yarn dev` command to generate the necessary type definitions, as explained in the [Automatically Generated Types guide](!docs!/learn/fundamentals/generated-types).
761
762 </Note>
763
764 ![Diagram showcasing the get-magento-products file to create](https://res.cloudinary.com/dza7lstvk/image/upload/v1739349590/Medusa%20Resources/magento-5_ueb4wn.jpg)
765
766 ```ts title="src/workflows/steps/get-magento-products.ts"
767 import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
768 import { MAGENTO_MODULE } from "../../modules/magento"
769 import MagentoModuleService from "../../modules/magento/service"
770
771 type GetMagentoProductsInput = {
772 currentPage: number
773 pageSize: number
774 }
775
776 export const getMagentoProductsStep = createStep(
777 "get-magento-products",
778 async ({ currentPage, pageSize }: GetMagentoProductsInput, { container }) => {
779 const magentoModuleService: MagentoModuleService =
780 container.resolve(MAGENTO_MODULE)
781
782 const response = await magentoModuleService.getProducts({
783 currentPage,
784 pageSize,
785 })
786
787 return new StepResponse(response)
788 }
789 )
790 ```
791
792 You create a step using `createStep` from the Workflows SDK. It accepts two parameters:
793
794 1. The step's name, which is `get-magento-products`.
795 1. An async function that executes the step's logic. The function receives two parameters:
796 - The input data for the step, which in this case is the pagination parameters.
797 - An object holding the workflow's context, including the [Medusa Container](!docs!/learn/fundamentals/medusa-container) that allows you to resolve Framework and commerce tools.
798
799 In the step function, you resolve the Magento Module's service from the container, then use its `getProducts` method to retrieve the products from Magento.
800
801 Steps that return data must return them in a `StepResponse` instance. The `StepResponse` constructor accepts as a parameter the data to return.
802
803 ### Create migrateProductsFromMagentoWorkflow
804
805 You'll now create the workflow that migrates products from Magento using the step you created and steps from Medusa's `@medusajs/medusa/core-flows` package.
806
807 In your plugin, create the file `src/workflows/migrate-products-from-magento.ts` with the following content:
808
809 ![Diagram showcasing the migrate-products-from-magento file to create](https://res.cloudinary.com/dza7lstvk/image/upload/v1739349820/Medusa%20Resources/magento-6_jjdaxj.jpg)
810
811 ```ts title="src/workflows/migrate-products-from-magento.ts" collapsibleLines="1-17" expandButtonLabel="Show Imports"
812 import {
813 createWorkflow, transform, WorkflowResponse,
814 } from "@medusajs/framework/workflows-sdk"
815 import {
816 CreateProductWorkflowInputDTO,
817 CreateProductOptionDTO,
818 UpsertProductDTO,
819 } from "@medusajs/framework/types"
820 import {
821 createProductsWorkflow,
822 createProductOptionsWorkflow,
823 updateProductsWorkflow,
824 useQueryGraphStep,
825 } from "@medusajs/medusa/core-flows"
826 import { getMagentoProductsStep } from "./steps/get-magento-products"
827 import { MagentoAttribute } from "../modules/magento/types"
828
829 type MigrateProductsFromMagentoWorkflowInput = {
830 currentPage: number
831 pageSize: number
832 }
833
834 export const migrateProductsFromMagentoWorkflowId =
835 "migrate-products-from-magento"
836
837 export const migrateProductsFromMagentoWorkflow = createWorkflow(
838 {
839 name: migrateProductsFromMagentoWorkflowId,
840 retentionTime: 10000,
841 store: true,
842 },
843 (input: MigrateProductsFromMagentoWorkflowInput) => {
844 const { pagination, products, attributes } = getMagentoProductsStep(
845 input
846 )
847 // TODO prepare data to create and update products
848 }
849 )
850 ```
851
852 You create a workflow using `createWorkflow` from the Workflows SDK. It accepts two parameters:
853
854 1. An object with the workflow's configuration, including the name and whether to store the workflow's executions. You enable storing the workflow execution so that you can view it later in the Medusa Admin dashboard.
855 2. A workflow constructor function, which holds the workflow's implementation. The function receives the input data for the workflow, which is the pagination parameters.
856
857 In the workflow constructor function, you use the `getMagentoProductsStep` step to retrieve the products from Magento, passing it the pagination parameters from the workflow's input.
858
859 Next, you'll retrieve the Medusa store details and shipping profiles. These are necessary to prepare the data of the products to create or update.
860
861 Replace the `TODO` in the workflow function with the following:
862
863 ```ts title="src/workflows/migrate-products-from-magento.ts"
864 const { data: stores } = useQueryGraphStep({
865 entity: "store",
866 fields: ["supported_currencies.*", "default_sales_channel_id"],
867 pagination: {
868 take: 1,
869 skip: 0,
870 },
871 })
872
873 const { data: shippingProfiles } = useQueryGraphStep({
874 entity: "shipping_profile",
875 fields: ["id"],
876 pagination: {
877 take: 1,
878 skip: 0,
879 },
880 }).config({ name: "get-shipping-profiles" })
881
882 // TODO retrieve existing products
883 ```
884
885 You use the `useQueryGraphStep` step to retrieve the store details and shipping profiles. `useQueryGraphStep` is a Medusa step that wraps [Query](!docs!/learn/fundamentals/query), allowing you to use it in a workflow. Query is a tool that retrieves data across modules.
886
887 When retrieving the store details, you specifically retrieve its supported currencies and default sales channel ID. You'll associate the products with the store's default sales channel, and set their variant prices in the supported currencies. You'll also associate the products with a shipping profile.
888
889 Next, you'll retrieve products that were previously migrated from Magento to determine which products to create or update. Replace the `TODO` with the following:
890
891 ```ts title="src/workflows/migrate-products-from-magento.ts"
892 const externalIdFilters = transform({
893 products,
894 }, (data) => {
895 return data.products.map((product) => product.id.toString())
896 })
897
898 const { data: existingProducts } = useQueryGraphStep({
899 entity: "product",
900 fields: ["id", "external_id", "variants.id", "variants.metadata"],
901 filters: {
902 external_id: externalIdFilters,
903 },
904 }).config({ name: "get-existing-products" })
905
906 // TODO create Magento attributes as product options
907 ```
908
909 Since the Medusa application creates an internal representation of the workflow's constructor function, you can't manipulate data directly, as variables have no value while creating the internal representation.
910
911 <Note>
912
913 Refer to the [Workflows](!docs!/learn/fundamentals/workflows/constructor-constraints) documentation to learn more about the workflow constructor function's constraints.
914
915 </Note>
916
917 Instead, you can manipulate data in a workflow's constructor function using `transform` from the Workflows SDK. `transform` is a function that accepts two parameters:
918
919 - The data to transform, which in this case is the Magento products.
920 - A function that transforms the data. The function receives the data passed in the first parameter and returns the transformed data.
921
922 In the transformation function, you return the IDs of the Magento products. Then, you use the `useQueryGraphStep` to retrieve products in the Medusa application that have an `external_id` property matching the IDs of the Magento products. You'll use this property to store the IDs of the products in Magento.
923
924 Next, you'll create the Magento attributes as product options. Replace the `TODO` with the following:
925
926 ```ts title="src/workflows/migrate-products-from-magento.ts"
927 const attributeExternalIds = transform({
928 attributes,
929 }, (data) => {
930 return data.attributes.map((attr) => attr.attribute_id.toString())
931 })
932
933 const { data: existingOptions } = useQueryGraphStep({
934 entity: "product_option",
935 fields: ["id", "title", "metadata", "values.id", "values.value"],
936 filters: {
937 metadata: {
938 external_id: attributeExternalIds,
939 },
940 },
941 }).config({ name: "get-existing-options" })
942
943 const { optionsToCreate } = transform({
944 attributes,
945 existingOptions,
946 }, (data) => {
947 const optionsToCreate = new Map<
948 string,
949 CreateProductOptionDTO & { metadata?: Record<string, unknown> }
950 >()
951
952 data.attributes.forEach((attr: MagentoAttribute) => {
953 const existingOption = data.existingOptions.find(
954 (option) => option.metadata?.external_id === attr.attribute_id.toString()
955 )
956
957 // If option already exists, skip it
958 if (existingOption) {
959 return
960 }
961
962 const optionData: CreateProductOptionDTO & { metadata?: Record<string, unknown> } = {
963 title: attr.default_frontend_label,
964 values: attr.options.map((opt) => opt.label),
965 metadata: {
966 external_id: attr.attribute_id.toString(),
967 },
968 }
969
970 optionsToCreate.set(attr.attribute_id.toString(), optionData)
971 })
972
973 return {
974 optionsToCreate: Array.from(optionsToCreate.values()),
975 }
976 })
977
978 // Create missing options if any
979 const newOptions = createProductOptionsWorkflow.runAsStep({
980 input: {
981 product_options: optionsToCreate,
982 },
983 })
984
985 // Merge existing and newly created options
986 const allOptions = transform({
987 existingOptions,
988 newOptions,
989 }, (data) => {
990 return [...(data.existingOptions || []), ...(data.newOptions || [])]
991 })
992
993 // TODO prepare products to create or update
994 ```
995
996 You:
997
998 1. Extract attribute external IDs using `transform`.
999 2. Retrieve existing options from the Medusa application using `useQueryGraphStep`.
1000 3. Check which attributes don't exist in Medusa and prepare to create them as options using `transform`.
1001 4. Create the missing options in Medusa using `createProductOptionsWorkflow`.
1002 5. Combine the existing and newly created options using `transform`.
1003
1004 Next, you'll prepare the data to create and update the products. Replace the `TODO` in the workflow function with the following:
1005
1006 export const prepareHighlights = [
1007 ["2", "productsToCreate", "The products to create."],
1008 ["3", "productsToUpdate", "The products to update."],
1009 ["4", "transform", "Prepare the product data."],
1010 ["12", "productsToCreate", "Create a map to store the products to create."],
1011 ["13", "productsToUpdate", "Create a map to store the products to update."],
1012 ["18", "description", "Try to retrieve description from the Magento product's custom attributes."],
1013 ["22", "handle", "Try to retrieve the product's handle from the Magento product's custom attributes."],
1014 ["25", "external_id", "Set the Magento product's ID in the Medusa product's `external_id` property."],
1015 ["26", "thumbnail", "Try to retrieve the product's thumbnail from the Magento product's media gallery entries."],
1016 ["29", "sales_channels", "Associate the product with the default sales channel."],
1017 ["32", "shipping_profile_id", "Associate the product with a shipping profile."],
1018 ["34", "existingProduct", "Find the existing product in Medusa that matches the Magento product's ID."],
1019 ["40", "options", "Map the Magento product's configurable product options to Medusa product options."],
1020 ["77", "variants", "Map the Magento product's children to Medusa product variants."],
1021 ]
1022
1023 ```ts title="src/workflows/migrate-products-from-magento.ts" highlights={prepareHighlights}
1024 const {
1025 productsToCreate,
1026 productsToUpdate,
1027 } = transform({
1028 products,
1029 attributes,
1030 stores,
1031 shippingProfiles,
1032 existingProducts,
1033 allOptions,
1034 }, (data) => {
1035 const productsToCreate = new Map<string, CreateProductWorkflowInputDTO>()
1036 const productsToUpdate = new Map<string, UpsertProductDTO>()
1037
1038 data.products.forEach((magentoProduct) => {
1039 const productData: CreateProductWorkflowInputDTO | UpsertProductDTO = {
1040 title: magentoProduct.name,
1041 description: magentoProduct.custom_attributes.find(
1042 (attr) => attr.attribute_code === "description"
1043 )?.value,
1044 status: magentoProduct.status === 1 ? "published" : "draft",
1045 handle: magentoProduct.custom_attributes.find(
1046 (attr) => attr.attribute_code === "url_key"
1047 )?.value,
1048 external_id: magentoProduct.id.toString(),
1049 thumbnail: magentoProduct.media_gallery_entries.find(
1050 (entry) => entry.types.includes("thumbnail")
1051 )?.file,
1052 sales_channels: [{
1053 id: data.stores[0].default_sales_channel_id,
1054 }],
1055 shipping_profile_id: data.shippingProfiles[0].id,
1056 }
1057 const existingProduct = data.existingProducts.find((p) => p.external_id === productData.external_id)
1058
1059 if (existingProduct) {
1060 productData.id = existingProduct.id
1061 }
1062
1063 productData.options = magentoProduct.extension_attributes.configurable_product_options
1064 ?.map((option) => {
1065 const attribute = data.attributes.find(
1066 (attr) => attr.attribute_id === parseInt(option.attribute_id)
1067 )
1068 const existingOption = data.allOptions.find(
1069 (opt) => opt.metadata?.external_id === option.attribute_id
1070 )
1071
1072 if (!existingOption || !attribute) {
1073 return null
1074 }
1075
1076 // Map option values to their IDs
1077 const valueIds = option.values
1078 .map((v) => {
1079 const attributeOption = attribute.options.find(
1080 (opt) => parseInt(opt.value) === v.value_index
1081 )
1082 if (!attributeOption) {
1083 return null
1084 }
1085
1086 const optionValue = existingOption.values.find(
1087 (val) => val.value === attributeOption.label
1088 )
1089 return optionValue?.id
1090 })
1091 .filter((id): id is string => Boolean(id))
1092
1093 return {
1094 id: existingOption.id,
1095 value_ids: valueIds,
1096 }
1097 })
1098 .filter((opt): opt is { id: string; value_ids: string[] } => opt !== null) || []
1099
1100 productData.variants = magentoProduct.children?.map((child) => {
1101 const childOptions: Record<string, string> = {}
1102
1103 child.custom_attributes.forEach((attr) => {
1104 const attrData = data.attributes.find((a) => a.attribute_code === attr.attribute_code)
1105 if (!attrData) {
1106 return
1107 }
1108
1109 childOptions[attrData.default_frontend_label] = attrData.options.find((opt) => opt.value === attr.value)?.label || ""
1110 })
1111
1112 const variantExternalId = child.id.toString()
1113 const existingVariant = existingProduct.variants.find((v) => v.metadata.external_id === variantExternalId)
1114
1115 return {
1116 title: child.name,
1117 sku: child.sku,
1118 options: childOptions,
1119 prices: data.stores[0].supported_currencies.map(({ currency_code }) => {
1120 return {
1121 amount: child.price,
1122 currency_code,
1123 }
1124 }),
1125 metadata: {
1126 external_id: variantExternalId,
1127 },
1128 id: existingVariant?.id,
1129 }
1130 })
1131
1132 productData.images = magentoProduct.media_gallery_entries.filter((entry) => !entry.types.includes("thumbnail")).map((entry) => {
1133 return {
1134 url: entry.file,
1135 metadata: {
1136 external_id: entry.id.toString(),
1137 },
1138 }
1139 })
1140
1141 if (productData.id) {
1142 productsToUpdate.set(existingProduct.id, productData as UpsertProductDTO)
1143 } else {
1144 productsToCreate.set(productData.external_id!, productData)
1145 }
1146 })
1147
1148 return {
1149 productsToCreate: Array.from(productsToCreate.values()),
1150 productsToUpdate: Array.from(productsToUpdate.values()),
1151 }
1152 })
1153
1154 // TODO create and update products
1155 ```
1156
1157 You use `transform` again to prepare the data to create and update the products in the Medusa application. For each Magento product, you map its equivalent Medusa product's data:
1158
1159 - You set the product's general details, such as the title, description, status, handle, external ID, and thumbnail using the Magento product's data and custom attributes.
1160 - You associate the product with the default sales channel and shipping profile retrieved previously.
1161 - You map the Magento product's configurable product options to Medusa product options by referencing the options created earlier (or existing ones). You map the option values to their IDs using the `attribute.options` and `existingOption.values` properties.
1162 - You map the Magento product's children to Medusa product variants. For the variant options, you pass an object whose keys is the option's label, such as "Color", and values is the option's value, such as "Red". For the prices, you set the variant's price based on the Magento child's price for every supported currency in the Medusa store. Also, you set the Magento child product's ID in the Medusa variant's `metadata.external_id` property.
1163 - You map the Magento product's media gallery entries to Medusa product images. You filter out the thumbnail image and set the URL and the Magento image's ID in the Medusa image's `metadata.external_id` property.
1164
1165 In addition, you use the existing products retrieved in the previous step to determine whether a product should be created or updated. If there's an existing product whose `external_id` matches the ID of the magento product, you set the existing product's ID in the `id` property of the product to be updated. You also do the same for its variants.
1166
1167 Finally, you return the products to create and update.
1168
1169 The last steps of the workflow is to create and update the products. Replace the `TODO` in the workflow function with the following:
1170
1171 ```ts title="src/workflows/migrate-products-from-magento.ts"
1172 createProductsWorkflow.runAsStep({
1173 input: {
1174 products: productsToCreate,
1175 },
1176 })
1177
1178 updateProductsWorkflow.runAsStep({
1179 input: {
1180 products: productsToUpdate,
1181 },
1182 })
1183
1184 return new WorkflowResponse(pagination)
1185 ```
1186
1187 You use the `createProductsWorkflow` and `updateProductsWorkflow` workflows from Medusa's `@medusajs/medusa/core-flows` package to create and update products in the Medusa application.
1188
1189 Workflows must return an instance of `WorkflowResponse`, passing as a parameter the data to return to the workflow's executor. This workflow returns the pagination parameters, allowing you to paginate the product migration process.
1190
1191 You can now use this workflow to migrate products from Magento to Medusa. You'll learn how to use it in the next steps.
1192
1193 ---
1194
1195 ## Step 6: Schedule Product Migration
1196
1197 There are many ways to execute tasks asynchronously in Medusa, such as [scheduling a job](!docs!/learn/fundamentals/scheduled-jobs) or [handling emitted events](!docs!/learn/fundamentals/events-and-subscribers).
1198
1199 In this guide, you'll learn how to schedule the product migration at a specified interval using a scheduled job. A scheduled job is an asynchronous function that the Medusa application runs at the interval you specify during the Medusa application's runtime.
1200
1201 <Note>
1202
1203 Refer to the [Scheduled Jobs](!docs!/learn/fundamentals/scheduled-jobs) documentation to learn more about scheduled jobs.
1204
1205 </Note>
1206
1207 To create a scheduled job, in your plugin, create the file `src/jobs/migrate-magento.ts` with the following content:
1208
1209 ![Diagram showcasing the migrate-magento file to create](https://res.cloudinary.com/dza7lstvk/image/upload/v1739358924/Medusa%20Resources/magento-7_rqoodo.jpg)
1210
1211 ```ts title="src/jobs/migrate-magento.ts"
1212 import { MedusaContainer } from "@medusajs/framework/types"
1213 import { migrateProductsFromMagentoWorkflow } from "../workflows"
1214 import {
1215 ContainerRegistrationKeys,
1216 } from "@medusajs/framework/utils"
1217
1218 export default async function migrateMagentoJob(
1219 container: MedusaContainer
1220 ) {
1221 const logger = container.resolve(
1222 ContainerRegistrationKeys.LOGGER
1223 )
1224 logger.info("Migrating products from Magento...")
1225
1226 let currentPage = 0
1227 const pageSize = 100
1228 let totalCount = 0
1229
1230 do {
1231 currentPage++
1232
1233 const {
1234 result: pagination,
1235 } = await migrateProductsFromMagentoWorkflow(container).run({
1236 input: {
1237 currentPage,
1238 pageSize,
1239 },
1240 })
1241
1242 totalCount = pagination.total_count
1243 } while (currentPage * pageSize < totalCount)
1244
1245 logger.info("Finished migrating products from Magento")
1246 }
1247
1248 export const config = {
1249 name: "migrate-magento-job",
1250 schedule: "0 0 * * *",
1251 }
1252 ```
1253
1254 A scheduled job file must export:
1255
1256 - An asynchronous function that executes the job's logic. The function receives the [Medusa container](!docs!/learn/fundamentals/medusa-container) as a parameter.
1257 - An object with the job's configuration, including the name and the schedule. The schedule is a cron job pattern as a string.
1258
1259 In the job function, you resolve the [logger](!docs!/learn/debugging-and-testing/logging) from the container to log messages. Then, you paginate the product migration process by running the `migrateProductsFromMagentoWorkflow` workflow at each page until you've migrated all products. You use the pagination result returned by the workflow to determine whether there are more products to migrate.
1260
1261 Based on the job's configurations, the Medusa application will run the job at midnight every day.
1262
1263 ### Test it Out
1264
1265 To test out this scheduled job, first, change the configuration to run the job every minute:
1266
1267 ```ts title="src/jobs/migrate-magento.ts"
1268 export const config = {
1269 // ...
1270 schedule: "* * * * *",
1271 }
1272 ```
1273
1274 Then, make sure to run the `plugin:develop` command in the plugin if you haven't already:
1275
1276 ```bash
1277 npx medusa plugin:develop
1278 ```
1279
1280 This ensures that the plugin's latest changes are reflected in the Medusa application.
1281
1282 Finally, start the Medusa application that the plugin is installed in:
1283
1284 ```bash npm2yarn
1285 npm run dev
1286 ```
1287
1288 After a minute, you'll see a message in the terminal indicating that the migration started:
1289
1290 ```plain title="Terminal"
1291 info: Migrating products from Magento...
1292 ```
1293
1294 Once the migration is done, you'll see the following message:
1295
1296 ```plain title="Terminal"
1297 info: Finished migrating products from Magento
1298 ```
1299
1300 To confirm that the products were migrated, open the Medusa Admin dashboard at `http://localhost:9000/app` and log in. Then, click on Products in the sidebar. You'll see your magento products in the list of products.
1301
1302 ![Click on products at the sidebar on the right, then view the products in the table in the middle.](https://res.cloudinary.com/dza7lstvk/image/upload/v1739359394/Medusa%20Resources/Screenshot_2025-02-12_at_1.22.44_PM_uva98i.png)
1303
1304 ---
1305
1306 ## Next Steps
1307
1308 You've now implemented the logic to migrate products from Magento to Medusa. You can re-use the plugin across Medusa applications. You can also expand on the plugin to:
1309
1310 - Migrate other entities, such as orders, customers, and categories. Migrating other entities follows the same pattern as migrating products, using workflows and scheduled jobs. You only need to format the data to be migrated as needed.
1311 - Allow triggering migrations from the Medusa Admin dashboard using [Admin Customizations](!docs!/learn/fundamentals/admin). This feature is available in the [Example Repository](https://github.com/medusajs/example-repository/tree/main/src/admin).
1312
1313 If you're new to Medusa, check out the [main documentation](!docs!/learn), where you'll get a more in-depth learning of all the concepts you've used in this guide and more.
1314
1315 To learn more about the commerce features that Medusa provides, check out Medusa's [Commerce Modules](../../../commerce-modules/page.mdx).