The idea is that, to generate the order number, the theory is to generate the order code when the order is saved. So trace the code to the Mage_sales_model_order Save () method. And then tracked down to mage_sales_model_resource_order_abstract this, in view of the characteristics of Magento, or mainly to see _beforesave, save,_aftersave these 3 things are almost, and check to see if there are events,
It is found that the _beforesave of this class is written in this way:
code is as follows |
copy code |
if ($this- >_useincrementid &&! $object->getincrementid ()) { /* @var $entityType mage_eav_model_entity_type * * $entityType = Mage::getmodel (' Eav/entity_type ')->loadbycode ($this->_entitytypeforincrementid); $object->setincrementid ($entityType->fetchnewincrementid ($object->getstoreid ())); } Parent::_beforesave ($object); Return $this |
This should be the generation of the order number, according to ' Eav/entity_type, you can trace to the Mage_eav_model_entity_type class, and then view the method Fetchnewincrementid, inside the definition of $incrementid = $ Incrementinstance->getnextid (); Therefore, the new order number should be $incrementinstance in the Getnextid method, as for $incrementinstance is what, there is no resolution Can only be judged by the code.
In the previous code, you can see that $incrementInstance = Mage::getmodel ($this->getincrementmodel ()) is defined in this way, The Getincrementmodel () method is not defined before and after, think of the _call method Magento the underlying definition, this may be the contents of the datasheet, open the Eav_entity_type table, you can find a Increament_model field. This is clear, according to the definition of eav/entity_increment_numeric, can trace to the Mage_eav_model_entity_increment_numeric class, so that only found the Getnextid method.
Here, as long as the rewrite of the Mage_eav_model_entity_increment_numeric class Getnextid can implement the custom order code, but will find invoice,shipment, are using the same class, So we increment_model the records to personalize our code.