Question

  1. Login to the website frontend in a customer account. Click on "Account information" and edit some information (firstname, lastname, ...). Click on the save button. Now login to the magento backend and click on customers -> manage customers. Now you see the grid with the correct "updated_at" timestamp.

  2. Login to the website frontend again. Click on "Account information" And now click on "Addressbook" and edit some information. Click on the save button. Now go to the magento backend and click on customers -> manage customers. Updated_at is not changed.

Now i have a observer. But there is no effect if i click the save button in the customer account / adressbook in the frontend.

How i can set new updated_at timestamp for the address book also:

Easylife_Meta.xml

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

Observer.php

<?php
function autoMetaDescription(Varien_Event_Observer $observer)
{
$_address = $observer->getCustomerAddress();
if (!$_address->hasDataChanges())
{
return $this;
}
$_customer = $_address->getCustomer();
$_customer->setUpdatedAt(Varien_Date::now())
->save();
}
?>

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Meta>
            <version>0.0.1</version>
        </Easylife_Meta>
    </modules>
    <global>
        <models>
            <easylife_meta>
                <class>Easylife_Meta_Model</class>
            </easylife_meta>
        </models>
    </global>
    <frontend>
        <events>
            <customer_address_save_after><!-- observe the event -->
                <observers>
                    <easylife_meta>
                        <class>easylife_meta/observer</class>
                        <method>autoMetaDescription</method>
                    </easylife_meta>
                </observers>
            </customer_address_save_after>
        </events>
    </frontend>
</config>
Was it helpful?

Solution

I solve the problem now.

observer.php

<?php
class Easylife_Meta_Model_Observer 
{
    public function autoMetaDescription(Varien_Event_Observer $observer)
    {
        $address = $observer->getCustomerAddress();
        if (!$address->hasDataChanges()) {
            return $this;
        }

        $customer = $address->getCustomer();
        //$_customer = Mage::getModel('customer/customer')->load($customer->getId());
        //$_customer->setUpdatedAt(Varien_Date::now());
        //$_customer->save();


        try
        {
            $read = Mage::getSingleton('core/resource')->getConnection('core_read'); 
            $write = Mage::getSingleton('core/resource')->getConnection('core_write');
            $connection = Mage::getSingleton('core/resource');
            $customerTable = $connection->getTableName('customer_entity');
            $write->update($customerTable, array("updated_at" => Varien_Date::now()), "entity_id=".$customer->getId());         
        }
        catch(Exception $e)
        {
            // $e->getMessage();
        }

    }

}
?>

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Meta>
            <version>0.0.1</version>
        </Easylife_Meta>
    </modules>
    <global>
        <models>
            <easylife_meta>
                <class>Easylife_Meta_Model</class>
            </easylife_meta>
        </models>
    </global>
    <frontend>
        <events>
            <customer_address_save_after>
                <observers>
                    <easylife_meta>
                        <class>easylife_meta/observer</class>
                        <method>autoMetaDescription</method>
                    </easylife_meta>
                </observers>
            </customer_address_save_after>
        </events>
    </frontend>
</config>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top