Answers:
你可以这样做 Magento Event/Observer
首先,使用payment_method_is_active
禁用取决于当前报价产品类型。
代码如下:
<global>
<events>
<payment_method_is_active>
<observers>
<paymentfilter_payment_method_is_active>
<type>singleton</type>
<class>yourmodel/observer</class>
<method>filterpaymentmethod</method>
</paymentfilter_payment_method_is_active>
</observers>
</payment_method_is_active>
</events>
</global>
<?php class YOURNANESPACE_YOURMODULE_Model_Observer { public function filterpaymentmethod(Varien_Event_Observer $observer) { /* call get payment method */ $method = $observer->getEvent()->getMethodInstance(); /* get Quote */ $quote = $observer->getEvent()->getQuote(); $result = $observer->getEvent()->getResult(); if (empty($quote) || (null === $quote)) { return $this; } /* Disable Your payment method for adminStore */ if ($method->getCode() == 'YOUR_PAYMENT_METHOD_CODE') { foreach ($quote->getAllItems() as $item) { // get Cart item product Type // if ($item->getProductType() == 'YourProductType'): $result->isAvailable = false; endif; } } } }
为此,您需要使用magento payment_method_is_active
事件
我假设你知道如何开发Magento的扩展[如果没有,那么请检查这个答案你会得到整个模块
编写代码在你config.xml
从app>code>codepool>namespace>package>etc
<global>
...
<events>
<payment_method_is_active>
<observers>
<paymentfilter_payment_method_is_active>
<type>singleton</type>
<class>PaymentFilter_Model_Observer</class>
<method>paymentMethodIsActive</method>
</paymentfilter_payment_method_is_active>
</observers>
</payment_method_is_active>
</events>
...
</global>
创建观察者文件 app/code/codepool>namespace>package/Model/Observer.php
class namespace_package_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;
}
}
}
您是否看过我认为这可以解决您的问题,您只需要修改methods.phtml文件,就可以从那里获取任何报价信息,并可以通过事件(观察者)或通过对其中的修改从模块中进行验证或条件phtml文件?
/programming/29819037/disable-cash-on-delivery-for-specific-products
和
/programming/14011348/disable-payment-options-only-cash-on-delivery-for-particular-product-magento