Shopify Script: undefined method 'rejected?'

Solved
Highlighted
Tourist
7 1 0
undefined method 'rejected?' for #<CartDiscount::FixedAmount:0x7fa11970ace0>

I get the above error message in my shipping script, but in your documentation, the claim is that the "rejected" method does not exist. Here is the salient snippet in my script:

free_shipping_code = false
if Input.cart.discount_code
  puts Input.cart.discount_code.code
  code = Input.cart.discount_code
  if not code.rejected? and 'BNL-103' == code.code
    free_shipping_code = true
  end
end

My goal is to determine if my customer has successfully applied a discount code "BNL-103" in the cart.

0 Likes
Highlighted
Shopify Staff
Shopify Staff
493 98 88

This is an accepted solution.

Hi @bestrada 

 

Looking at the specifics here, it appears this is a visual bug but the script is infact working. The best workaround for the time being is to publish the script and preview on the storefront. 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes
Highlighted
Tourist
7 1 0

@vix do you mind checking again? I already tried running my script in production and your tools yielded the same error under "Production errors":

undefined method 'rejected?' for #<CartDiscount::FixedAmount:0x7fb151602a40>

this also failed in my test store, you can see it here: https://contoso-fashion.myshopify.com/admin/apps/d25e45407e508f96409c2dd796e9bd95/scripts/81428546/e...

I am reluctant to activate this script with actual errors on my production site because it will affect my real customers.

the error is still therethe error is still there

0 Likes
Highlighted
Tourist
7 1 0

This is an accepted solution.

to those who have browsed this post looking for a solution, I received a direct email with the answer:

 

Hi Bryan,

Jon L. from the Shopify Plus Support Frontend Development team here. We’ve received the question that Hamish submitted on your behalf about the Input.cart.discount_code.rejected? method not working in Shipping Scripts.

After doing some testing we've confirmed that the reject and rejected? methods are currently not available in Shipping Scripts, though they are available in Line Item Scripts, and have reported this to our technical teams so that it can either be fixed or the documentation updated to show the methods as unavailable in Shipping Scripts. It does seem most likely that these methods will be moved to the 'Line Item Scripts only' section of the documentation.

When a discount code is rejected by a Line Item Script, Shipping Scripts don't see any Input.cart.discount_code object at all even though the discount code still shows in the checkout view as rejected. With this in mind, the solution would be to set up the Shipping Script without the .rejected? check and only check for the existence of the discount_code object as well as that the discount_code.code matches the code you're looking for.

0 Likes