0

Following code return customer group, how to add condition if customer group "Tester" then only show selected payment gateway?

app\etc\modules\Gta_FindPaymentGateway.xml

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

app\code\local\Gta\FindPaymentGateway\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Gta_FindPaymentGateway>
            <version>1.0.0</version>
        </Gta_FindPaymentGateway>
    </modules>
    <global> 
        <models>
            <gta_findpaymentgateway>
                <class>Gta_FindPaymentGateway_Model</class>
            </gta_findpaymentgateway>
        </models> 
        <events>
            <checkout_cart_product_add_after>
                <observers>
                    <Gta_FindPaymentGateway_Model_Observer>   
                        <type>singleton</type>
                        <class>Gta_FindPaymentGateway_Model_Observer</class>
                        <method>paymenter</method>
                    </Gta_FindPaymentGateway_Model_Observer>
                </observers>
            </checkout_cart_product_add_after>      
        </events>
    </global> 
</config>

app\code\local\Gta\FindPaymentGateway\Model\Observer.php

<?php
    class Gta_FindPaymentGateway_Model_Observer
    {
        public function paymenter($Observer)
        {
            if(Mage::getSingleton('customer/session')->isLoggedIn())
            {
                // Get group Id
                $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();

                //Get customer Group name
                $group = Mage::getModel('customer/group')->load($groupId);

                 Mage::log($group->getCode(),null,'filter.log',true);
            }
        }
    }
?>
4
  • Observer, and it's better to add your customer to customer_group then you filter that payment methods per customer_group, with this you can add more customers to this feature, maybe in the future. you can follow this magento.stackexchange.com/a/33055/48355 – PЯINCƏ Jan 21 '20 at 12:53
  • please try with this - Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getMethodInstance()->getTitle(); using before place order. – Anas Mansuri Jan 22 '20 at 9:42
  • Before that how to test my observer working or not? magento.stackexchange.com/q/301862/57334 – zus Jan 22 '20 at 9:44
  • @AnasMansuri Code : justpaste.it/4b37d can i get help – zus Jan 27 '20 at 11:58

Your Answer

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

Browse other questions tagged or ask your own question.