Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Magento-一页签出-根据发货方式隐藏付款方式_Php_Magento_Payment_Shipping_Onepage Checkout - Fatal编程技术网

Php Magento-一页签出-根据发货方式隐藏付款方式

Php Magento-一页签出-根据发货方式隐藏付款方式,php,magento,payment,shipping,onepage-checkout,Php,Magento,Payment,Shipping,Onepage Checkout,我曾经问过这个问题,但没有成功,因此我现在在这里问 我使用的是Magento Community Edition 1.9.0.1,并且已经正确创建和注册了我的模块,但是我似乎无法检测到运送方法。基本上,如果选择了统一费率或免费送货,我想隐藏货到付款。下面是我的observer类的代码: class Kol_PaymentToggle_Model_Observer { public function paymentMethodIsActive(Varien_Event_Observer

我曾经问过这个问题,但没有成功,因此我现在在这里问


我使用的是Magento Community Edition 1.9.0.1,并且已经正确创建和注册了我的模块,但是我似乎无法检测到运送方法。基本上,如果选择了统一费率或免费送货,我想隐藏货到付款。下面是我的observer类的代码:

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;
            }
        }
    }
}
我猜我没有使用正确的运输方式代码名或付款方式代码名,但我不确定。有人有什么建议吗

编辑: 我只启用了3种配送方式:

  • 店内收款
    Title=店内收款
    方法名称=店内收款()
  • 统一费率
    标题=标准配送
    方法名称=标准配送
  • 免费送货
    标题=免费送货
    方法名称=免费
编辑2: config.xml的输出


0.0.1
独生子女
Kol_PaymentToggle_Model_Observer
付款方式有效

希望这些额外的信息能对我有所帮助

至于我得到的,你试图隐藏一些基于发货方式的付款方式。因此,你根本不需要观察事物。只要你能做到,就跟我来

每个方法(在一页签出中)将选择的方法发布到下一个级别。因此,您可以在付款方式级别获得所选的装运方式。只需把帖子打印出来

app/design/frontend/base/default/template/checkout/onepage/payment/methods.phtml
在这下面加上一句

<?php print_r($_POST); ?>
这里,

 if($_POST['shipping_method'] == 'flatrate_flatrate') {
if($_code == 'checkmo') {
    continue;
}
}
检查装运方式并跳过我们不希望显示的付款方式。就这样。如果您有任何疑问,请在此发表评论

注意:

 shipping_method => flatrate_flatrate
 paymet_method   => checkmo

除了@Simbus82提供的一页签出IWD解决方案之外:

$shipping = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod();

foreach ($methods as $_method): 
        $_code = $_method->getCode(); 
        if ( $shipping == 'matrixrate_matrixrate_140' or $shipping == 'matrixrate_matrixrate_148' ) { 
            if($_code != 'cashondelivery') { 
                continue;   
            } 
        }
虽然可行,但它不是一个优雅的解决方案,因为它提示我们检查phtml文件中的post数据,这不是一个好方法。相反,你应该寻找一个事件来完成这项工作

幸运的是,我们有一个完美的事件来完成这项工作,那就是
付款方法\u处于活动状态
。请看


基本上,您需要通过此方法将付款方式设置为非活动状态,正如您在回答中所看到的。

您能告诉我在哪种情况下代码为fire吗?您好,阿米特。这意味着在用户必须选择付款方式的一页结账时触发。对不起,您是指代码中的事件,对吗?在此模块的config.xml中,事件被称为
付款方法\u处于活动状态
,观察者被称为
paymentfilter\u payment\u method\u is\u active
@Amit:Edited my post以包含
config.xml
output您能告诉我您将要使用paymentMethodIsActive函数进行支付\u method\u is\u active事件吗?@Elvarasan:谢谢!我知道我应该改为修改PHTML。更有意义。我将覆盖子主题的PHTML请求:我将粘贴到哪里
Elvarasan,你是明星!工作得很漂亮。即使我返回几个步骤并选择不同的运送方式,它也会更新。不需要检查Mage签出会话或类似的出色解决方案。谢谢Elavarasan。如果我有来自IWD的一页签出,我的所有步骤都在同一页中,所以我不能使用POST。如何在此methods.phtml中包含shipping\u method/available.phtml中的数组$\u shippingRateGroups?如果我能得到这个,我可以做这样的检查
。。。foreach($methods as$\u method):$\u code=$\u method->getCode();如果(array_key_exists('freeshipping',$_shippingRateGroupsCheck)){if($_code=='msp_cashondelivery'){continue;}}}…
很抱歉恢复了这篇旧文章。我应该把这个代码放在哪里?在哪个文件里?我完全同意。在模板文件中进行此类检查不是最佳做法。如果主题发生变化,它也不会起作用
 shipping_method => flatrate_flatrate
 paymet_method   => checkmo
$shipping = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod();

foreach ($methods as $_method): 
        $_code = $_method->getCode(); 
        if ( $shipping == 'matrixrate_matrixrate_140' or $shipping == 'matrixrate_matrixrate_148' ) { 
            if($_code != 'cashondelivery') { 
                continue;   
            } 
        }