I am trying to setup a Cron to automatically update order statuses that have a are in a "Processing" state in Magento.
Here is what I have so far
config.xml
<orders>
<schedule><cron_expr>0 9,11,13,15,17 * * *</cron_expr></schedule>
<!--schedule><cron_expr>*/15 * * * *</cron_expr></schedule-->
<run><model>orders/Status::cron</model></run>
</orders>
</jobs>
And inside Status.php
public function updateOrderStatus($order)
{
$order->setOrderStatus(self::STATUS_PACKING);
$order->save();
}
What I would like to do is change any orders from "Processing" to "Packing" but I can't seem to find a way to do it…
If anyone knows any good resources please share.
Best Answer
There are a few things that seem to need correcting:
<run><model>orders/status::cron</model></run>
This line says to look in the
orders
module (though that it is a bit of an oversimplification) and look for a Model calledStatus
and run thecron()
functionWhat you probably want to do is change the line to this:
<run><model>orders/status::updateOrderStatus</model></run>
updateOrderStatus()
function does not have access to your ordersEven though the function has a parameter called
$order
it does not act like an observer where the object is there automatically.In other words: the order collection needs to be loaded with the following code:
Mage::getResourceModel('sales/order_collection');
The collection should be narrowed to what you need (see below).
The function should end up looking like this: