Prevent Discount Codes from Being Used on Certain Products

Tourist
11 0 1

Wonderful!
Thanks!

0 Likes
New Member
8 0 0

Is this the usage?

Input.cart.reject(:message=>"Discounts applied.")

I get this error:

[Error] undefined method 'reject' for #<Cart:0x7f0acd43a660>
 

0 Likes
Shopify Staff
Shopify Staff
84 0 11

@Andy

In the API reference, you'll notice that the reject is on CartDiscount classes. You'll have to use something like this 

cart = Input.cart

contition_is_met = #magic

if condition_is_met
  cart.discount_code.reject(
    message: "You don't have access to this discount"
  )
end

 

0 Likes
New Member
8 0 0

Thank you, that did the trick!

0 Likes
New Member
8 0 0

Is it possible to have the "message" show in Orange instead of Red?  I'm using it to reject the discount code but apply discounts manually (but I want the user to assume the discount code was what caused the discount).  

0 Likes
Shopify Staff
Shopify Staff
7 0 5

Hi Andy,

It currently isn't possible to run a scripted discount that's dependent on a discount, while at the same time rejecting said discount code. Calling reject on the discount code prevents that discount code from being applied to the cart.

0 Likes
New Member
8 0 0

Yes, I understand.  What I'm doing is seeing that the user entered a discount code, and then manually changing line item prices basing on a custom set of rules, and then rejecting the discount code so that the rules of the discount code aren't also applied.  We had a problem where our custom rules AND the discount code rules were being applied and that wasn't what we were trying to achieve.  My question is mostly if we can have the "message" parameter of the .reject method be a positive message (in orange) rather than a negative message (in red).

 

 

0 Likes
Shopify Staff
Shopify Staff
7 0 5

Oh, understood! :)

Unfortunately, the color currently can't be changed. But that's definitely something that we'll keep in mind while we improve the way things work between Scripts and discount codes.

0 Likes
New Member
8 0 0

Hi all,

We're getting some inconsistent behavior with this.

1.  Discount shows and then disappears.  The store's owner sees this behavior:

https://dl.dropboxusercontent.com/u/2717180/SPEND149.mov

2.  Inconsistency between script editor and live store.  (screenshot attached) When I test it in the script editor, it works perfectly.  But when I test it on the live store, the discount code is not rejected and it applies the normal discount code percentage off.

Is it possible it takes time to propagate to all users?  Has anyone else experience these inconsistencies?

Thanks,

Andy

0 Likes
Shopify Staff
Shopify Staff
7 0 5

Hi Andy,

Can you state what type of discount code you're using and a summary of the conditions of your script? I'd like to look into the issue and recreate the scenario you're encountering.

0 Likes