Implement personalized order number code in Magento

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.