doukai2839 2014-05-05 15:11
浏览 13
已采纳

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.

  • 写回答

1条回答 默认 最新

  • douding6266 2014-05-05 16:44
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题