Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Multiple Custom Apps on Same Codebase

Gage K. Holland edited this page Oct 18, 2021 · 8 revisions

Shopify now has limitations on unpublished apps. Custom Apps can only be used on one store. This is an issue if you have a "private" app you wish to share with your clients, but use the same codebase.

This solution allows for swapping out API keys on-the-fly to a Custom App's keys.

In your config/shopify-app.php's config_api_callback option, you would do:

use Osiset\ShopifyApp\Contracts\Objects\Values\ShopDomain as ShopDomainValue;
use Illuminate\Support\Facades\Config;

    // ...

    'config_api_callback' => function (string $key, $shop) {
        $fullKey = "shopify-app.{$key}";
        if (! $shop) {
            // No shop passed, return default
            return Config::get($fullKey);
        }

        // Clean the shop domain
        $shopDomain = $shop instanceof ShopDomainValue ? $shop->toNative() : $shop;
        $shopDomain = preg_replace('/[^A-Z0-9]/', '', strtoupper(explode('.', $shopDomain)[0]));

        // Try to get env defined for shop, fallback to config value
        return env(
             strtoupper($key)."_".$shopDomain,
             Config::get($fullKey)
        );
    },

This will pull API key and secret from your environment variables. So if a shop domain is charles-store.myshopify.com, you would make two entries in your environment variables:

API_KEY_CHARLESSTORE="66d7f69b713b201e06805db4d6f9bcefa"
API_SECRET_CHARLESSTORE="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"

Now, anytime the API interface is called for the shop, it will use the keys defined for that shop.

Welcome to the wiki!

Please see the homepage for a list of relevant pages.

Clone this wiki locally