如何禁用特定产品类型的货到付款


9

基本上,我需要禁用特定产品类型的货到付款。基本上我使用法师商店的商店信用。这是给magento中的钱包的。在付款方式上显示货到付款。它不是物理或虚拟产品。因此,我需要禁用此产品类型的货到付款。

Answers:


11

你可以这样做 Magento Event/Observer

首先,使用payment_method_is_active禁用取决于当前报价产品类型。

代码如下:

模块config.xml代码:

<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;
            }
        }
    }

}

ahed gr8 work dude @amit仅2分钟
Keyur Shah

@Amit Bera如何在这里获得产品类型
Deepak Rai

@DeepakRai,已经放置了代码。使用$ item-> getProductType()来获取商品的产品类型
阿米特·贝拉

4

为此,您需要使用magento payment_method_is_active事件

我假设你知道如何开发Magento的扩展[如果没有,那么请检查这个答案你会得到整个模块 编写代码在你config.xmlapp>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;
                }

        }

    }

我可以在这里获得帮助吗magento.stackexchange.com/q/301777/57334 @Keyur Shah
zus

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.