I’m making an attempt so as to add an attribute like product_id for merchandise that can have auto_increment.
What I did up to now and isn’t working:
and so forth/config.xml
<?xml model="1.0"?>
<config>
<modules>
<Mymodule>
<model>0.1.0</model>
</Mymodule>
</modules>
<world>
<helpers>
<mymodule>
<class>Mymodule_Helper</class>
</mymodule>
</helpers>
<fashions>
<Mymodule>
<class>Mymodule_Model</class>
</Mymodule>
</fashions>
<sources>
<mymodule_setup>
<setup>
<module>mymodule</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</mymodule_setup>
<mymodule_write>
<connection>
<use>core_write</use>
</connection>
</mymodule_write>
<mymodule_read>
<connection>
<use>core_read</use>
</connection>
</mymodule_read>
</sources>
</world>
</config>
The mannequin:
<?php
class Mymodule_Model_Myitem extends Mage_Core_Model_Abstract {
//this methodology merely provides one to the increment id an returns the brand new one
public operate getIncrementId(){
return Mage::getSingleton('eav/config')
->getEntityType('myitem')
->fetchNewIncrementId();
}
protected operate _beforeSave()
{
mother or father::_beforeSave();
if (!$this->getIncrementId()) {
$incrementId = Mage::getSingleton('eav/config')
->getEntityType('custom_sku2')
->fetchNewIncrementId($this->getStoreId());
$this->setIncrementId($incrementId);
}
}
}
and the installer script:
<?php
$set up = $this;
$install->startSetup();
$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())
->setStoreId(0)
->setIncrementPrefix("MYPREFIX")
->setIncrementLastId(100)
->save();
$install->endSetup();
Then I create an attribute the traditional means in Magento with the identify “custom_sku2” and I add this attribute in merchandise grid.
Even after save i can’t see this attribute auto increment, it’s clean.