3

Can anyone explain me how and where I can customize the add to cart button functionality based on the current customer group? I’d like to show a popup or redirect to a CMS page but only for a specific customer group.

Any help will be much appreciated!

Thanks in advance! Damian

2
  • which magento version ? from where you want to redirct (controller/phtml)?
    – Pawan
    Commented Aug 11, 2018 at 1:07
  • Sorry I forgot that detail... I’m using version 1.9 and not sure if controller or phtml, which one would you recommend? The only important detail is that every add to cart button must behave the same way. Thanks!
    – Damil
    Commented Aug 11, 2018 at 1:14

1 Answer 1

1

You can check first customer is logged in or not, If logged in get customer Group. based on group you can Pop Up message.

$login = Mage::getSingleton('customer/session')->isLoggedIn(); //Check if User is Logged In
if($login)
{
    $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); //Get Customers Group ID

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

    $groupName = $group->getCode();

    if($groupName == 'General'){

    //Here should be Pop up code

    }
}

Edit I: If you want to redirect to CMS page you can use:

Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl().'contacts');

Edit II :

If you want to replace add to cart button based on customer group you can edit below file:

[magento_root]/app/design/frontend/[package]/[theme]/template/catalog/product/view/addtocart.phtml

You can put above code in your phtml file where you want to check customer group.

3
  • I understand, but how do I find out which phtml file I need to use? That’s were I’m quite lost.
    – Damil
    Commented Aug 11, 2018 at 1:57
  • please see updated answer
    – Pawan
    Commented Aug 11, 2018 at 2:03
  • Welcome @DamianLobalzo :)
    – Pawan
    Commented Aug 11, 2018 at 2:59

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.