Programmatically: How to create custom Magento product types
Step 1: Create a new module
Create a new directory in app/code/local with your company name and module name, for example MyCompany/MyCustomProductType.
Step 2: Create the module configuration file
Create a file named config.xml in the module directory with the following content:
true
local
Step 3: Create the product type class
Create a new file named Product/Type/MyCustomProductType.php in the module directory with the following content:
class MyCompany_MyCustomProductType_Model_Product_Type_MyCustomProductType extends Mage_Catalog_Model_Product_Type_Abstract
{
protected function _construct()
{
parent::_construct();
$this->_label = 'My Custom Product Type';
}
public function getCode()
{
return 'mycustomproducttype';
}
}
Step 4: Create the product type model
Create a new file named Product/Model/Product/Mycustomproducttype.php in the module directory with the following content:
class MyCompany_MyCustomProductType_Model_Product_MyCustomProductType extends Mage_Catalog_Model_Product_Abstract
{
public function getAvailabilityMessage($isInStock = true)
{
return 'This is a custom availability message';
}
}
Step 5: Register the product type
In your module's etc/config.xml file, add the following code:
MyCompany_MyCustomProductType_Model_Product_MyCustomProductType
Step 6: Add the product type to the product form
In your module's etc/config.xml file, add the following code:
Step 7: Create the template
Create a new file named form.phtml in your module's view/frontend/templates/mycompany/mycustomproducttype directory with the following content:
This is a custom form field for my custom product type