Solved

Shopify plus script: Line Item, is there away to access a json file?

Codesto1
Shopify Partner
26 3 3

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.  

Accepted Solution (1)

playwright-mike
Shopify Partner
72 18 33

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

Playwright | Create Shopify Scripts without writing code | https://playwrightapp.com
- Was my reply helpful? Please Like and Accept Solution.

View solution in original post

Reply 1 (1)

playwright-mike
Shopify Partner
72 18 33

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

Playwright | Create Shopify Scripts without writing code | https://playwrightapp.com
- Was my reply helpful? Please Like and Accept Solution.