Guide Adding a Custom Magento print Product Type

View: 330    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: Magento template   Fields: Other

9 point/2 review File has been tested

This guide is going to assume you have some basic knowledge of the inner workings of a Magento module.

Introduction

This guide is going to assume you have some basic knowledge of the inner workings of a Magento module.

Building a good module is a bit of an art on its own and it's the subject matter of a post all its own. With that said, we're going to take a look at how to set up the module for it.

Now, on to the main point of discussion.

Like everything in Magento, our work here too starts in the configuration files. We want to create a separate module for this because in Magento, we want separate modules for everything. Keeping things separate and modular in Magento keeps us happy. I ended up with Robogento Printable, Robogento being my company and Printable the module name.

To add a product type, we have to tell Magento about it and define it. These are the applicable parts of the config.xml file we’re going to need, you will need to fill in the blanks yourself, of course:

<config>
  ...
  <global>
    ...
    <catalog>
      <product>
        <type>
          <printable translate="label" module="printable">
            <label>Printable Product</label>
            <model>printable/product_type</model>
            <price_model>printable/product_price</price_model>
            <is_qty>1</is_qty>
          </printable>
        </type>
    ...

There we go. 

As you can see, my module is defined as “printable”, the label is for the benefit of filtering in the grids that show the product in the backend and when creating a new product. The model and price model are where the fun begins. Every product needs a type, this can be pretty straight forward.

Extend the base system by creating the Type model. Watch the file path based on the class definition:

class Robogento_Printable_Model_Product_Type
    extends Mage_Catalog_Model_Product_Type_Simple { }

And there we go. 

Suddenly our printable product is now a clone of the Simple Product Magento is already aware of. What’s actually happening here is that by extending from the Simple Type, we’re reusing all of the features that product type has. The added benefit is we can very simply override the existing features with our own if we’re so inclined.

There was one other thing I showed you for our config.xml file. The product type’s price model. Very much the same thing applies here:

class Robogento_Printable_Model_Product_Price
    extends Mage_Catalog_Model_Product_Type_Price { }

As you can see, we’re simply extending from Magento’s existing system again. Magento has flaws enough, but the simple and virtual product types were among the better thought out parts of it and it’s always a good idea to reuse existing code when you can.

Normally, I'd say there's more to it, but in the case of Magento, this is really all there is to it. We’ve now essentially created an alias of the Simple Product system and named it Printable. 

The printable product will use all of the features and definitions as they are set up for the simple products. So two addresses, inventory settings, you name it If you only need an invoice address, extend from the Virtual product instead. If you want to provide downloadable products, but with a slightly different set of features, extend from the Downloadable system.

Guide Adding a Custom Magento print Product Type

Guide Adding a Custom Magento print Product Type Posted on 19-01-2016  This guide is going to assume you have some basic knowledge of the inner workings of a Magento module. 4.5/10 330

Comment:

To comment you must be logged in members.

Files with category

 

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd