Passing external values into a script

mfs-mindsize
Excursionist
20 0 5

Currently, we have a hardcoded value in a script. For example, order total must be $50 or more for  ____ to happen. The 5000 is hardcoded. We'd like the be able to have a setting somewhere in the Shopify admin dashboard - that the client can access - so the $50 can be changed to something else without having to modify the actual script. 

 

Is this possible? I've looked for examples and can't find anything. 

 

Are there any other ways in Shopify to define business rules and enforce them? And allow some shop owner flexibility? 

 

 

0 Likes
Mircea_Piturca
Shopify Partner
1459 39 284

If you are referring to Shopify Scripts https://help.shopify.com/en/manual/apps/apps-by-shopify/script-editor, then no.

Scripts have a limited input for good reasons. Security would be one

Finally—Add variant descriptions to your products
0 Likes
mfs-mindsize
Excursionist
20 0 5

At Mircea - Thanks.

 

fwiw, this isn't really a sec issue. Certainly, the "receiving" script could and should do some validation. That is, if I'm expecting an INT between X and Y, I can test for that, yes; as all good functions/methods do :)

 

The alternative to that is to have to manually edit the script every time there needs to be a change. Which we'd all agree also involves risk :) 

 

Scripts are helpful. But without the ability to pass in simple basic args, they feel overly-limited and thus compromise their usefulness. 

0 Likes
Mircea_Piturca
Shopify Partner
1459 39 284

You can pass data to Scripts as cart line items properties. You could pass a string in there...

As this happens on frontend, anyone can pass or alter that data. Not safe to use.

 

I also feel that there should be a broader I/O on Scripts. Some data from settings schema would be nice to have there.

Finally—Add variant descriptions to your products
0 Likes
mfs-mindsize
Excursionist
20 0 5

Thanks again. 

 

Yeah, we just need to pass in some simple settings. 

 

p.s. If you have examples (read: links) on how to pass from the frontend, please share. tua

0 Likes