0

My condition: Selected Payment Gateway Eligible only for a selected customer group, id 9.

My observer:

<?php
class Gta_FilterPaymentGateway_Model_Observer
{
    public function paymenter(Varien_Event_Observer $observer)
    {
        $currentCustomerGroup = (int)Mage::getSingleton('customer/session')->getCustomerGroupId();
        if(Mage::getSingleton('customer/session')->isLoggedIn())
        {
            if (($observer->getMethodInstance()->getCode() == 'paytm_cc') && ($currentCustomerGroup !== 9)) 
            {
                $result = $observer->getResult();
                $result->isAvailable = false;
            }
        }
    }
}

Here i can set PayTM payment Gateway only for customer group 9, but guest customer also eligible to pay via PayTM payment gateway, how to restrict for guest customer also?

2 Answers 2

0

I had a similar issue on magento 2.4 but I fixed it by using HTTPcontext instead of sessions. I don't know, for some reason sessions don't return expected customer group, probably some kind of cache issue. However, it works smoothly with HTTPcontext. But unfortunately, there's a difference in implementation of Magento1.x and Magento2.x. If you want, I can share 2.x code with you that uses dependency injection of HTTPcontext to get things done. :)

8
  • Yes, I did in Magento 2 - Code: paste.ofcode.org/f7ndd7CaQGsrSeGcciKzyd Now i am looking for Magento 1.
    – zus
    Oct 29, 2020 at 9:44
  • In your code on Magento 2, you've used customerSession, not httpContext. In my case, customerSession was returning customer_group_id of logged in customer, even when customer was logged out. I used httpContext, and this issue was resolved. I'd suggest you to check customer_group on different pages, and see if it's working fine, otherwise, perhaps, use httpContext not session. Oct 29, 2020 at 9:57
  • Yes, i tested thoroughly even proxy browser its working, any help in Magento 1?
    – zus
    Oct 29, 2020 at 9:59
  • I just updated my post
    – zus
    Oct 29, 2020 at 11:13
  • 1
    There's no problem with your condition, it's a problem with session object since it doesn't return expected customer group on every page, what I said in my answer. That's why you need to print_r($currentCustomerGroup);exit; in your observer to see if it return 0 for logout customer or not. That's the only way to check if your session is working fine or not. Oct 29, 2020 at 12:58
0

you can try following way ..

<?php 
//GET SESSION DATA
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));
$customer_data = Mage::getModel('customer/customer')->$session->id);

//CHECK IF LOGGED IN
if($session->isLoggedIn()){
    // here your logic
} 
2
  • The guest customer's group ID is 0, in my code how can include in if condition if (($observer->getMethodInstance()->getCode() == 'paytm_cc') && ($currentCustomerGroup !== 9) && ($currentCustomerGroup == 0)) Not wokring. Any help thanks
    – zus
    Oct 29, 2020 at 12:21
  • My complete code: paste.ofcode.org/39vAiy2GEcAZQ8vkzEuSHGy FYI My observer working but also working for Guest i want to restrict this.
    – zus
    Oct 29, 2020 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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