I have a custom category attribute called passcode and it is unique for every category. (with the help of this tutorial

When a customer logins (there is an addition field in the login.phtml for the passcode which will be stored in a session variable), magento will only display that specific category which has the entered passcode.

I have already created a custom field in the login.phtml and hooks it to customer login action (here is the link) how can I redirect customer to that specific category only which has the same passcode with the customer entered one?

The customer will only see the entered passcode category and its products, and not be able to see any other category and products.

1 Answer 1


I have found the solution and here it is:

public function customerLogin(Varien_Event_Observer $observer) {
    $login = Mage::app()->getRequest()->getParam('login');
    $passcode = $login['passcode'];
    $session = Mage::getSingleton('customer/session');

    $categories = Mage::getResourceModel('catalog/category_collection');
    $categories->addAttributeToFilter('is_active', 1);
    $categories->addAttributeToFilter('passcode', $passcode);

    if ($categories->getFirstItem()) {
        $category = $categories->getFirstItem();

        if (strpos(Mage::helper('core/http')->getHttpReferer(), 'checkout') === false)


    else {
        echo 'No category exists with the name ' . $name;

public function customerLogout(Varien_Event_Observer $observer) {
    $session = Mage::getSingleton('customer/session');

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.