Magento update order status and order tags programmatically

28 Jun

Hello Friends,

TGIF (Thank God Its Friday) but it was not at all  thank full for me, When I was told to update the order tags in magento admin. Yes right I am taking about the order_tag associated with every order status in magento.

Here is the piece of code which did the trick for me.

$order = Mage::getModel(‘sales/order’)->loadByIncrementId($oid);
// Here in place of $oid, use any order id which you want to update. if you have a list of order ids, then iterate it through foreach loop.

$order->setData(‘order_tag’, “Test”);
// The function setData passes the test tag that we are trying to update.

$order->save(); //It save the data to magento

Magento update order status programmatically:-

$order = Mage::getModel(‘sales/order’)->loadByIncrementId($oid);
$state = ‘new’;
$status = ‘any_order_status_comes_here’;
$comment = ‘Write you comment here’;
$isCustomerNotified = false;
//If you choose to set $isCustomerNotified then it would make the neccessary notification to customer else put it false.
$order->setState($state, $status, $comment, $isCustomerNotified);
$order->sendOrderUpdateEmail(true, $comment); //Send email to customer. If not reuqired leave this line.

Imp Note:- Magento doesn’t allow setState for complete and closed.

Do reply if you need any help or if it is not working for you. You can also reach me by email:- mukund002(at)gmail(com)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.