Magento 1.9 version Custom discount is not working
-
05-02-2021 - |
Pergunta
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.
Solução
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();
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange