9

Basically I need to disable cash on delivery on specific product type. Basically i m using store credit of mage store. This is for wallet in magento. on payment option its showing cash on delivery . its a not a physical or virtual product. So i need to disable cash on delivery on this product type.

11

You can do this by Magento Event/Observer

First,using payment_method_is_active disable on depends current quote product type.

Code for this:

Module config.xml code:

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

Observer code is:

<?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();

        /* 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;
            }   
        }
    }
}
  • just 2 min ahed gr8 work dude @amit – Keyur Shah May 15 '15 at 6:45
  • @Amit Bera how to get product type here – Deepak Rai May 15 '15 at 6:48
  • @DeepakRai,already code has been put.use $item->getProductType() for get Item product type – Amit Bera May 15 '15 at 6:52
4

for that you need to use magento payment_method_is_active event

I am assuming you know how to develop magento extension[If not then please check this answer you get whole module Write this code in your config.xml from 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>

Create observer file 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;
                }

        }

    }
1

Have you look this I think this would bee solve your issue you just need to modify the methods.phtml file andfrom where you can got any quotes info and do the validations or conditions as well from the module by event - observer or by the modification in phtml file ?

https://stackoverflow.com/questions/29819037/disable-cash-on-delivery-for-specific-products

and

https://stackoverflow.com/questions/14011348/disable-payment-options-only-cash-on-delivery-for-particular-product-magento

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.