How to get Discount Percent
-
16-10-2019 - |
Question
I am looking for a way to get the discount percent of an order, possibly from the order class or the invoice class, it would be amazing if
$order->getDiscountPercent();
worked, but it doesn't, any ideas on how I can pull the discount percent from either the order class or the invoice class?
Solution
As far as I know, there is no way of doing this. All discounts are calculated in $insertAnyCurrency
. Therefore you have two ways, if you want this:
SalesRule
There is a $order->getCouponRuleName()
. But I don't know whether this is everytime filled. With this field you can (very fuzzy) get the rules and from the rules the percentages
discount / grandtotal
You can just calculate the percentage from the discount. But this is very fuzzy too and I'm not sure, wether you need it with or without shipping and with or without tax.