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

Agl*_*nci 1 php magento

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

一个例子是:如果我选择"免费国际航运",必须删除或不活动"现金"付款选项.

Key*_*hah 5

我想你可以用observer.首先,你必须创建一个模块(我假设你已经知道如何创建模块)

在你config.xmlapp>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>
Run Code Online (Sandbox Code Playgroud)

并创建您的观察者并在您的代码中编写此代码 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
        }
}
Run Code Online (Sandbox Code Playgroud)

}

cashondelivery付款方式名称在哪里.您可以写任何付款名称,如

  1. ccsave(信用卡(已保存))
  2. checkmo(支票/汇票)
  3. purchaseorder(采购订单)
  4. 银行转账(银行转账付款)
  5. cashondelivery(货到付款)等..

如果您有任何疑问,请告诉我