Built by

Thisisjuke

Category

Source

Version

1.0.0

Last updated

Nov 27, 2022, 16:28:13 PM2 years ago

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
Copy to clipboard
medusa-source-shopify
: https://github.com/medusajs/medusa/tree/master/packages/medusa-source-shopify

Context: what's the difference?

  • I need something smoother and more simple than
    Copy to clipboard
    updated_at_min
    coming from cache: Original repo method
    Copy to clipboard
    getAndUpdateBuildTime_
    .
  • For dev purposes or just to migrate Shopify one time: I want to be able to use JSON files like
    Copy to clipboard
    products.json
    .
  • It's always better if I can dodge working with
    Copy to clipboard
    Shopify Private Applications
    🐱 !

Install the plugin

Navigate to your Medusa server (the API, not the admin dashboard) in your terminal, and install the plugin.
$ cd my-medusa-server
$ yarn add medusa-source-shopify-json

Fetch from a local JSON

Download your products

💡
Copy to clipboard
MY_STORE_NAME
is the name of your store.
  • Go to:
    Copy to clipboard
    https://MY_STORE_NAME.myshopify.com/admin/api/unstable/products.json
  • Save this JSON in a
    Copy to clipboard
    .json
    file, like in
    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

const 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
Copy to clipboard
Apps
and click the
Copy to clipboard
Develop apps for your store
button at the bottom of the page. After navigating to the
Copy to clipboard
App development
page, click the
Copy to clipboard
Create an app
in the top right corner.
This should open a modal where you can choose a name for your app. Write a name and click
Copy to clipboard
Create app
.
You should then click the button that says
Copy to clipboard
Configure Admin API scopes
. Scroll down to
Copy to clipboard
Products
and select the
Copy to clipboard
read_products
scope, and then save your changes.
Go back to overview and click
Copy to clipboard
Install app
. This should generate a token, that you should write down as you can only view it once : it's your
Copy to clipboard
password
.

Add the plugin to your configuration

Update your
Copy to clipboard
medusa-config.js
with the following:
//Shopify keys
const 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
Copy to clipboard
SHOPIFY_STORE_URL
and
Copy to clipboard
SHOPIFY_API_KEY
to your
Copy to clipboard
.env
.
SHOPIFY_API_KEY=<your_secret_shopify_key>
SHOPIFY_STORE_URL=<your_store_name>
The
Copy to clipboard
SHOPIFY_API_KEY
is the token that we generated in the previous step.
Copy to clipboard
SHOPIFY_STORE_URL
is the name of your store (don't add
Copy to clipboard
myshopify.com
in this variable). You can view the name in the url of your Shopify dashboard, which has the following format
Copy to clipboard
<your_store_name>.myshopify.com
.
Copy to clipboard
updated_after
overwrite the autogenerated date from build to fetch all products starting a date.
updated_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 clipboard
false
.
updated_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
$ yarn start
and the plugin will handle the rest.

Note / Limitations

Copy to clipboard
Product/Collection
relations (
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:
  1. Custom collections
  2. Smart collections
This means that if product
Copy to clipboard
X
is part of custom collection
Copy to clipboard
Y
and smart collection
Copy to clipboard
Z
in Shopify, it will only be added to custom collection
Copy to clipboard
X
in Medusa.

Build your own plugins

Develop your own plugins with our API to speed up your processes.

Make your plugin available via npm for it to be shared in our Plugin Library with the broader Medusa community.