Magento – Zero Subtotal Checkout – Hide All Other Payment Methods

magento-1.8paymentpayment-methods

At the moment I have Paypal and Zero Subtotal Checkout payment methods enabled.

If the basket is €0 then Zero Subtotal Checkout will display however Paypal is displayed underneath it.

Whats the best way to hide all other payment methods besides from Zero Subtotal Checkout if the basket is €0

Best Answer

Do this using event observer.....create an event on payment_method_is_active and depends on grandtoatal group disable and enable payment method:

See there.Implementing payment method per currency

And you need change on observer.

  <?php
    class Bh_ZeroSubtotalpaymentmethod_Model_Observer {

        public function filterpaymentmethod(Varien_Event_Observer $observer) {
            /* call get payment method */
        $method = $observer->getEvent()->getMethodInstance();

    $quote = $observer->getEvent()->getQuote();
    /* this condition will disable rest of  payment method if grandtotal  <= 0 */
        if($method->getCode()!='free' && (Mage::app()->getStore()->roundPrice($quote->getGrandTotal())<=0))
        {   

            $result = $observer->getEvent()->getResult();   
            $result->isAvailable = false;

            return;
        }
    /* this condtion prevent zero payment to display when grandtotal greater then 0 */
        if($method->getCode()=='free'){
            $quote = $observer->getEvent()->getQuote();
            if(Mage::app()->getStore()->roundPrice($quote->getGrandTotal())>0){
            $result = $observer->getEvent()->getResult();   
            $result->isAvailable = false;
            return;
            }
        }
        return;
      }
    }
Related Topic