Magento-OnePage Checkout-根据付款方式隐藏付款方式 [英] Magento - OnePage Checkout - Hide Payment method depending on Shipping Method

查看:129
本文介绍了Magento-OnePage Checkout-根据付款方式隐藏付款方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Magento Stackexchange 没有任何成功,因此我现在在这里问.

I have asked this question on Magento Stackexchange without any success, hence me now asking here.

我使用的是Magento Community Edition 1.9.0.1,并且已经正确创建并注册了我的模块,但是我似乎无法检测到运输方式.基本上,如果选择了平价免费送货,我想隐藏货到付款.这是我的观察者类的代码:

I'm using Magento Community Edition 1.9.0.1 and have correctly created and registered my module, but I can't seem to detect the shipping methods. Basically, I want to hide Cash on Delivery if Flat Rate or Free Shipping is chosen. Here is the code I have for my observer class:

class Kol_PaymentToggle_Model_Observer
{
    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 == "standardshipping" || $shippingMethod == "free") {
            if($method->getCode() == 'cashondelivery' ) {
                $result->isAvailable = false;
            }
        }
    }
}

我猜我没有使用正确的送货方式代码名称或付款方式代码名称,但不确定.有人有什么建议吗?

I'm guessing that I haven't used the correct shipping method code names or payment method code names, but I'm unsure. Anyone has any advice?

我只启用了3种送货方式:

I only have 3 shipping methods enabled:

  • 在商店中收集
    标题=在商店中收集
    方法名称=在商店中收集(
  • Collect In Store
    Title = Collect in Store
    Method Name = Collect In Store (Extension link)
  • Flat Rate
    Title = Standard Delivery
    Method Name = Standard Shipping
  • Free Shipping
    Title = Free Delivery
    Method Name = Free

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Kol_PaymentToggle>
            <version>0.0.1</version>
        </Kol_PaymentToggle>
    </modules>
    <frontend>
        <events>
            <payment_method_is_active>
                <observers>
                    <paymentfilter_payment_method_is_active>
                        <type>singleton</type>
                        <class>Kol_PaymentToggle_Model_Observer</class>
                        <method>paymentMethodIsActive</method>
                    </paymentfilter_payment_method_is_active>
                </observers>
            </payment_method_is_active>
        </events>
    </frontend>
</config>

希望这些额外的信息对帮助我很有帮助!

Hopefully this extra information can prove useful towards helping me!

推荐答案

据我所知,您试图隐藏一些基于送货方式的付款方式.为此,您根本不需要观察任何事物.只需跟随我,您就可以做到这一点,

As for I got, you trying to hide some payment methods based on shipping method. For this you don't need to observe things at all. Simply you can do this, just follow me,

所有方法(一页签出)将选择的方法发布到下一个级别.因此您可以在付款方式级别获得选择的送货方式.只需在

Every methods(in one page check out) post the methods which are chosen to the next level. so you can get the shipping method which are chosen, in payment method level. Just print the post things in

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

在此添加项下面,

<?php print_r($_POST); ?>

因此,现在您可以获取上一步选择的送货方式.请注意,所以现在,您可以在同一文件中添加简单的逻辑条件(如果有的话)以隐藏付款,

So now you can get the shipping methods which are chosen previous step. And note it, so now, you can add just simple logic (if else) condition in same file for hiding payment,

例如,如果运送方式为flat,我想隐藏check / money order付款方式.此处的付款方式代码为checkmo.您只需在同一个文件中打印该变量(如echo $_code = $_method->getCode();)即可获得付款方式代码.所以在这里添加简单的else

For example here I want hide check / money order payment method, if shipping method is flat. Here the payment method code is checkmo. you can get payment method code by simply printing that variable like echo $_code = $_method->getCode(); in same file. so here just add simple if else ,

  <?php
    $methods = $this->getMethods();


    $oneMethod = count($methods) <= 1;
?>
<?php if (empty($methods)): ?>
    <dt>
        <?php echo $this->__('No Payment Methods') ?>
    </dt>
<?php else:
    foreach ($methods as $_method):
       echo  $_code = $_method->getCode();


if($_POST['shipping_method'] == 'flatrate_flatrate') {
if($_code == 'checkmo') {
    continue;
}
}
?>

在这里

 if($_POST['shipping_method'] == 'flatrate_flatrate') {
if($_code == 'checkmo') {
    continue;
}
}

检查运输方式,并跳过我们不想显示的付款方式.而已.如果您有任何疑问,请在这里发表评论.

checks the shipping method and skip the payment method which we don't want to display. That's it. Please comment here if you have any doubt.

注意:

 shipping_method => flatrate_flatrate
 paymet_method   => checkmo

这篇关于Magento-OnePage Checkout-根据付款方式隐藏付款方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆