2
  1. Login to the frontend in a customer account.
  2. Click on "Account information" and edit some information (firstname or lastname). Click on the save button.

Now go to the magento backend and click on customers -> manage customers. Now you see the grid with the correct "updated_at" timestamp.

  1. Login to the frontend in a customer account.
  2. Click on "Account information"
  3. 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.

How can we set new updated_at timestamp for the address book also?

2

Both the customer_entity as well as the customer_address_entity table have their own updated_at column. This means those two values will be updated independent from each other. The easiest is probably to trigger an update of the customer entity data.

Create a new module and add an observer on the customer_address_save_after event:

<config>
    <modules>
        <YourName_Customer>
            <version>0.0.1</version>
        </YourName_Customer>
    </modules>
        <models>
            <yourname_customer>
                <class>YourName_Customer_Model</class>
            </yourname_customer>
        </models>
        <events>
            <customer_address_save_after>
                <observers>
                    <customer_address_save_after_update_customer>
                        <class>yourname_customer/observer</class>
                        <method>afterAddressSave</method>
                    </customer_address_save_after_update_customer>
                </observers>
            </customer_address_save_after>
        </events>
    </global>
</config>

Then create YourName/Customer/Model/Observer.php and add the afterAddressSave function:

class YourName_Customer_Model_Observer {

    /**
     * Save customer after customer address update
     *
     * @param Varien_Event_Observer $observer
     */
    public function afterAddressSave($observer) {
        /** @var $customerAddress Mage_Customer_Model_Address */
        $customerAddress = $observer->getCustomerAddress();
        $customer = $customerAddress->getCustomer();
        $customer->setHasDataChanges(true);
        $customer->save();
    }
}

If the update of the customer data does not work, you might consider adding $customer->setSomeNonExistentProperty(true); to the observer function.

Note: The code above is not tested. It might needs some improvement to get it running.

0
0

I solve the problem. But i will check your code. Thank you!

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>

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.