Magento如何在选择特定送货方式时删除付款选项

Magento如何在选择特定送货方式时删除付款选项

问题描述:

How can I remove a specific payment option when a specific shipping method is checked?

An example would be: If i select the "Free International Shipping" the "Cash" paymend option must be removed or inactive.

如果选中特定的送货方式,如何删除特定的付款方式? p>

一个例子是: 如果我选择“免费国际航运”,则必须删除或停用“现金”付款选项。 p> div>

I think you can do using observer. First of all you have to create one module(I'm assuming you already know how to create module)

In your config.xml from app>code>your_codepol>Namespace>module>etc>config.xml

<frontend>
    <events>
        <payment_method_is_active>
            <observers>
                <paymentfilter_payment_method_is_active>
                    <type>singleton</type>
                    <class>YOUR_CLASS_observer</class>
                    <method>paymentMethodIsActive</method>
                </paymentfilter_payment_method_is_active>
            </observers>
        </payment_method_is_active>
    </events>
</frontend>

and create your observer and write this code in your observer.php

public function paymentMethodIsActive(Varien_Event_Observer $observer) {
    $event           = $observer->getEvent();
    $method          = $event->getMethodInstance();
    $result          = $event->getResult(); 
$quote  = $observer->getEvent()->getQuote();
$shippingMethod = $quote->getShippingAddress()->getShippingMethod();
   if($shippingMethod=="Free International Shipping"){
        if($method->getCode() == 'cashondelivery' ){ // to hide this method
            $result->isAvailable = false; // false means payment method is disable
        }
}

}

Where cashondelivery is payment method name. You can write any payment name like

  1. ccsave(Credit Card (saved))
  2. checkmo(Check / Money order)
  3. purchaseorder(Purchase Order)
  4. banktransfer(Bank Transfer Payment)
  5. cashondelivery(Cash On Delivery) etc..

Let me know if you have any query