0

I tried a few iterations and for whatever reason I can't add cookies or even execute any code from my observer, as it's not giving anything even if my observer has dies in it. I have my module visible on the list and enabled, there are no exceptions in the exception.log.

This is my xml file where observer define

app/code/local/MyProject/Cookie123/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MyProject_Cookie123>
            <version>1.0.0</version>
        </MyProject_Cookie123>
    </modules>
    <global>
        <models>
            <Cookie123>
                <class>MyProject_Cookie123_Model</class>
            </Cookie123>
        </models>
        <events>
            <customer_login>
                <observers>
                    <MyProject_Cookie123>
                        <type>model</type>
                        <class>MyProject_Cookie123_Model_Observer</class>
                        <method>customerLogin</method>
                    </MyProject_Cookie123>
                </observers>
            </customer_login>
            <customer_logout>
                <observers>
                    <MyProject_Cookie123>
                        <type>model</type>
                        <class>MyProject_Cookie123_Model_Observer</class>
                        <method>customerLogout</method>
                    </MyProject_Cookie123>
                </observers>
            </customer_logout>
            <controller_front_send_response_before>
                <observers>
                    <MyProject_Cookie123>
                        <type>model</type>
                        <class>MyProject_Cookie123_Model_Observer</class>
                        <method>sendResponse</method>
                    </MyProject_Cookie123>
                </observers>
            </controller_front_send_response_before>
        </events>
    </global>
</config>

This is my Observer file:-

app/code/local/MyProject/Cookie123/Model/Observer.php

<?php

class MyProject_Cookie123_Model_Observer
{

    public function customerLogin($observer)
    {
        Mage::getModel('core/cookie')->set('testing_auth', 1);
    }

    public function customerLogout($observer)
    {
        Mage::getModel('core/cookie')->delete('testing_auth');
    }

    public function sendResponse($observer)
    {
        Mage::getModel('core/cookie')->set('test_123', 1);

        $cartItems = Mage::helper('checkout/cart')->getItemsQty();
        if ($cartItems > 0) {
            Mage::getModel('core/cookie')->set('testing_cart', 1);
        } else {
            if (Mage::getModel('core/cookie')->get('testing_cart')) {
                Mage::getModel('core/cookie')->delete('testing_cart');
            }
        }
    }

}
1

change your config to following move your events to frontend tag & gave unique event ids:- app/code/local/MyProject/Cookie123/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MyProject_Cookie123>
            <version>1.0.0</version>
        </MyProject_Cookie123>
    </modules>
    <global>
        <models>
            <Cookie123>
                <class>MyProject_Cookie123_Model</class>
            </Cookie123>
        </models>

    </global>
    <frontend>
        <events>
            <customer_login>
                <observers>
                    <myproject_cookie123_customerlogin>
                        <type>model</type>
                        <class>MyProject_Cookie123_Model_Observer</class>
                        <method>customerLogin</method>
                    </myproject_cookie123_customerlogin>
                </observers>
            </customer_login>
            <customer_logout>
                <observers>
                    <myproject_cookie123_customerlogout>
                        <type>model</type>
                        <class>MyProject_Cookie123_Model_Observer</class>
                        <method>customerLogout</method>
                    </myproject_cookie123_customerlogout>
                </observers>
            </customer_logout>
            <controller_front_send_response_before>
                <observers>
                    <myproject_cookie123_sendresponse>
                        <type>model</type>
                        <class>MyProject_Cookie123_Model_Observer</class>
                        <method>sendResponse</method>
                    </myproject_cookie123_sendresponse>
                </observers>
            </controller_front_send_response_before>
        </events>
    </frontend>
</config>

Your Answer

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

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