It is possible to create a completely new EAV increment model. This is where the magic happens when getting the next ids :)
Firstly you can see what the current model is by looking at the table eav_entity_type
under the column increment_model
. For example to order has the following set.
eav/entity_increment_numeric
You can create your new model and set it for orders via an install script.
class My_CustomEav_Model_Entity_Increment_New extends Mage_Eav_Model_Entity_Increment_Abstract
{
public function getNextId()
{
// Some magic here to get the unique vaue you want and return it
}
}
The table eav_entity_store
holds a few more pieces of important information. Here you can store increment_prefix varchar(20)
which is the prefix that is normally added to the increment, I think the default it 1, and increment_last_id varchar(50)
this stores the last id used for the entity type on a given store, note that without changing the table definition you will be limited to varchar(50)
, though that should be enough....maybe.
NOTE I have not tested this myself as I have never needed to but it should all work nicely if the ids are unique.
To reduce the number of digits, you'll want to modify the increment_pad_length
in the eav_entity_type
table (for the order
row, of course).
You can change the prefix by modifying the increment_prefix
value in the eav_entity_store
table. (Use the entity_type_id
from the other table to identify which row you'd change.) By default, Magento uses the store's id (1
) as the prefix.
If you're interested in learning more about the increment IDs, check out the Mage_Eav_Model_Entity_Increment_Numeric
and Mage_Eav_Model_Entity_Increment_Abstract
classes which are responsible for generating the next available ID based on the database settings.
Edit: You could even create your own increment logic by extending the Abstract class I mentioned above.
Best Answer
You can do this via below code, Magento uses
Magento\SalesSequence\Model\Sequence::getNextValue()
For next increment ID
So what you can can do is
Create a plugin and rewrite this method in your plugin
Your
di.xml
file located inYourPackage/YourModule/etc
folderYour
Sequence.php
is,