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 Answer
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
-
This is answer is for Magento1, Do you have the full code for Magento2 ?– Jsparo30Feb 13, 2018 at 7:54