Magento: Save admin name to order_status change using an Observer

28. April 2015 at 15:24

php code

config.xml:

<adminhtml>
  <events>
    <sales_order_status_history_save_before>
      <observers>
        <module_status_history_save_before>
          <class>module/observer</class>
          <method>addUserNameBeforeComment</method>
        </module_status_history_save_before>
      </observers>
    </sales_order_status_history_save_before>
  </events>
</adminhtml>

Observer.php:

public function addUserNameBeforeComment($observer)
{
        $data = '<strong>' . Mage::getSingleton('admin/session')->getUser()->getFirstname() . ' ' . Mage::getSingleton('admin/session')->getUser()->getLastname() . ': </strong>';
        $history = Mage::app()->getRequest()->getPost('history');
        if ($history && isset($history['comment']) && $history['comment'] != '') {
            $history['comment'] = $data . $history['comment'];
            Mage::app()->getRequest()->setPost('history', $history);
        }
}

 

Please share this article von facebook & google plus or where you want, thank you!

Magento: eigene Events mit Observer definieren

18. Februar 2011 at 14:15

Events mit Hilfe des Observer im Magento definiert ihr in der config.xml des Modules wie folgt (bsp. Event in der Customer_Adress-Klasse):

<frontend>
<events>
<namespace_module_address_save_after>
<observers>
<namespace_module_observer>
<type>singleton</type>
<class>namespace_module/observer</class>
<method>customerSaveFrontEnd</method>
</namespace_module_observer>
</observers>
</namespace_module_address_save_after>
</events>
 </frontend>

Der Aufruf in PHP in der entsprechenden Funktion:

$eventArgs = array(
 'address' => $address,
 'request' => $this->getRequest(),
 );
 Mage::dispatchEvent('customer_address_save_after', $eventArgs);

Die aufgerufene Funktion in der Observer-Klasse:

public function customerSaveFrontEnd(Varien_Event_Observer $observer)
 {
// add your code here
 }