Create custom product type in Magento

Create custom product type in Magento – As you know, in Magento, there are 6 product types:
– Simple products
– Configurable products
– Grouped products
– Bundle products
– Virtual products
– Downloadable products

In this tutorial, we will show you how to create a custom product type in Magento. If you don’t have your own module, please create a simple one following this post.

To create a new product type, we need to do:
– Edit your config.xml file to declare your new product type
– Create a model for your product type
– Create a model for your product type price

Let’s do it step by step.

1. Edit your config.xml file.

Open file /app/code/local/YourVendor/YourModule/etc/config.xml and add content:

– ‘special‘ is your product type code.
‘yourmodule/catalog/product/type/special‘ is your product type model.
– ‘yourmodule/catalog/product/type/special‘ is your product type price model.

2. Create product type model.

Create new file /app/code/local/YourVendor/YourModule/Model/Catalog/Product/Type/Special.php with content:

3. Create product type price model

Create new file /app/code/local/YourVendor/YourModule/Model/Catalog/Product/Type/Sepecial/Price.php with content:

In those 2 classes, you can override some functions of Magento core product type. You can find parent classes at:
/app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php
/app/code/core/Mage/Catalog/Model/Product/Type/Price.php
At last, refresh all cache types and try to create a new product to check if Magento recognized your new product type.

create custom product type in Magento
create custom product type in Magento

 

If you have any question, leave a comment or contact us.

Create new module in Magento

Create new module in Magento – As you know, Magento has its own modules in /app/core/ directory. In this tutorial, we’re going to create a simple module which is necessary to use in other tutorials.

To make Magento recognize your module, you need to create at least following directories and files:

/app/etc/modules/YourVendor_YourModule.xml
/app/code/local/YourVendor/YourModule/etc/config.xml
/app/code/local/YourVendor/YourModule/Helper/Data.php

Let’s do it step by step:

1. Create file /app/etc/modules/YourVendor_YourModule.xml

with content:

This file make Magento know about your module name and code pool ( which is ‘YourVendor_YourModule’ and ‘local’)

2. Create your module config file /app/code/local/YourVendor/YourModule/etc/config.xml

with content:

3. Create your module helper file /app/code/local/YourVendor/YourModule/Helper/Data.php

with content:

After creating those files, go to your backend -> System -> Cache Management, refresh all cache types and flush cache storage also.
At last, to check if Magento recognized your module, go to your backend -> System -> Configuration -> Advanced -> Disable Modules Output, you can see your module with name ‘YourVendor_YourModule‘ has been listed.

If you got any problem when create new module in Magento, please leave a comment or contact us.

Send custom email in Magento

Send custom email in Magento – Sometimes, you want to create a function that can send an email without using the built-in email feature of Magento. Let’s find out how to do that.

All things we need to to:

  • Create an email template which is a html file.
  • Declare that email template in config.xml file
  • Build your own send email function.

Let’s do it step by step.

1. Create an email template.

Create file: /app/locale/en_US/template/email/yourmodulename/sample_email.html with simple content:

You can use your own template name and your store locale instead of “en_US”

2. Declare that email template in config.xml file.

3. Create your own send email function using the email template.

You can place it anywhere you want.

 

You can review function ‘sendTransactional‘ of class ‘Mage_Core_Model_Email_Template‘ for details: