Create a new product type

Last modified by Ryan Sun _Kuafu on Sun, April 1, 2012 20:42
Source|Old Revisions  

Please Note

Here you’ll find all the necessary about creating a new product type. This page is currently under construction. Keep watching about evolutions soon !

I’m on holidays till 22/07, so this page can stay unupdated till this date.

Good to know

Option Value
Magento version 1.4.1.0 Stable
Namespace for tutorial Namespace
Module name for tutorial Rate

Steps

1. Create new module

First, we must create our new module. We will made the module as simplest as possible.

Actually, we just need the config file and the helper (every module needs a helper). We also create a translation file and a layout update file and declare it in the config file).

And of course, we need to declare our new module by adding a new file in /app/etc/modules/ named Namespace_Rate.xml

Here an exemple of our actual config file. Please note the layout and translation files are added to adminhtml tags and not on the frontend one.

  1. <?xml version="1.0"?>
  2. <config>
  3.     <modules>
  4.         <Namespace_Rate>
  5.             <version>0.1.0</version>
  6.         </Namespace_Rate>
  7.     </modules>
  8.     <global>
  9.         <helpers>
  10.             <rate>
  11.                 <class>Namespace_Rate_Helper</class>
  12.             </rate>
  13.         </helpers>
  14.  
  15.         <catalog>
  16.             <product>
  17.                 <type>
  18.                     <rate translate="label" module="rate">
  19.                         <label>Rate Product</label>
  20.                         <model>rate/product_type_rate</model>
  21.                         <composite>0</composite>
  22.                         <index_priority>12</index_priority>
  23.                     </rate>
  24.                 </type>
  25.             </product>
  26.         </catalog>
  27.     </global>
  28.     <adminhtml>
  29.         <translate>
  30.             <modules>
  31.                 <Namespace_Rate>
  32.                     <files>
  33.                         <default>Namespace_Rate.csv</default>
  34.                     </files>
  35.                 </Namespace_Rate>
  36.             </modules>
  37.         </translate>
  38.         <layout>
  39.             <updates>
  40.                 <rate>
  41.                     <file>rate.xml</file>
  42.                 </rate>
  43.             </updates>
  44.         </layout>
  45.     </adminhtml>
  46. </config>

2. Creating models

In order to create a new product type, we need to create some additionnal models inside our module.

So we need to declare it in our config file (inside <global> tags).

  1. <models>
  2.     <rate>
  3.         <class>Namespace_Rate_Model</class>
  4.     </rate>
  5. </models>

We need to create 3 different classes:

  • /app/code/local/Namespace/Rate/Model/Product/Type.php
  • /app/code/local/Namespace/Rate/Model/Product/Price.php
  • /app/code/local/Namespace/Rate/Model/Product/Type/Rate.php

You can just copy the simple product type classes and add your own methods




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs