Showing results for 
Search instead for 
Did you mean: 

Add product attribute that will auto_increment aftersave


Add product attribute that will auto_increment aftersave

Hello , i am trying to add an attribute like product_id for products that will have auto_increment.


What i did so far and is not working:



<?xml version="1.0"?>

The model:

class Mymodule_Model_Myitem extends Mage_Core_Model_Abstract {
 //this method simply adds one to the increment id an returns the new one
    public function getIncrementId(){
        return Mage::getSingleton('eav/config')

protected function _beforeSave()


    if (!$this->getIncrementId()) {
        $incrementId = Mage::getSingleton('eav/config')



and the installer script:


$install = $this;

$install->addEntityType('mymodule', array(
    'entity_model'          => 'mymodule',
    'increment_model'       => 'eav/entity_increment_numeric',
    'increment_per_store'   => false,

$entityType = Mage::getModel('eav/entity_type')->loadByCode('custom_sku2');
$entityStoreConfig = Mage::getModel('eav/entity_store')->loadByEntityStore($entityType ->getId(), 12);
$entityStoreConfig->setEntityTypeId($entityType ->getId())


Then i create an attribute the normal way in Magento with the name "custom_sku2" and i add this attribute in products grid.
Even after save i cannot see this attribute auto increment, it is blank.