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

时间:2014-05-05 15:11:01

标签: php magento

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

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

1 个答案:

答案 0 :(得分:5)

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

来自config.xml

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>

并创建您的观察者并在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
        }
}

}

cashondelivery是付款方式名称。您可以写任何付款名称,如

  1. ccsave(信用卡(已保存))
  2. checkmo(支票/汇票)
  3. purchaseorder(采购订单)
  4. 银行转账(银行转账付款)
  5. cashondelivery(货到付款) 等。
  6. 如果您有任何疑问,请告诉我