Hi,

I've been trying for the past few hours to figure out a way to stop the percentage discount applying to shipping line items. I've been working in rules to loop through all the line items, but then can't figure out a way to use the redeeming coupon action, but that action only seems to apply to the entire order regardless of any calculations you work out previously.

I've looked through the code and also can't see a way to make this only apply to product line item types.

Could anyone help with this please? Our client won't sign off the site until this is fixed hence the major issue.

Thanks in advance

Comments

pcambra’s picture

Category: support » bug
Priority: Major » Normal

I'd call this a bug report. We should control that kind of stuff by rules, I was pending on a Commerce commit but I'll provide a workaround before that happens.

ajaysolutions’s picture

Ok, that sounds great. Do you know when you'll be able to provide the workaround?

Is there anything we can do or help with in the meantime?

pcambra’s picture

The steps for the workaround are:

- Create an event for coupons on line item refresh hook of commerce.
- Move all the refresh elements to that event, instead of using the hook directly so people will have 2 rules, one for redeem and one for refresh.

Related:
#1547440: Kill coupon log entity
#1475118: Rules support for cart line item and order refresh
#1413126: Commerce coupons roadmap

ajaysolutions’s picture

Could you please explain how we go about implementing that? As it sounds like we really need to be waiting on a patch for this module?

generalconsensus’s picture

Wanted to mention that this is causing problems with taxing as it is being applied to the subtotal pre-discounted subtotal... I would like to open access to the data value of the subtotal order with and without discounts etc. No idea where to start unfortunately.

#3 is rather confusing, pcambra can you elaborate?

generalconsensus’s picture

Status: Active » Needs review
Issue tags: +patch
StatusFileSize
new11.28 KB

I was just recently trying to figure this problem out and I realized that the issue might be that we need a different kind of action for applying a percentage coupon against an order total. This is just the first part we still need for the coupon percentage to be visible and actionable by the rule 'commerce_coupon_action_create_coupon_line_item'. That I have yet to figure out.

generalconsensus’s picture

StatusFileSize
new12.69 KB

Ok ignore the above patch. The patch included will allow you to apply percentage coupons just to the subtotal but still requires you to add the item created to the commerce-order:commerce-coupon-order-reference list. Included is the patch and the exported rule I used for it. Let me know what folks think

Here is the exported rule:

{ "commerce_coupon_pct_percent_amount" : {
    "LABEL" : "Calculate coupon with percentage amount",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "commerce_coupon_pct", "commerce_coupon" ],
    "ON" : [ "commerce_coupon_redeem" ],
    "IF" : [
      { "data_is" : {
          "data" : [ "coupon:type" ],
          "op" : "=",
          "value" : "commerce_coupon_pct"
        }
      },
      { "entity_has_field" : { "entity" : [ "coupon" ], "field" : "commerce_coupon_percent_amount" } },
      { "NOT AND" : [
          { "data_is_empty" : { "data" : [ "coupon:commerce-coupon-percent-amount" ] } }
        ]
      },
      { "entity_has_field" : {
          "entity" : [ "commerce_order" ],
          "field" : "commerce_coupon_order_reference"
        }
      },
      { "data_is" : {
          "data" : [ "coupon:commerce-coupon-percent-amount" ],
          "op" : "\u003E",
          "value" : 1
        }
      },
      { "data_is" : { "data" : [ "coupon:is-active" ], "op" : "=", "value" : true } }
    ],
    "DO" : [
      { "list_add" : {
          "list" : [ "commerce-order:commerce-coupon-order-reference" ],
          "item" : [ "coupon" ],
          "unique" : 1
        }
      },
      { "commerce_coupon_pct_apply_to_total" : {
          "USING" : {
            "coupon" : [ "coupon" ],
            "commerce_order" : [ "commerce_order" ],
            "component_name" : [ "coupon:price-component-name" ],
            "round_mode" : "1"
          },
          "PROVIDE" : { "commerce_coupon_pct_line_item" : { "commerce_coupon_pct_line_item" : "commerce coupon percent line item" } }
        }
      }
    ]
  }
}
MaherSakka’s picture

@ajaysolutions: Did you resolve your problem ?

essbee’s picture

I like this addition. I far prefer to have the discount applied as part of the totals rather than affecting all individual line items throughout the order.

My only issues is that the taxes, and the ex-tax subtotal dont reflect the discount.

So i have
Subtotal $100
Tax (10%) $10
Discount (20%) -$22
Total $88
The total is correct and the discount is correct but the tax amount is wrong as it no longer reflects 1/11 of the final total

It should be

Discount -$22
Subtotal $80
Tax $8
Total $88

Does anyone know how I reorder the items and push the tax calculation to the correct spot

pcambra’s picture

Status: Needs review » Needs work

The patch above in #7 is really hard to review as it has a lot of changes regarding spacing and it needs a reroll.

Anyways, I don't think that we should just remove the pct discount per line item to move it to order basis, it should be at most an option there.

essbee’s picture

I'm not sure on the whole discount per line item. Would definitely like to see it as at minimum and option, and to be honest I think it makes more sense to be the default option.

I really can't think of a receipt/invoice that I have received where a coupon percentage discount was applied throughout on each line item. The norm seems to be a single line item stating the discount amount. That is unless it is a coupon that applies to a specific set of products - but thats a whole other kettle of fish.

arun_ms’s picture

Hello all,

i am also having the same problem. I dont want to include shipping cost in coupon calculation. Can anyone please suggest me a solution.

Thanks all

pcambra’s picture

mrpeanut’s picture

@generalconsensus I applied your patch and tried to import your rule, but am getting this error:

Integrity check for the imported configuration failed. Error message: Unknown action commerce_coupon_pct_apply_to_total..

I, too, would like to apply the discount to the order total, not the individual line items. Are you still doing that?

yatil’s picture

StatusFileSize
new27.26 KB

Hi there,

good to see that this is a topic here. I find the display rather confusing.

The prices are displayed with discount applied (33,90€) but then the Subtotal (Zwischensumme) is back referring to the original price point (but this time without VAT), then subtracting the discount again, adding VAT and Shipping.

As far as I can see it makes the correct math, I’d just like to see the full price in the individual rows instead of the discounted one.

Cheers, Eric

yatil’s picture

Oh, just found out you can ignore the discount by editing the view, select a price field, chose price by components from the drop down and check base price and VAT.

avpaderno’s picture

Issue summary: View changes
Issue tags: -patch +Needs reroll