Override magento Mage_Sales_Model_Order using or
Copy
app/code/core/Mage/Sales/Model/Order.php
to
app/code/local/Mage/Sales/Model/Order.php
add define new event on
_setStatus function
protected function _setState($state, $status = false, $comment = '',
$isCustomerNotified = null, $shouldProtectState = false)
{
Mage::dispatchEvent('sales_order_status_before', array('order' => $this, 'state' => $state, 'status' => $status, 'comment' => $comment, 'isCustomerNotified' => $isCustomerNotified, 'shouldProtectState' => $shouldProtectState));
// attempt to set the specified state
if ($shouldProtectState) {
if ($this->isStateProtected($state)) {
Mage::throwException(
Mage::helper('sales')->__('The Order State "%s" must not be set manually.', $state)
);
}
}
$this->setData('state', $state);
// add status history
if ($status) {
if ($status === true) {
$status = $this->getConfig()->getStateDefaultStatus($state);
}
$this->setStatus($status);
$history = $this->addStatusHistoryComment($comment, false); // no sense to set $status again
$history->setIsCustomerNotified($isCustomerNotified); // for backwards compatibility
}
Mage::dispatchEvent('sales_order_status_after', array('order' => $this, 'state' => $state, 'status' => $status, 'comment' => $comment, 'isCustomerNotified' => $isCustomerNotified, 'shouldProtectState' => $shouldProtectState));
return $this;
}
using two sales_order_status_after and sales_order_status_before you can do your requirement
or best way to do this
sales_order_save_after and in this observer if
you get old value then try
$oldstatus=$order->getOrigData('status');
$Newstatus=$order->getData('status');
https://stackoverflow.com/questions/8182009/get-product-changes/8184430#8184430
Have a state related to status etiqueta_impressa
?
Try set status and add history comment separately, and search for observers after save order.
$_order = Mage::getModel('sales/order')->load($idOrder);
$_order->setStatus('etiqueta_impressa');
$comment = 'Etiqueta impressa via Ferramentas > SIGEP em: '.date("d/m/Y H:i:s");
$history = $_order->addStatusHistoryComment($comment, false);
$history->setIsCustomerNotified($isCustomerNotified);
$_order->save();
Best Answer
To retrieve latest order's comment history you can do following:
To add new history comment to the created order you can use
Magento\Sales\Model\Order\Status\HistoryFactory
and\Magento\Sales\Api\OrderStatusHistoryRepositoryInterface
: