npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

medusa-source-shopify-json

v1.0.0

Published

Source plugin that allows users to import products from a Shopify store using Shopify App or JSON.

Downloads

4

Readme

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 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 updated_at_min coming from cache: Original repo method getAndUpdateBuildTime_.
  • For dev purposes or just to migrate Shopify one time: I want to be able to use JSON files like products.json.
  • It's always better if I can dodge working with 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

💡 MY_STORE_NAME is the name of your store.

  • Go to: https://MY_STORE_NAME.myshopify.com/admin/api/unstable/products.json
  • Save this JSON in a .json file, like in ./products.json

Do the same with these 3 urls:

  • custom_collections : https://MY_STORE_NAME.myshopify.com/admin/api/unstable/custom_collections.json
  • smart_collections : https://MY_STORE_NAME.myshopify.com/admin/api/unstable/smart_collections.json
  • collects_path : 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 Apps and click the Develop apps for your store button at the bottom of the page. After navigating to the App development page, click the 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 Create app.

You should then click the button that says Configure Admin API scopes. Scroll down to Products and select the read_products scope, and then save your changes.

Go back to overview and click Install app. This should generate a token, that you should write down as you can only view it once : it's your password.

Add the plugin to your configuration

Update your 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 SHOPIFY_STORE_URL and SHOPIFY_API_KEY to your .env.

SHOPIFY_API_KEY=<your_secret_shopify_key>
SHOPIFY_STORE_URL=<your_store_name>

The SHOPIFY_API_KEY is the token that we generated in the previous step.

SHOPIFY_STORE_URL is the name of your store (don't add myshopify.com in this variable). You can view the name in the url of your Shopify dashboard, which has the following format <your_store_name>.myshopify.com.

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 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

Product/Collection relations (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 X is part of custom collection Y and smart collection Z in Shopify, it will only be added to custom collection X in Medusa.