Solved

Adding function in existing app

nuethicadam
Shopify Partner
2 0 0

Is there a way to automatically install a shopify function into a store when an app is installed? I have an  existing app that I'd like to replace the clunky buggy system we have now that updates product prices via AJAX and javascript with something that runs in the backend and Scripts are going to be deprecated soon.

Accepted Solution (1)

lizk
Shopify Staff
246 58 71

This is an accepted solution.

Hi there 👋

Is there a way to automatically install a shopify function into a store when an app is installed?

To add a Shopify Function on a store you will need to create a discount object that references your function. You create the discount object with an GraphQL mutation. In your install flow you can make the API call to create the discount object that references your function to activate the function on your store.

I would recommend working through this tutorial. In the tutorial they make the API call with GraphiQL to activate the function, but this can be modified to take place in the installation flow of the app.

It is important to note that to use Shopify Functions with an existing app, your app need to be compatible with the Shopify CLI. 

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Reply 1 (1)

lizk
Shopify Staff
246 58 71

This is an accepted solution.

Hi there 👋

Is there a way to automatically install a shopify function into a store when an app is installed?

To add a Shopify Function on a store you will need to create a discount object that references your function. You create the discount object with an GraphQL mutation. In your install flow you can make the API call to create the discount object that references your function to activate the function on your store.

I would recommend working through this tutorial. In the tutorial they make the API call with GraphiQL to activate the function, but this can be modified to take place in the installation flow of the app.

It is important to note that to use Shopify Functions with an existing app, your app need to be compatible with the Shopify CLI. 

To learn more visit the Shopify Help Center or the Community Blog.