0

I have an observer event that should get the customer when a customer is updated and write it to a var log

my config

<?xml version="1.0"?>
<config>
    <modules>
        <Mage_Customerupdate>
            <version>0.0.1</version>
        </Mage_Customerupdate>
    </modules>
    <global>
        <models>
            <Mage_Customerupdate>
                <class>Mage_Customerupdate_Model</class>
            </Mage_Customerupdate>
        </models>
        <events>
            <customer_save_after>
                <observers>
                    <Mage_Customerupdate>
                        <type>singleton</type>
                        <class>Mage_Customerupdate_observer</class>
                        <method>logUpdate</method>
                    </Mage_Customerupdate>
                </observers>            
            </customer_save_after>
        </events>
    </global>
</config>

My module

<?xml version="1.0"?>
<config>
    <modules>
        <Mage_Customerupdate>
            <active>true</active>
            <codePool>local</codePool>
        </Mage_Customerupdate>
    </modules>
</config>

My Observer

<?php
class Mage_Customerupdate_Model_Observer {
    public function logUpdate(Varien_Event_Observer $observer){
        $customer = $observer->getEvent()->getCustomer();
        $name = $customer->getName();
        $telephone = $customer->getTelephone();
        Mage::log("{$name} ({$telephone}) updated", null, 'customerupdate.log');
    }
}

This is my first attempt at using the observer and so far nothing is happening. I will most likely need longer more specific answers as to how I get this to produce the customer information. at this point all I am trying to get is the name and phone number.

closed as off-topic by sv3n, Jai, Manoj Deswal, liyakat, Keyur Shah Feb 3 '18 at 11:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced OR seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – sv3n, Jai, Manoj Deswal, liyakat, Keyur Shah
If this question can be reworded to fit the rules in the help center, please edit the question.

1

I guess there is a typo ... this

<class>Mage_Customerupdate_observer</class>

... should match to ...

<models>
    <Mage_Customerupdate> <!-- alias -->
        <class>Mage_Customerupdate_Model</class>
    </Mage_Customerupdate>
</models>

Try to change it to (full class name)

<class>Mage_Customerupdate_Model_Observer</class>

... or better (alias) ...

<class>Mage_Customerupdate/observer</class>

Edit:

config.xml should look like ...

            <observers>
                <Mage_Customerupdate>
                    <type>singleton</type>
                    <class>Mage_Customerupdate/observer</class> <!-- changed -->
                    <method>logUpdate</method>
                </Mage_Customerupdate>
            </observers> 

For logging use

Mage::log("{$name} ({$telephone}) updated", null, 'customerupdate.log', true);
  • If i understand correctly change the models class to the /observer? – John Burgess Feb 2 '18 at 20:29
  • @JohnBurgess Yes. This should fix it. – sv3n Feb 2 '18 at 20:31
  • So If I logged into magento(frontside) and updated my customer information, something would get written in the var/log/customerupdate.log? – John Burgess Feb 2 '18 at 20:39
  • @JohnBurgess It should, but if you haven't enabled logging in config section, nothing happens. You can force logging with an 4th parameter in Mage::log($msg, $level, $file, -->true<--); Btw ... clear cache after changing config.xml. (Note: change the model class within events node ... not the model declaration itself) – sv3n Feb 2 '18 at 20:43
  • you mean Mage_Customerupdate.xml?? I had changed it in the config.xml – John Burgess Feb 2 '18 at 21:23

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