How to create a new product type in Magento

18 Comments 21st JAN 2010 | Posted by Branko Ajzele in Magento

How to create a new product type in Magento

Magento comes packed with several product types: simple, grouped, configurable, virtual, bundle, downloadable. Sometimes clients request can reach beyond any of these built in product types functionality. In such cases, usual way of handling things is throwing some new attributes and hooking into some events from which you can handle and “re-route” certain logic.

In some cases, the required product logic can extend to such level that you are better of with building a new product type in Magento. Why, you might ask? Becase of the more finer control you can achieve on product trough your own models than to poke around on the existing stuff.

Attached to this article is a fully working extension I wrote that creates a new product type in your Magento store. This new product type uses code name “customproduct”. Its based on the Mage_Catalog_Model_Product_Type_Abstract class, the one on which the “simple” product is build upon. Unlike “simple” product type, this “customproduct” does not have any, whatsoever, additional logic built in. This, I leave to you.

Also, extension comes with several “hooks” to certain Magento controllers actions. If you open the app/code/local/Ajzele/CustomProduct/Model/Observer.php you will see implemented several “blank” methods as hooks. Going to config.xml file of this extension will show you what these methods “observe”.

Here are few screenshots of how this looks like on frontend and on backend.

And here is the module (extension), Ajzele_CustomProduct.

Note, DO NOT INSTALL the extension on LIVE SITE. Use it merely for development testing and getting to know Magento product types. Extension is tested on my PC, latest Magento 1.3.2.4 version and it seems to work fine, both in admin and frontend. It is by no means intendant to be used on live site. Use it at your own responsibility.

Hope you find it useful :)

Cheers.

If you like what you read, please share it.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Yahoo! Bookmarks
  • Reddit
  • Technorati
  • Twitter
  • StumbleUpon
  • LinkedIn
  • Netvibes
  • NewsVine
  • Sphinn
  • Tumblr
  • Posterous

To post code in comments, place your code inside [code] and [/code] tags.

There are 18 comments (Add Yours +)

  • Does it work in Magento 1.4? I’ve done some extensions for 1.3.2.4 (like creating custom checkout fields) but they just stop working in 1.4 :(

  • Nice post.. will look into this…but…. I can’t think of a situation..when..I need to create a product type…Can you provide me any..situation.. :D

  • Hi there,
    I dint understand the need of this. Let me clear my point.
    I think, we can just use Simple Product Type always.

    Kindly give us an example of a situation, when you may need this.
    Im sure, you would have come across any client’s requirements and thats why, you would have done this and just wrote this .
    So, let us know that situation.
    Thanks.

  • @All

    There are tons of scenarios one might need custom product type, such as more finer control over “live products” that are pulled via some feed from some third party service or etc….

    For all those who do not “understand the need for custom product” type, answer might be brutal but simple, please ignore this the article and attached extension. In short, consider yourself lucky if you won’t need to create a new product type ever.

    Happy coding people.

  • @Branko

    This post is impossible.. to ignore..coz.. I can learn from this.. about Magento’s ins and outs :D .

    Also..will post a thank you… after…if I ever need a custom product type :D

  • We’re trying to develop a product type of “schematic”, which is similar to a grouped product, but needs reference numbers and quantities for each part that goes to the product listed. Using this, it should be much easier. Thanks.

  • Thanks for this. This would really be great in testing new products. I’m also following your note; not using it on live site.

  • We customize the hell out of our products! … i am not a coder, but i like to learn about what is happening in the development world so i can keep my coders “honest” and get ideas for us.

    We had a situation where we built a theatre booking system and the coders had to customize the a simple product and instructed us to “duplicate” this simple product for additional concerts. So this can help us greatly (I think!!)

    But, a question just so i can understand and talk with some “authority” with my coders, how is this product different from a simple product? i can’t read php to save my life and the tabs seem similar to what one would usually see in a simple product.

  • @Nasser

    This specific product in the example is not that different from Simple product type. However, it enables you now to do any custom logic in the model that will make it a whole lot different then any product type in Magento :) -For example, if you use “duplicate” function a lot I would guess you are using it in order to “presetting” some values for product so you do not have to fill them in each time manually. Why not do so with the code in your custom product type?! Just a thought.

    Cheers.

  • ok. now i understand. The fact this code creates a new product type means we can have the additional logic embedded in this product type.

    I will share with you the example once we do it :)

    Many thanks for the explanation.

  • I’m using this code with Magento 1.4.0.1 and I keep getting this error:

    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 46: parser error : Opening and ending tag mismatch: blocks line 26 and global in /home/drjsafety/www/www/lib/Varien/Simplexml/Config.php on line 510″

    I went through config.xml adding nodes one by one until I could get the error to repeat and seems to be caused by the catalog node.

    Do you have any more insight into what’s causing this?

  • Scratch that last comment. Somehow I looked past the same unclosed node like fifty times. All seems well now.

  • The zip file seems to be invalid. Could you fix it please?

  • Couldn’t you just create a new attribute set to accomplish? What did you use this for, specifically?

  • This is how our team plans to use it (not sure if we can or not, though) … for example we have a product that simulates a theater booking system. In addition to the attributes, we have specific code within the product. Every time we need to create a new theater event, we have to duplicate a product. Now, if we can create a new product type and embed in it our code, then we can simply create a theater event as opposed to duplicating the original product.

  • This is just what i was looking for. Wanted to copy & make some changes to the bundled product type. This will come in handy at learning Magento. Just started looking into it yesterday, but i soon learned it has serious drawbacks when it comes to price calculation based on chosen attributes.

  • ok. now i understand. The fact this code creates a new product type means we can have the additional logic embedded in this product type.

    I will share with you the example once we do it

    Many thanks for the explanation.

  • Hi Coders,

    It’s a very interesting article !
    Do you know how to add some tabs with specific informations linked to our new product type?

    Just like downloadable products… I’ve tried to look in the code of downloadble module but i’m lost…

    I want to create a product type ‘Rateable’, these products must have a start and end date for the rates, an estimated price, …

    I cant create a new attribute set ‘Rateable’ because the rateable products can have another attribute set with other attributes…

    I wish you beleive me with my bad english…

    Thanks ! Jona

Leave a Comment

Please wrap all source codes with [code][/code] tags.
Magento Design and Development | Magento SEO | iPhone Application Development Web Application Development with ZEND | WordPress Ecommerce | WordPress development
Sitemap

Inchoo - webappsolutions | 2009