This repository was archived by the owner on Nov 30, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 375
Multiple Custom Apps on Same Codebase
Tyler King edited this page Dec 2, 2020
·
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;
// ...
'config_api_callback' => function (string $key, $shop) {
if (! $shop) {
return Config::get("shopify-app.{$key}");
}
$shopDomain = $shop instanceof ShopDomainValue ? $shop->toNative() : $shop;
$shopDomain = preg_replace('/[^A-Z0-9]/', '', strtoupper(explode('.', $shop)[0]));
return env(strtoupper($key)."_".$shopDomain, Config::get("shopify-app.{$key}"));
},
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.
road map
Welcome to the wiki!
Please see the homepage for a list of relevant pages.