00001 <?php
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 class Mage_Eav_Model_Entity_Increment_Alphanum
00038     extends Mage_Eav_Model_Entity_Increment_Abstract
00039 {
00040     public function getAllowedChars()
00041     {
00042         return '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
00043     }
00044     
00045     public function getNextId()
00046     {
00047         $lastId = $this->getLastId();
00048         
00049         if (strpos($lastId, $this->getPrefix())===0) {
00050             $lastId = substr($lastId, strlen($this->getPrefix()));
00051         }
00052         
00053         $lastId = str_pad((string)$lastId, $this->getPadLength(), $this->getPadChar(), STR_PAD_LEFT);
00054         
00055         $nextId = '';
00056         $bumpNextChar = true;
00057         $chars = $this->getAllowedChars();
00058         $lchars = strlen($chars);
00059         $lid = strlen($lastId)-1;
00060         
00061         for ($i = $lid; $i >= 0; $i--) {
00062             $p = strpos($chars, $lastId{$i});
00063             if (false===$p) {
00064                 throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid character encountered in increment ID: %s', $lastId));
00065             }
00066             if ($bumpNextChar) {
00067                 $p++;
00068                 $bumpNextChar = false;
00069             }
00070             if ($p===$lchars) {
00071                 $p = 0;
00072                 $bumpNextChar = true;
00073             }
00074             $nextId = $chars{$p}.$nextId;
00075         }
00076         
00077         return $this->format($nextId);
00078     }
00079 }