cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate Discount against unit price not line total. Is this possible

Calculate Discount against unit price not line total. Is this possible

I'm running into a rounding issue when parsing magento orders to invoices out of my ERP system to be inclusive of the discount.  Is there a way I can configure the coupon discount to be calculated against the unit Price and then multiplied out by qty. 

 

Eg Magento sends this.

MyProduct x 390 units @   $1.55 = $604.50  less 15% (90.675)

                                                              = $513.825 total value

                                               MyProduct            =  $1.3175 each

 

but it hits my ERP system it gets rounded to $1.32 and then total value goes to  $514.80…..

 

I think this is because For the discount,  Magento is using total line price $604.50 x 15 % = $90.68

Not unit price - $1.55 x 15% = $0.23 X 390 = $89.70……if we get $89.70 then that will work for EDI in our ERP,

ie we can calculate the Unit Price as TotalPrice/Qty  …….$514.80/390 = $1.32 unit price

I hope this makes sense, Any ideas of

1 REPLY 1

Re: Calculate Discount against unit price not line total. Is this possible

There is no configuration in Magento about that behavior.

I think what you need to do is to override

app/code/Magento/SalesRule/Model/Rule/Action/Discount/ByPercent.php

In method _calculate there are 

$discountData->setAmount(($qty * $itemPrice - $item->getDiscountAmount()) * $_rulePct);
$discountData->setBaseAmount(($qty * $baseItemPrice - $item->getBaseDiscountAmount()) * $_rulePct);
$discountData->setOriginalAmount(($qty * $itemOriginalPrice - $item->getDiscountAmount()) * $_rulePct);
$discountData->setBaseOriginalAmount(
            ($qty * $baseItemOriginalPrice - $item->getBaseDiscountAmount()) * $_rulePct
        );

and there you can try to change calculation to get price rounded based on unit price and then multiply it by $qty