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

  • Do have any specific condition to give the custom discount? or for all orders – Hitesh Oct 25 '18 at 11:46
  • yes,you are right.There is a specific condition when customer fill form then we are giving 3% discount to that customer(who fill-up the form) – sumeet bajaj Oct 25 '18 at 11:49
  • can you go through this one, maybe something you missed – Hitesh Oct 25 '18 at 11:50
  • @Hit's i add other snapshot(updated) after try your link getting in negative row total. Here i am giving 10% and 3% discount – sumeet bajaj Oct 25 '18 at 12:47

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;

To -

foreach($quote->getAllItems() as $item){
    $item->setDiscountAmount(($item->getDiscountAmount()+$ratdisc) * $item->getQty());
    $item->setBaseDiscountAmount(($item->getBaseDiscountAmount()+$ratdisc) * $item->getQty())->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.