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 to solve the problem. But there is no effect if i click the save button in the customer account / adressbook in the frontend.

Easylife_Meta.xml

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

Observer.php

<?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();
}
?>

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>

3 Answers 3

0

Replace code in Observer.php file

From

<?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();
}
?>

To

<?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(now())->save();
    }
}
?>
3
  • If i click the SAVE button i get this error: Fatal error: Call to a member function getEvent() on a non-object in /app/code/local/Easylife/Meta/Model/Observer.php on line 6
    – Tommy
    Jan 12, 2016 at 13:12
  • updated ans pls check now
    – Abdul
    Jan 12, 2016 at 13:28
  • if i click SAVE now the site is loding and loading... After 2 or 3 minutes i get this error massage
    – Tommy
    Jan 12, 2016 at 18:32
0

@Abdul

Click on the save button and the page is loading get this magento error minutes... Then i get an error message. Can you help me please?

Error Log

There has been an error processing your request
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away, query was: SELECT `main_table`.* FROM `design_change` AS `main_table` WHERE (store_id = :store_id) AND (date_from <= :required_date or date_from IS NULL) AND (date_to >= :required_date or date_to IS NULL)

Trace:
#0 /homepages/16/d280867927/htdocs/dev-brand-top/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /homepages/16/d280867927/htdocs/dev-brand-top/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#3 /homepages/16/d280867927/htdocs/dev-brand-top/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT `main_ta...', Array)
#4 /homepages/16/d280867927/htdocs/dev-brand-top/lib/Varien/Db/Adapter/Pdo/Mysql.php(504): Zend_Db_Adapter_Pdo_Abstract->query('SELECT `main_ta...', Array)
#5 /homepages/16/d280867927/htdocs/dev-brand-top/lib/Zend/Db/Adapter/Abstract.php(756): Varien_Db_Adapter_Pdo_Mysql->query(Object(Varien_Db_Select), Array)
#6 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Model/Resource/Design.php(179): Zend_Db_Adapter_Abstract->fetchRow(Object(Varien_Db_Select), Array)
#7 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Model/Design.php(62): Mage_Core_Model_Resource_Design->loadChange('1', NULL)
#8 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Model/App/Area.php(162): Mage_Core_Model_Design->loadChange('1')
#9 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Model/App/Area.php(124): Mage_Core_Model_App_Area->_initDesign()
#10 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Model/App/Area.php(92): Mage_Core_Model_App_Area->_loadPart('design')
#11 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Model/App.php(789): Mage_Core_Model_App_Area->load()
#12 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Controller/Varien/Action.php(512): Mage_Core_Model_App->loadArea('frontend')
#13 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Controller/Front/Action.php(69): Mage_Core_Controller_Varien_Action->preDispatch()
#14 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Customer/controllers/AddressController.php(49): Mage_Core_Controller_Front_Action->preDispatch()
#15 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Controller/Varien/Action.php(407): Mage_Customer_AddressController->preDispatch()
#16 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('formPost')
#17 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#18 /homepages/16/d280867927/htdocs/dev-brand-top/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#19 /homepages/16/d280867927/htdocs/dev-brand-top/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#20 /homepages/16/d280867927/htdocs/dev-brand-top/index.php(83): Mage::run('', 'store')
#21 {main}
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 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.