The order increment ID is generate by the class Mage_Eav_Model_Entity_Increment_Numeric
(see table eav_entity_type
column increment_model
) which is invoked on order beforeSave via Mage_Eav_Model_Entity_Type::fetchNewIncrementId
.
Now the later has no knowledge of what it is actually rendering the increment ID for. Where I normally would suggest using another increment_model
(as described by Atwix) this won't work.
The best solution in this case would probably be to use an observer. In this case you want to do that before the object is committed to database so we can use the $this->_eventPrefix.'_save_before'
invoked by Mage_Core_Model_Abstract::_beforeSave
.
The order models eventPrefix is sales_order
so that would make the event you want to observer sales_order_save_before
.
Tying that all together we would get something like this in your own custom module
config.xml
[...]
<global>
<events>
<sales_order_save_before>
<observers>
<[namespace]_[module]_sales_order_save_before>
<type>singleton</type>
<class>[Namespace]_[Module]_Model_Observer</class>
<method>salesOrderSaveBefore</method>
</[namespace]_[module]_sales_order_save_before>
</observers>
</sales_order_save_before>
[...]
</events>
[...]
</global>
[Namespace]/[Module]/Model/Observer.php
class [Namespace]_[Module]_Model_Observer
{
public function salesOrderSaveBefore($o)
{
$this->_generateOrderId($o);
return $this;
}
protected function _generateOrderId($o)
{
$_object = $o->getDataObject();
if ($_object->isObjectNew !== true) // only set the increment of a new order
return;
$incrementId = $_object->getIncrementId(); // get original increment ID
$payment = $order->getPayment();
/**
* Do some magic with payment methods
* to format the $incrementID
*/
$_object->setIncrementId($incrementId); // set the new increment ID to be saved
}
}
Disclaimer: this is untested code and might need some tender love and tweaking before you deploy it on a live environment.