Check if App embed Is Active

Check if App embed Is Active

Ido1425
Shopify Partner
26 0 0

Hi everyone!

I am developing my Shopify app and I am struggling to find solution for checking if my app embed block is active in the user's theme editor, the Shopify documentation about it is very short and not informative.

I would really appreciate help with that!

Replies 3 (3)

BSSCommerce-B2B
Shopify Expert
553 110 133

Hi @Ido1425,

 

You could check in themes config/settings_data.json. Like the picture below, if an app embed is active, its information should be displayed

BSSCommerceB2B_0-1718709795948.png

 

let activeAppEmbeds = true;
let contentFile = null;
let searchBlock = false;
// You should write your own getContentFile
let resContentFile = await getContentFile(domain, token,themeId,"config/settings_data.json");
if (resContentFile) {
    contentFile = JSON.parse(resContentFile);
}
if (contentFile && contentFile?.current?.blocks) {
    const appEmbeds = contentFile?.current?.blocks;
    for (const key in appEmbeds) {
        if (Object.prototype.hasOwnProperty.call(appEmbeds, key)) {
            searchBlock = true;
            const app = appEmbeds[key];
            // extensionId is your theme app extension id after deployed
            if (app.type.includes(extensionId) && app.disabled) {
                activeAppEmbeds = false;
                break;
            }
        }
    }
    if(!searchBlock) {
        activeAppEmbeds = false;
    }
} else {
    activeAppEmbeds = false;
}

 

I hope this is helpful to you.

If our suggestions are useful, please let us know by giving it a like, marking it as a solution.


B2B Solution & Custom Pricing |BSS: B2B Portal, Quote, Net 30 | BSS: B2B Login Lock Hide Price


Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency
Ido1425
Shopify Partner
26 0 0

Thank you for that!

The only thing I don't understand is how do I get the content file I want from the current theme. 

I couldn't find explanation for that in the Shopify docs

(I am using Gadget.dev)

BSSCommerce-B2B
Shopify Expert
553 110 133

You need `read_themes` scopes and use Shopify Theme API to get the current/main theme ID (the current theme has its role value as main like the first picture below, you could get the theme list and do filter to get the current theme) and use the returned theme ID to make request to Shopify Asset API to get theme file content, with query param asset[key]=config/settings_data.json

 

1. 

BSSCommerceB2B_0-1718781805826.png

 

2. 

BSSCommerceB2B_1-1718781976807.png

 

Hope this is helpful to you.

If our suggestions are useful, please let us know by giving it a like, marking it as a solution.


B2B Solution & Custom Pricing |BSS: B2B Portal, Quote, Net 30 | BSS: B2B Login Lock Hide Price


Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency