Medusa Source Shopify JSON
Plugin that allows users to source Medusa using a Shopify store or JSON of products coming from Shopify.
It's a fork from
: https://github.com/medusajs/medusa/tree/master/packages/medusa-source-shopifyCopy to clipboardmedusa-source-shopify
Context: what's the difference?
- I need something smoother and more simple than
coming from cache: Original repo methodCopy to clipboardupdated_at_min
.Copy to clipboardgetAndUpdateBuildTime_
- For dev purposes or just to migrate Shopify one time: I want to be able to use JSON files like
.Copy to clipboardproducts.json
- It's always better if I can dodge working with
🐱 !Copy to clipboardShopify Private Applications
Install the plugin
Navigate to your Medusa server (the API, not the admin dashboard) in your terminal, and install the plugin.
12$ cd my-medusa-server$ yarn add medusa-source-shopify-json
Fetch from a local JSON
Download your products
💡is the name of your store.Copy to clipboardMY_STORE_NAME
- Go to: Copy to clipboard
https://MY_STORE_NAME.myshopify.com/admin/api/unstable/products.json
- Save this JSON in a
file, like inCopy to clipboard.json
Copy to clipboard./products.json
Do the same with these 3 urls:
- custom_collections : Copy to clipboard
https://MY_STORE_NAME.myshopify.com/admin/api/unstable/custom_collections.json
- smart_collections : Copy to clipboard
https://MY_STORE_NAME.myshopify.com/admin/api/unstable/smart_collections.json
- collects_path : Copy to clipboard
https://MY_STORE_NAME.myshopify.com/admin/api/unstable/collects_path.json
💡 You now have created 4 files inside your applications.
Add the plugin to your configuration
1234567891011121314const plugins = [// other plugins...{resolve: `medusa-source-shopify-json`,options: {json: {products_path: "./products.json",custom_collections_path: "./custom_collections.json",smart_collections_path: "./smart_collections.json",collects_path: "./collects.json"}}}];
Fetch directly your products from Shopify
Create a Shopify app
Navigate to your Shopify dashboard, and then go to
and click theCopy to clipboardApps
button at the bottom of the page. After navigating to theCopy to clipboardDevelop apps for your store
page, click theCopy to clipboardApp development
in the top right corner.Copy to clipboardCreate an app
This should open a modal where you can choose a name for your app. Write a name and click
.Copy to clipboardCreate app
You should then click the button that says
. Scroll down toCopy to clipboardConfigure Admin API scopes
and select theCopy to clipboardProducts
scope, and then save your changes.Copy to clipboardread_products
Go back to overview and click
. This should generate a token, that you should write down as you can only view it once : it's yourCopy to clipboardInstall app
.Copy to clipboardpassword
Add the plugin to your configuration
Update your
with the following:Copy to clipboardmedusa-config.js
123456789101112131415//Shopify keysconst SHOPIFY_STORE_URL = process.env.SHOPIFY_STORE_URL || "";const SHOPIFY_API_KEY = process.env.SHOPIFY_API_KEY || "";const plugins = [// other plugins...{resolve: `medusa-source-shopify-json`,options: {domain: SHOPIFY_STORE_URL,password: SHOPIFY_API_KEY,updated_after: "2021-01-01"}}];
You should then add
andCopy to clipboardSHOPIFY_STORE_URL
to yourCopy to clipboardSHOPIFY_API_KEY
.Copy to clipboard.env
12SHOPIFY_API_KEY=<your_secret_shopify_key>SHOPIFY_STORE_URL=<your_store_name>
The
is the token that we generated in the previous step.Copy to clipboardSHOPIFY_API_KEY
is the name of your store (don't addCopy to clipboardSHOPIFY_STORE_URL
in this variable). You can view the name in the url of your Shopify dashboard, which has the following formatCopy to clipboardmyshopify.com
.Copy to clipboard<your_store_name>.myshopify.com
overwrite the autogenerated date from build to fetch all products starting a date.Copy to clipboardupdated_after
1updated_after: '2022/10/10' //this will fetch products modified since the 10th October of 2022.
If you want to disable this feature and fetch things independently of the date, set it to
.Copy to clipboardfalse
1updated_after: false;
If your remove it, it does like the default behavior:
The plugin stores everytime it is run, and will use this timestamp to only fetch products, collections and collects that have been updated in Shopify since the last time it pulled data.
Run your server
After setting everything up you can now run your server
1$ yarn start
and the plugin will handle the rest.
Note / Limitations
Copy to clipboardProduct/Collection
relations (Copy to clipboardCollect
)
Copy to clipboard
Product/Collection
Copy to clipboard
Collect
(this is the same limitation as in the official plugin)
Shopify supports products being part of more than one collection, but Medusa does not support this. For this reason a product will only be part of the first collection it has a relation to in Medusa. The plugin processes Shopify product/collection relations in the following order:
- Custom collections
- Smart collections
This means that if product
is part of custom collectionCopy to clipboardX
and smart collectionCopy to clipboardY
in Shopify, it will only be added to custom collectionCopy to clipboardZ
in Medusa.Copy to clipboardX
