1

I need to create a simple custom payment method like "cash on delivery" but with extra fee when customer selects it. I implemented payment method, but can't find how to make part with extra fee. Can anybody give me a hint?

1
  • explain in more detail.. what do you mean by extra fee ? if you want this payment method along or with existing one ? – lalit mohan Oct 17 '16 at 9:52
1

I found this article how to add custom fee and only added couple changes to collect() function, like this:

public function collect(Mage_Sales_Model_Quote_Address $address)
{
    parent::collect($address);
    try{
        $quote = $address->getQuote();
        $code = $quote->getPayment()->getMethodInstance()->getCode();
        if($code == 'my_payment'){
                $this->_setAmount(0);
                $this->_setBaseAmount(0);
                $items = $this->_getAddressItems($address);
                if (!count($items)) {
                    return $this; 
                }

                $exist_amount = $quote->getFeeAmount();
                //$fee = Excellence_Fee_Model_Fee::getFee(); 
                $fee=Mage::getStoreConfig('payment/my_payment/price');
                $balance = $fee - $exist_amount;
                $address->setFeeAmount($balance);
                $address->setBaseFeeAmount($balance);
                $quote->setFeeAmount($balance);
                $address->setGrandTotal($address->getGrandTotal() + $address->getFeeAmount());
                $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseFeeAmount());
        }
    } catch(Exception $e){}
}

Now only when user selects my payment method this fee would be added to totals

1
  • This is answer is for Magento1, Do you have the full code for Magento2 ? – Jsparo30 Feb 13 '18 at 7:54

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.