5

When user add those SKUs [items] to cart then I want to allow only some particular payment methods.

4
+50

Try this code:

I have not incuded cart items code in my observer. using this observer you can set is-available to false.

app\code\local\Dmage\Dev\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Dmage_Dev>
            <version>0.1.0</version>
        </Dmage_Dev>
    </modules>
    <global>
        <models>
            <dev>
                <class>Dmage_Dev_Model</class>
            </dev>
        </models>
    </global>
    <frontend>
        <events>
            <payment_method_is_active>
                <observers>
                    <paymentfilter_payment_method_is_active>
                        <type>singleton</type>
                        <class>dev/observer</class>
                        <method>paymentMethodIsActive</method>
                    </paymentfilter_payment_method_is_active>
                </observers>
            </payment_method_is_active>
        </events>
    </frontend>
</config> 

app\code\local\Dmage\Dev\Model\Observer.php

class Dmage_Dev_Model_Observer
{
    public function paymentMethodIsActive(Varien_Event_Observer $observer)
    {
        $event           = $observer->getEvent();
        $method          = $event->getMethodInstance();
        $result          = $event->getResult();

        $skuTrue = 0; //Sku flag is off

        if ($skupresent) {
            $skuTrue=1;
        }

        if ($method->getCode() == 'checkmo' && $skuTrue) {
            $result->isAvailable = false;
        }
        return;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy