Can a Magento 1 system survive an increment ID that exceeds its padding length?

That is -- the eav_entity_type table contains an increment_pad_length column that defaults to 8. This means when Magento generates an increment ID for an order (or quote, shipment, etc) from the eav_entity_store table, it will pad the number to look something like this


Will a Magento system still operate normally if that padding is is set to 1 or 0? Will a Magento system still operate normally if that padding is reduced to something like 4, and the actual increment ID value in eav_entity_store is greater than 10,000?

1 Answer 1


It won't blow up, unless you exceed the column length in Magento's eav_entity_type table.

The only place that the pad setting is used in Magento is in Mage_Eav_Model_Entity_Increment_Alphanum::getNextId, and that uses the Last ID set to increment the last digit(s).

As it calculates the next ID it trims off the leading prefix, and only string pads left. It uses the inbuild PHP function to do so, which ignores strings longer than the pad.

See this repl output:

[1] boris> str_pad('9999999999',8,'0',STR_PAD_LEFT);
 → string(10) "9999999999"
[2] boris> str_pad('999999999999999999',8,'0',STR_PAD_LEFT);
 → string(18) "999999999999999999"

So in essence it just treats the resulting id string as if it were any other string. The for loop afterward is smart enough to cycle by the total length of that string, and should easily handle any size:


function test($lastId){
        $nextId = '';
        $bumpNextChar = true;
        $chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $lchars = strlen($chars);
        $lid = strlen($lastId)-1;

        for ($i = $lid; $i >= 0; $i--) {
            $p = strpos($chars, $lastId{$i});
            if (false===$p) {
                throw new Exception('Invalid character found');
            if ($bumpNextChar) {
                $bumpNextChar = false;
            if ($p===$lchars) {
                $p = 0;
                $bumpNextChar = true;
            $nextId = $chars{$p}.$nextId;


// =>string(11) "09234029343"

// =>string(2) "23"
// =>string(35) "23409235092835029385023958230598236"

Be aware that if you exceed a certain length with an integer in PHP it'll convert to Scientific Notation, which will trigger the exception.

Therefore I have intentionally passed these as a string.

If for some reason Magento did export these as an int, which I haven't seen, then it would blow up, because of the + symbol:

// =>PHP Fatal error:  Uncaught exception 'Exception' with message 'Invalid character found'


I ran up against this in 1.2 CE days, so bear with me and consider the age of my knowledge (and nevermind the fact that I'm reading EE code making these assumptions)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.