1

We want to hide particular payment method if subtotal is zero.

We are giving 100% discount for some products, so that if customers try to buy those products, then I want to hide some custom payment method [code: hdfc]

  • It's magento default functionality. You need to configure from payment configuration settings 'Minimum Order Total'. – Sohel Rana Jul 20 '16 at 9:27
  • @SohelRana Thanks for reply, unfortunately we are using custom payment method. – Baby in Magento Jul 20 '16 at 9:28
  • No problem then, Please add a option to system.xml. Magento will automatically handle this. – Sohel Rana Jul 20 '16 at 9:33
  • @BabyinMagento: check answer for setting Minimum Order Total. – Anil Suthar Jul 20 '16 at 9:42
  • @AnilSuthar Thanks a lot, i am trying your answer and i am sure it will work. – Baby in Magento Jul 20 '16 at 9:47
2

You can add min_order_total setting in system.xml :

<fields>
....

<min_order_total>
    <label>Minimum Order Total</label>
    <frontend_type>text</frontend_type>
    <sort_order>98</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>0</show_in_store>
</min_order_total>
....
</fields>

Now you can see a Text box in admin Minimum Order Total, set it's value to 1. So this method will not be shown for all orders below order total of 1.

OR if you want to disable payment method programatically, use below code :

Magento provides the isAvailable() method in the model of the each payment method. This method tell Magento if the corresponding payment method is available or not for checkout.

Step 1 : Open the config.xml in your custom module and do following changes:

<config>
 <global>
  <!-- Rewrite the Purchase order model -->
  <payment>
   <rewrite>
    <method_purchaseorder>Myproject_Mymodule_Model_Method_Purchaseorder</method_purchaseorder>
   </rewrite>
  </payment>
 </global>
</config>

Step 2 : Create the new Model file in your custom module at the location: app/code/local/Myproject/Mymodule/Model/Method/Purchaseorder.php. In this file create the isAvailable() method as:

<?php
class Myproject_Mymodule_Model_Method_Purchaseorder extends Mage_Payment_Model_Method_Purchaseorder
{
 /**
  * Check if payment method is available for use
  * 
  * @param type $quote
  * @return boolean
  */
 public function isAvailable($quote = null) {
  //Here write your logic for enabling/disabling the method
  //if this
   return true;
  //else
   rerturn false;
 }
}

Referenced from here : Dynamically Enable/Disable Payment Method

1

Override your below form base folder to your theme,

frontend/base/default/template/checkout/onepage/payment/methods.phtml

and here you put the condition subtotal, For example, I have disabled some payment method for some customer which have customer group id = 1 so,

<?php
if(Mage::getSingleton('customer/session')->isLoggedIn()){
    $customerData = Mage::getSingleton('customer/session')->getCustomer();
    $customerId = $customerData->getId();
    $customerCollection =  Mage::getModel('customer/customer')->load($customerId);
}
 ?>
<dt id="dt_method_<?php echo $_code ?>">
<?php if(!$oneMethod):?>
    <?php if($_code == "checkmo"){ ?>
        <input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->escapeHtml($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio"  <?php if($customerCollection->getGroupId() == 1){ ?>disabled<?php } ?> />
    <?php }else{ ?>
        <input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->escapeHtml($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
    <?php } ?>
<?php else: ?>
    <span class="no-display"><input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" checked="checked" class="radio" /></span>
    <?php $oneMethod = $_code; ?>
<?php endif; ?>
    <label for="p_method_<?php echo $_code ?>"><?php echo $this->escapeHtml($this->getMethodTitle($_method)) ?> <?php echo $this->getMethodLabelAfterHtml($_method) ?></label>
</dt>
<?php if ($html = $this->getPaymentMethodFormHtml($_method)): ?>
<dd id="dd_method_<?php echo $_code ?>">
    <?php echo $html; ?>
</dd>

So here you put your condition of subtotal.

Hope this will help you.

1

You can add an observer to payment_method_is_active event an add your logic there ...

<payment_method_is_active>
    <observers>
        <disable_paypal_express>
            <class>[module]/observer</class>
            <method>disablePaypalExpress</method>
        </disable_paypal_express>
    </observers>
</payment_method_is_active>

Observer.php

public function disablePaypalExpress(Varien_Event_Observer $observer)
{
    if (Mage::app()->getFrontController()->getAction()->getFullActionName() == 'checkout_cart_index') {
        return;
    }

    $method = $observer->getMethodInstance();
    if ($method->getCode() == 'paypal_express') {
        # your code here
        if (your_check) {
            $result = $observer->getResult();
            $result->isAvailable = false;
        }
    }
}

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.