thetrevorharmon / gatsby-theme-shopify-manager

The easiest way to start a Shopify shop on Gatsby.
https://gatsby-theme-shopify-manager.netlify.app/
MIT License
122 stars 12 forks source link

Multiple Shopify stores? #89

Closed davidpaulsson closed 3 years ago

davidpaulsson commented 3 years ago

First off: thanks for a great plugin!

I'm wondering what's the best approach would be to build a regionalized gatsby site that connects to different Shopify stores? My company currently have different Shopify stores for different regions, like one Shopify store for US, one for EU, one for Canada etc.

I'm trying to figure out the architecture for this to have mysite.com/en-eu/:splat, mysite.com/en-us/:splat, and mysite.com/en-ca/:splat, etc, and have useCart (as an example) connect to the different Shopify stores based on a regional setting. Is it possible to somehow have multiple versions of gatsby-theme-shopify-manager running at once?

thetrevorharmon commented 3 years ago

I would pass false to shouldWrapRootElementWithProvider (docs link). From there, you can set up your own context provider that conditionally provides the right access token/info.

Example:

import React from 'react';
import {ContextProvider} from 'gatsby-theme-shopify-manager';
export function StoreWrapper = ({children}) => {

  const shopName = {
    us: 'some-US-shop-name',
    eu: 'some-EU-shop-name',
  };

  const accessToken = {
    us: 'some-US-token',
    eu: 'some-EU-token',
  };

  return (
    <ContextProvider shopName={shopName[currentLocation]} accessToken={accessToken[currentLocation]}>
      {children}
    </ContextProvider>
  );
};

I think this will work, but I've never tried something like this. Best of luck.

davidpaulsson commented 3 years ago

@thetrevorharmon Thank you!