0
  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>
2
  • Have define class name at Observer.php it should be Easylife_Meta_Model_Observer
    – Amit Bera
    Jan 11, 2016 at 7:01
  • I add the class. But no effect again. Can you test it please? My observer.php now: <?php class Easylife_Meta_Model_Observer { public function autoMetaDescription(Varien_Event_Observer $observe) { $_address = $observer->getEvent()->getCustomerAddress(); } if (!$_address->hasDataChanges()) { return $this; } $_customer = $_address->getCustomer(); $_customer->setUpdatedAt(Varien_Date::now()) ->save(); } ?>
    – Tommy
    Jan 12, 2016 at 11:38

1 Answer 1

0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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