【发布时间】:2014-12-23 14:49:30
【问题描述】:
我在Magento Stackexchange 上问过这个问题,但没有成功,所以我现在在这里问。
我正在使用 Magento Community Edition 1.9.0.1 并且已正确创建并注册了我的模块,但我似乎无法检测到运输方式。基本上,如果选择统一费率或免费送货,我想隐藏货到付款。这是我的观察者类的代码:
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 种送货方式:
-
店内取货
标题 = 店内取货
方法名称 = 店内取货 (Extension link) -
统一费率
标题 = 标准配送
方法名称 = 标准配送 -
免费送货
标题 = 免费送货
方法名称 = 免费
编辑 2: 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>
希望这些额外的信息对我有所帮助!
【问题讨论】:
-
你能告诉我代码是在哪个事件中触发的吗?
-
嗨,阿米特。它旨在在人们必须选择付款方式的地方触发单页结帐。
-
抱歉,您的意思是代码中的事件,对吗?在此模块的 config.xml 中,事件称为
payment_method_is_active,观察者称为paymentfilter_payment_method_is_active -
@Amit:编辑我的帖子以包含
config.xml输出 -
你能知道payment_method_is_active事件上的paymentMethodIsActive函数吗?
标签: php magento payment shipping onepage-checkout