0

My module is about filtering Payment Method when customer selects one of the shipping methods. Namespace: Insync

Module-Name: Paymentfilter

Config.xml (app/code/local/Insync/Paymentfilter/etc) :

<?xml version="1.0"?>
<config>
<modules>
    <Insync_Paymentfilter>
        <version>1.0</version>
    </Insync_Paymentfilter>
</modules>
<frontend>
    <events>
        <payment_method_is_active>
            <observers>
                <paymentfilter_payment_method_is_active>
                    <type>singleton</type>
                    <class>Insync_Paymentfilter_Model_Observer</class>
                    <method>paymentMethodIsActive</method>
                </paymentfilter_payment_method_is_active>
            </observers>
        </payment_method_is_active>
    </events>
</frontend>
</config>

Observer.php (app/code/local/Insync/Paymentfilter/Model) :

class Insync_Paymentfilter_Model_Observer {

public function paymentMethodIsActive(Varien_Event_Observer $observer) {


$event           = $observer->getEvent();
$method          = $event->getMethodInstance();
$result          = $event->getResult();
$carriers = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod();

        if ($carriers == 'tablerate' ){
                if($method->getCode() == 'checkmo' OR $method->getCode() == 'ccsave'){
                    $result->isAvailable = true;
                }else{
                    $result->isAvailable = false;
                }
            }

         }
}

Insync_Paymentfilter.xml (app/etc/modules)

<?xml version="1.0"?>
<config>
<modules>
    <Insync_Paymentfilter>
        <active>true</active>
        <codePool>local</codePool>
        <version>0.1.0</version>
    </Insync_Paymentfilter>
</modules>
</config>

The purpose of module is when customer selects 'tablerate' as shipping method he would be ONLY given two Payment Methods i.e

Check/Money Order (checkmo)

and

Credit Card (ccsave)

Fufu Tulla
  • 45
  • 1
  • 9
  • what is at the top of your app/etc/modules file? – Smartie Sep 04 '15 at 11:31
  • by "module won't show up" you mean it does nothing or is not picked up by magento? – Marius Sep 04 '15 at 11:31
  • Marius it neither gets showed up in Advanced section nor works. – Fufu Tulla Sep 04 '15 at 11:34
  • did you create the file app/etc/modules/Insync_Paymentfilter.xml? Did you clear the cache? – Marius Sep 04 '15 at 11:50
  • @Marius its already there.read my question i have included all essential files but its not working.can you please check my config.xml to make sure its correct? – Fufu Tulla Sep 04 '15 at 11:55
  • I read the question. I just wanted to make sure. The only reason a module would not appear in the advanced section is that if the file from app/etc/modules is not there or is not readable or is not valid, or if the cache is not cleared. The config.xml can be completely screwed up. If the declaration file app/etc/modules is there and is valid and is readable the rest of the module is not important. It should show up in the advanced section. – Marius Sep 04 '15 at 12:01
  • @Marius You are right. I edited and removed first line from my insync_paymentfilter.xml it now shows up in Advanced section but it does not work the way it is supposed to do.Like when I select tablerate shipping as shipping method i am getting all payment methods intead of just two defined in my observer.php – Fufu Tulla Sep 04 '15 at 12:11
  • so the question itself it solved right? – Julien Lachal Sep 04 '15 at 12:14
  • You can look into the method restrictAdminBillingAgreementUsage in Mage_Sales_Model_Oberver class, you'll get an idea where you are going wrong with this approach, but still try to raise a different question for this condition, as it no longer aligns with the initial question. – Prateek Sep 05 '15 at 14:07

0 Answers0