How to select discounted line items

Highlighted
Shopify Partner
2 0 2

Hi, I'm trying to do something in particular only for those line items on cart that are affected by a discount code, but I'm not being able to do it. Based on docs, there's a discounted? property that should pull this off, but it's always returning me false, no matter if the line_item is affected or not. 

 

Has anybody been able to make this happen?

 

 

Thanks!

0 Likes
Highlighted
Shopify Partner
10 0 0

I get the same error where .discounted? always returns false for me even though discounts are applied to that line item. I hit up Shopify to see if I'm misunderstanding something or if it is indeed a bug.

0 Likes
Highlighted
Shopify Partner
38 4 4

Is it a line item script? Have you tried .line_price_changed?

0 Likes
Highlighted
Shopify Partner
10 0 0

discounted?  is based on if the script editor has discounted the line items, not a user applying a discount to the cart via the storefront. I can only hope that they add additional methods to show discounts applied through the storefront.

0 Likes
Highlighted
Shopify Partner
38 4 4

I have a case here where I've applied a discount code that is a fix dollar item discount at the checkout and the .discounted? method returns true for only that item and not for the other items in the cart.

0 Likes
Highlighted
Shopify Partner
10 0 0

@BradKrane I couldn't replicate your case. Could you provide more information?

Did you discount apply to an order, collection or specific products?

 

I made fixed amount & % off discounts for a specific product and discount? still returns false for every single discount type for a specific product.

Input.cart.line_items.each do |item|
      if item.discounted?
        puts "discounted"
      else
        puts "not discounted"
      end
  end
0 Likes
Highlighted
Shopify Partner
38 4 4

@NAVEKI I created a discount code for a fixed dollar amount off of a specific variant then added that and another item to the cart and applied the code at checkout. The item that was discounted's discounted? method responds true after the code application.

0 Likes
Shopify Partner
10 0 0

@BradKrane  I understood that from your last post but I still couldn't replicate your case. Could you provide screenshots or something? Like I said before tried what you said but can't reproduce your functionality. I think you must be doing something else to get discounted? to return a boolean based off of a cart discount - outside of script editor.

 

I'm interested in your case because I received information from Shopify explicitly stating that the discounted? method only regards line items discount applied through script editor - not storefront applied discounts.

0 Likes