禁用特定产品的付款选项-仅货到付款-magento [英] Disable payment options-only cash on delivery for particular product-magento
问题描述
我使用的是 Magento 1.4.1.1,我想禁用某些产品的付款选项.我只想显示某些产品的货到付款方式,而需要隐藏其他方式.
I am using Magento 1.4.1.1 and i want to disable payment option for some products.i want to show only Cash on Delivery method for some products and need to hide other.
有任何机构可以帮助我吗?我该如何管理?管理员是否有任何选项,或者我是否需要自定义代码.如果是这样,能否请您提供代码和文件的确切路径?
Any body there to help me?How can i manage this?Is there any option at admin or do i need to customize the code.If so,could you please provide me a code and the exact path to the files?
提前致谢.
推荐答案
一种不显眼的过滤支付方式的方式是为名为 payment_method_is_active
的事件实现观察者步骤
1> 在 config.xml 中注册事件:‘payment_method_is_active’.在 app/code/local/MagePsycho/Paymentfilter/etc/config.xml 中添加以下 xml 代码:
An unobtrusive way of filtering payment method is to implement observer for event called payment_method_is_active
Steps
1> Register the event: ‘payment_method_is_active’ in config.xml.
Add the following xml code in app/code/local/MagePsycho/Paymentfilter/etc/config.xml:
...
<global>
...
<events>
<payment_method_is_active>
<observers>
<paymentfilter_payment_method_is_active>
<type>singleton</type>
<class>paymentfilter/observer</class>
<method>paymentMethodIsActive</method>
</paymentfilter_payment_method_is_active>
</observers>
</payment_method_is_active>
</events>
...
</global>
...
2> 实现观察者模型创建观察者文件:app/code/local/MagePsycho/Paymentfilter/Model/Observer.php 并粘贴以下代码:
2> Implement the observer model Create observer file: app/code/local/MagePsycho/Paymentfilter/Model/Observer.php and paste the following code:
<?php
/**
* @category MagePsycho
* @package MagePsycho_Paymentfilter
* @author magepsycho@gmail.com
* @website http://www.magepsycho.com
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class MagePsycho_Paymentfilter_Model_Observer {
public function paymentMethodIsActive(Varien_Event_Observer $observer) {
$event = $observer->getEvent();
$method = $event->getMethodInstance();
$result = $event->getResult();
$currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
if($someTrueConditionGoesHere){
$result->isAvailable = true;
}else{
$result->isAvailable = false;
}
}
}
这篇关于禁用特定产品的付款选项-仅货到付款-magento的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!