How to activate an app block automatically (NodeJS)

Solved

How to activate an app block automatically (NodeJS)

Neli2404
Shopify Partner
13 1 2

Hello!
I'm currently researching app blocks(Theme app extension). Is there anyway to activate an app block automatically without Theme Editor?

With app embed block i can use a deep link but the docs (https://shopify.dev/apps/online-store/theme-app-extensions/extensions-framework#simplified-installat...) pointed out: "Deep linking is compatible only with app embed blocks. You can't deep link to an app block.".

So if it's not possible with app blocks then is there a way to work around this? Any help would be appreciated. Thank you.

Accepted Solution (1)

Neli2404
Shopify Partner
13 1 2

This is an accepted solution.

Since Shopify documentation never fully explains anything and whenever I ask no one answer, I have to find solutions to every Shopify problem myself (real pain). This is no exception.

To solve this, first, you deploy your app blocks and add it manually using Theme Editor. Then you go to the "Edit code" section in your Theme, go to "product.json", and scroll down til you find the App Blocks property (really easy to identify because the name of the property is a really long id). 

 

Then to activate it automatically, copy that property, duplicate the product.json using Asset API, and also use Asset API to add that property to that duplicate file (remember to add the property's name to the block_order property as well). Finally, assign the product template to that product.json duplicate template/file. 

 

Why do you have to duplicate the product.json file instead of just editing the file itself? Because Shopify will just reset the code for default files anyway, which is understandable but it doesn't notify you.

View solution in original post

Replies 3 (3)

youshd
Shopify Partner
2 0 1

Why no one answers? Shopify supports redirects me to the forum and here no one answers. Strange!

Neli2404
Shopify Partner
13 1 2

This is an accepted solution.

Since Shopify documentation never fully explains anything and whenever I ask no one answer, I have to find solutions to every Shopify problem myself (real pain). This is no exception.

To solve this, first, you deploy your app blocks and add it manually using Theme Editor. Then you go to the "Edit code" section in your Theme, go to "product.json", and scroll down til you find the App Blocks property (really easy to identify because the name of the property is a really long id). 

 

Then to activate it automatically, copy that property, duplicate the product.json using Asset API, and also use Asset API to add that property to that duplicate file (remember to add the property's name to the block_order property as well). Finally, assign the product template to that product.json duplicate template/file. 

 

Why do you have to duplicate the product.json file instead of just editing the file itself? Because Shopify will just reset the code for default files anyway, which is understandable but it doesn't notify you.

1080
Shopify Partner
297 9 56

@Neli2404  @youshd   have ypu found the solution. 

i have see few of the app that was do the automatic theme app blocked activated.


i can see the app blocked data are store in the theme file /  settings_data.json.