Welcome back to Lesson 20 – Magento Product Types!

In the previous tutorial, we’ve known that Magento has six standard product types including: Simple product; Grouped product; Configurable product; Virtual product; Bundle product and Downloadable product.

However, what if you want to create another product type to fit your specific needs? It is the issue we will discuss in this post – Add custom product type.

Don’t miss:

Magestore’s Extensions for both Magento 1 and Magento 2 that Store Owners can’t live without.

Add custom Magento product type

Suppose that we want to create a new product type named “Gift Card” in Magento system. Firstly, create a new module and add to config.xml file (in folder app\code\local\Magestore\Lesson20\etc)

<config>
...
<global>
...
<catalog>
<product>
<type>
<giftcard translate="label" module="lesson20">
<label>Gift Card</label>
<model>lesson20/giftcard_product</model>
<price_model>lesson20/giftcard_price</price_model>
<index_data_retreiver>catalogindex/data_simple</index_data_retreiver>
</giftcard>
</type>
</product>
</catalog>
</global>
</config>
  • Label: name of the product type we have created
  • Model: product type model
  • Price_model: model used to determine price of this product type
  • Index_data_retreiver: model used when we reindex product data

 

create magento product types

Next, create models for product type and product type price.

The product type model must inherit Mage_Catalog_Model_Product_Type_Abstract layer, code in app\code\local\Magestore\Lesson20\Giftcard\Product.php file.

class Magestore_Lesson20_Model_Giftcard_Product extends Mage_Catalog_Model_Product_Type_Abstract
{
/**
* Check is virtual product
*
* @param Mage_Catalog_Model_Product $product
* @return bool
*/
public function isVirtual($product = null)
{
// Gift Card is virtual product
return true;
}
}

Because Gift Card is a virtual product, we rewrite it asVirtual and return to true.

Finally, create product type price model and file of product type in the same folder. Product type price model must inherit Mage_Catalog_Model_Product_Type_Price layer.

class Magestore_Lesson20_Model_Giftcard_Price extends Mage_Catalog_Model_Product_Type_Price
{
}

Now, we can create a Gift Card product in backend and then check out it in frontend.

create magento product types backend

create magento product types frontend

We can see that there is no information about shipping because Gift Card is a virtual product.

Your turn

Now it’s your turn to imply this guide to achieve what you want! Let’s practise and leave us a comment if you have any difficulties.

Stay tuned for more helpful Magento tutorials for both Magento 1 and Magento 2 next week!

Author

Why Magestore? We believe in building a meaningful & long-term relationship with you.

4 Comments

  1. Knowledgeable post!! It is the easiest way to create the new product type for Magento.

Write A Comment