How to access Discount Codes

Shopify Expert
3996 14 321

Simple cart with a discount code is selected. Try to run a simple script. 

cart = Input.cart
dc = cart.discount_code

puts "DC: #{dc}"

Output.cart = Input.cart

Generates an error: 

  • Code requirements not met

What am I missing? Why is script editor choking on this simple test? The Code itself is just 50% of products in the cart. 

Would be nice if the error messages included some information about what is exactly missing. Like saying "Discount Code requirements not met" is a lot clearer than your current "Code requirements not met"... leaves me saying WTF is wrong with my code as opposed to the internal discount code has some issues with the cart.

And even worse... when searching inventory for products to test the scripting on, your result sets are often totally incomplete. I see variants that I need to test are not even found by the script editor. This is a huge drag-a-roony... for PLUS customers, seems the effort is just not there yet? 

 

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
1 Like
Highlighted
New Member
13 0 0

I'm getting the same error. Did you ever find a solution to this?

0 Likes
New Member
13 0 0

It's odd my scrip works fine till add anything about the discount_code then it always breaks even if I remove it.

0 Likes
Shopify Expert
3996 14 321

I did figure this out, but I cannot remember what the answer was. Probably something dumb. I do know now that it can be nil, or an object. So it is likely that simple. 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes