Hi all,
I’m planning the build for an app I’d like to install on multiple stores across multiple organisations via a publicly (unlisted) deployed/distributed app, and I’m trying to determine if Shopify Functions is the best tool for the job.
The purpose of the app is to allow merchants to build Gift With Purchase Campaigns (GWP) that wouldn’t interfere with other automatic discounts set up natively on the store (such as a free shipping discount, or a discount code) with the GWP criteria being a simple “Spend X, Get Y Free” set up. The Y would only need to be a specifically set productVariant selected by the merchant, the X a monetary amount.
I begun with spinning up a Remix Template App using a product_discount templated extension for a Shopify Function, and have gotten as far as applying a discount to a specific product variant when the spend threshold is met. Which is great. However, I can’t find a successful way to achieve a cart add from within the function. The Storefront API is only accessible if we choose a custom distribution which limits us to one organisation, and any attempts to use the Cart AJAX API with a node HTTP client such as Axios fall short because once compiled to web assembly with Javy we’re unable to add items to the event queue/event loop.
I can’t seem to find any similar projects on the web to see if there are solutions I can learn from, and this impasse has me thinking I’m trying to make a square peg fit a round hole, so I figured I’d ask plain and simple:
Is my goal of creating an app that can be publicly unlisted for distribution across multiple organisations that can add an item to a user’s cart automatically and then discount said item achievable/feasible with Shopify Functions?
If it’s a case of using the storefront API on a custom distributed application, where would I invoke a mutation for the storefront API? Again the compilation to web assembly prevents use of async so I can’t really post a mutation inside the function once a set condition’s been met.
Any help is greatly appreciated!
- Paul