Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Check if App embed Is Active

Check if App embed Is Active

Ido1425
Shopify Partner
26 0 3

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 Partner
1969 564 566

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.

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

Ido1425
Shopify Partner
26 0 3

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 Partner
1969 564 566

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.

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now