Question

I am using these 2 observers -

1 - sales_quote_collect_totals_after

2 - sales_order_place_before

Custom discount(which is 3%) is working fine when customer do order from Cash on delivery but customer pay via online then it is not working.

I am using USAePay payment method.

Note:Discount(10% using coupon code) is working fine for both cash on delivery and USAePay payment.

enter image description here

enter image description here

Was it helpful?

Solution

I solved my problem,the problem is wrong calculations here - So changed from -

foreach ($quote->getAllItems() as $item) {
    $rat = $item->getPriceInclTax() / $total;
    $ratdisc = $discountAmount * $rat;
    $item->setDiscountAmount(($item->getDiscountAmount()));
    $item->setBaseDiscountAmount($item->getBaseDiscountAmount())->save();
}

To -

foreach($quote->getAllItems() as $item){
    $rat=$item->getPriceInclTax()/$total;
    $ratdisc=$discountAmount*$rat;
    $item->setDiscountAmount(($item->getDiscountAmount()+$ratdisc) * $item->getQty());
    $item->setBaseDiscountAmount(($item->getBaseDiscountAmount()+$ratdisc) * $item->getQty())->save();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top