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
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024