Quantcast
Viewing all articles
Browse latest Browse all 5

Conditional payment methods

Sometimes you may have a condition on the availability of a payment method. For example most, or all, payment methods should not be available when the grandtotal is 0.00. This was also the case for a client of ours, due to some client requirements it was possible to have a subtotal of zero, and the delivery cost could also be zero, so the grandtotal also became zero. This however caused an error in one of our remote payment providers, which of course didn’t accept a payment of zero euros.

As you can see, Magento already has a standard “Zero subtotal checkout” payment method, which only gets displayed when the grandtotal is zero. Checking the code of this payment method, Mage_Payment_Model_Method_Free, reveals the following method:

public function isAvailable($quote = null)
{
    return parent::isAvailable($quote) && (!empty($quote))
    && (Mage::app()->getStore()->roundPrice($quote->getGrandTotal()) == 0);
}

This method determines, based on the quote, if the payment method is available, as the name already suggests. Of course you could also add this method to your own payment method, changing the “== 0″ to “> 0″ and the payment method will only be visible when the grandtotal is more than zero. Of course the criteria could be as complex as you want, as long as it can be based on the quote. You could for example only display a certain payment method based on the shipping method (cash on delivery, for example).


Viewing all articles
Browse latest Browse all 5

Trending Articles