small businesses often use an existing book keeping software and can’t just stop with their current order numbers.
I have a client for example which uses the series 90001 - 99999 for their webshop.
I have a feeling this can be changed in the database, probably in the sales_order table, increment_id field. Though I’m not sure. I’m looking into this for myself as well so if I figure it out I’ll post a reply.
Thanks, Moshe. Would it cause problems if I changed the length to 6 characters? It’s still VARCHAR(50), just want to reduce the length of the number and also match a 3rd party accounting system.
I too, want to mak a custom order number, such as “WEB1/1” + date("y") + bin2hex(Number of order +1)
I tried to override the Mage_Sales_Model_Order model (getIncrementId and other methods), but it seems not to be interpreted…
I took a look at the eav_entity_store, in order to realise this, but it sems impossible. I only managed to had the “WEB1/1” prefix… not the year (08), nor the number of orders in hexadecimal.
This is very important for me to manage that… Can somebody tip me on the way to realize this ?
After taking a quick look at this, it seems that although you might not be able to add the prefix directly into the SQL database if you want to add the functions there you have one of two options. Either you modify the numeric.php increment function to use your custom values or you change the incrementing model that it uses to a custom one and you use your custom values there.
I would say that everything you need is fairly easy to change. In the table eav_entity_type you can see that entity_type_id = 11 is what will control the sales/order increment number. Under the column increment_model is what defines what model it uses to increment. By default it is set as eav/entity_increment_numeric. Say you wanted a custom model in there and you wanted it called customincrement.php you could put eav/entity_increment_customincrement under the column increment_model and it will use that custom function. Keep in mind you might have to tell Magento that you added a new model but you get the point. Now there are a few more options in there, you can see that the increment_per_store column is set at 1 which means that it will go up just one at a time (I am fairly certain but I would have to check) adn increment_pad_length is the number of padded characters added. And increment_pad_char is for what character will be added there for padding.
Now if you go to the table eav_entity_store you will see that there is a row with entity_type_id = 11, this corresponds to that same entity type and you can see that the increment_prefix is stored there (which should only be alphanumeric characters) and the increment_last_id is there. Fairly self explanatory.
Now let’s look at the file Numeric.php under the increment folder.
<?php
class Mage_Eav_Model_Entity_Increment_Numeric extends Mage_Eav_Entity_Increment_Abstract {
public function getNextId()
$last = $this->getLastId() //This will pull from the database the increment_last_id field
//This handles the padding and you see that getPrefix corresponds to the field increment_prefix, if you prefix getSomething then whatever table //the model is linked to will pull from that database field, i.e. getSomethingToTest will get something_to_test as the field name if (strpos($last, $this->getPrefix())===0) { $last = (int)substr($last, strlen($this->getPrefix())); } else { $last = (int)$last; } $next = $last+1;
return $this->format($next); }
Ok so we want to make this function add something to that, well right now it is being casted to an int hence the (int) but if we want to do something with the alphanumeric characters you should look at Alphanum.php, essentially the same thing just with some more checks added for allowed characters. But you wanted to do something like:
You would probably want to do this in Alphanum because it will be expecting a return from an alphanumeric and not from an integer. In addition, you will want to do more checks but you get the point.
update `eav_entity_type` set `increment_pad_length`=6 where `entity_type_code`='order';
This should do the trick.
Don’t forget to clean EAV cache.
I removed all cache, then made the above database edit, edited the last_increment_id in eav_entity_store to a 6-digit number, then refreshed all cache, but there’s still a 9-digit order number when a test order is placed. I can see that the increment_pad_length is correctly set to 6 in the database, so I don’t really get what’s going wrong. Any ideas? Thanks in advance!
update `eav_entity_type` set `increment_pad_length`=6 where `entity_type_code`='order';
This should do the trick.
Don’t forget to clean EAV cache.
I removed all cache, then made the above database edit, edited the last_increment_id in eav_entity_store to a 6-digit number, then refreshed all cache, but there’s still a 9-digit order number when a test order is placed. I can see that the increment_pad_length is correctly set to 6 in the database, so I don’t really get what’s going wrong. Any ideas? Thanks in advance!
Update for future reference:
Changing increment_pad_length in the database didn’t work, I extended Mage_Eav_Model_Entity_Increment_Numeric and Mage_Eav_Entity_Increment_Abstract with local classes to get the desired padding.
Basically, the order number for the store owner, magento, and the back end will be correct (#1000459 for example)… but on the customer’s invoice and account, it’ll show order #A497583.
If the member needs help and gives you the order #A4975B3, you just search for that order number and Magento automatically decrypts that number to the correct number on the fly.
Again, my memory is fuzzy, but I feel that this is the best way to handle the order numbers. I personally don’t like customers or competitors to know how many orders I do daily/monthly…