1

It is required to have some session variables set when customer visit store for first time, or his session was expired and renewed.

For existing customer it is possible to listen to customer_customer_authenticated event and when customer logs in - and add variable to core/sessionsingleton with observer, but how to deal with the guest user (or new registered customer ) ?

The main goal is to set some session variables when customer session is initiated, if the customer visits store for the first time, or its session was expired and reinitiated.

( From this session variables some layered filter defaults will be set, if the guest customer - one filter, if logged in - another filter - based on attributes of this customer, etc. But if session exists for him, let him to customize his layered filters in catalog area. )

How to accomplish this task ?

Thanks

1 Answer 1

0

You can use visitor_init event defined in Mage_Log_Model_Visitor.

Just create an observer on it and grab the session:

<?xml version="1.0"?>
<config>
    ...
    <frontend>
        ...
        <events>
            ...
            <visitor_init>
                <observers>
                    <my_module>
                        <class>my_module/observer</class>
                        <type>singleton</type>
                        <method>visitorInit</method>
                    </my_module>
                </observers>
            </visitor_init>
            ...
        </events>
        ...
    </frontend>
</config>

And in your observer:

<?php
class My_Module_Model_Observer {
    public function visitorInit($observer) {
        ...
    }
}

I would suggest you to use core/session rather than customer/session for what you need to do. custoemr/session will be erased after login/logout.

Hope it helps.

2
  • Thank you Riccardo, this is exactly i was looking for !!!
    – Ilja
    Commented Apr 25, 2016 at 19:28
  • You are welcome ;) Stack Exchange is here for that ;) Commented Apr 25, 2016 at 19:58

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.