Personalized checkout and custom promotions with Shopify Scripts
Currently I have a script under Script Editor / Line Items / Bulk discounts.
The current documentation on scripts only allows for payment api and shipping api so I'm a little confused if this is even possible.
Is there away where I can pass data to the line item script using an asset file?
in example:
def tier_items(name)
myJsonData = {{ 'custom-scripts.js.liquid' | asset_url }}
return [
{
quantity: 1,
discount_type: :dollar,
discount_amount: 0.01,
discount_message: message_display(1, name),
},
The Ruby file kicks out an error since it's not liquid.
Solved! Go to the solution
This is an accepted solution.
Hey @Codesto1 , unfortunately you cannot use liquid code inside of a Shopify Script. Think of a Shopify Script as a special Ruby script which runs in a locked-down area and evaluates a restricted set of APIs before loading the steps of the checkout screen. Also, due to memory, computation, and timing restrictions, you cannot make network calls to load outside resources (like your json file).
You can however define some objects at the top of your Shopify Script and reference them later. You can see that in many of the examples that Shopify provides. But unfortunately those object definitions need to be fully contained in your script.
Lastly, some people find ways of doing fancy things using line item properties and/or metafields. But perhaps you could explain a bit more about exactly what scenario you are trying to solve for? It may help generate some more specific suggestions.
I hope that was helpful,
Matthew
This is an accepted solution.
Hey @Codesto1 , unfortunately you cannot use liquid code inside of a Shopify Script. Think of a Shopify Script as a special Ruby script which runs in a locked-down area and evaluates a restricted set of APIs before loading the steps of the checkout screen. Also, due to memory, computation, and timing restrictions, you cannot make network calls to load outside resources (like your json file).
You can however define some objects at the top of your Shopify Script and reference them later. You can see that in many of the examples that Shopify provides. But unfortunately those object definitions need to be fully contained in your script.
Lastly, some people find ways of doing fancy things using line item properties and/or metafields. But perhaps you could explain a bit more about exactly what scenario you are trying to solve for? It may help generate some more specific suggestions.
I hope that was helpful,
Matthew
User | RANK |
---|---|
4 | |
2 | |
1 | |
1 | |
1 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023