3

My store have two payment methods, one based on credit card and another bank transfer. If I choose credit card and choose to installments, Magento update subtotal adding taxes.

If I give up to pay with credit card and change to bank transfer (who should't have taxes), the taxes of installments persists. How can I clear installments in this cenary?

I tried to use those events:

  • checkout_type_onepage_save_order_after
  • sales_order_place_after

But it is not triggered when I change the form of payment. Only when saved.

1

I solved creating event sales_model_service_quote_submit_before on ModuleVendor/ModuleName/etc/events.xml:

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_model_service_quote_submit_before">
        <observer name="mpfix" instance="ModuleVendor\ModuleName\Observer\Mpfix" />
    </event>
</config>

And the observer:

<?php

namespace ModuleVendor\ModuleName\Observer;

use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;

class Mpfix implements ObserverInterface {

    public function execute(EventObserver $observer) {
        $order = $observer->getOrder();
        $quote = $observer->getQuote();

        if($order->getPayment()->getMethod() == "payment_method_code"){ //code of payment method 
            $quote->setFinanceCostAmount(0);
            $quote->setBaseFinanceCostAmount(0);
            $quote->save();

            $order->setFinanceCostAmount(0);
            $order->setBaseFinanceCostAmount(0);
            $order->save();
        }
    }

}
| improve this answer | |

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.