Magento Forum

   
Page 1 of 2
New Product Type + New Tab
 
JonathanJ
Member
 
Avatar
Total Posts:  60
Joined:  2008-08-27
Liege
 

Hi Coders,

First, i want to excuse myself for my bad english… I’m from Belgium and i speak french.
I have read some posts on the subject of “Create new product type” and i want to start a new one for regrouping all of these.

I’m based on the Downloadble Products for inspiration and testing…

I want to create a product type ‘Rateable Product’.

- This type of product can’t be added to the cart
- It dont need inventory attributes
- It can have an estimated price but no price or special price ect…
- It have a start_date and end_date of rate (vote en francais)

For creating a new product type, i’ve created a new module (named ‘Rate’), correctly declared:

<?xml version="1.0"?>
<config>
    <
modules>
        <
XXX_Rate>
            <
active>true</active>
            <
codePool>local</codePool>
        </
XXX_Rate>
    </
modules>
</
config>

This is my module structure, i will try to explane the role of each file but maybe i’m wrong so please tell it if you know it wink

XXX
- - - Rate
- - - - - Block
- - - - - - - Adminhtml
- - - - - - - - - Catalog
- - - - - - - - - - - Product
- - - - - - - - - - - - - Edit
- - - - - - - - - - - - - - - Tab
- - - - - - - - - - - - - - - - - Rate
- - - - - - - - - - - - - - - - - - - Info.php
- - - - - - - - - - - - - - - Rate.php
- - - - - controllers
- - - - - - - Product
- - - - - - - - - EditController.php
- - - - - etc
- - - - - - - config.xml
- - - - - Helper
- - - - - - - Data.php
- - - - - Model
- - - - - - - CatalogIndex
- - - - - - - - - Data
- - - - - - - - - - - Rate.php
- - - - - - - Product
- - - - - - - - - Type
- - - - - - - - - - - Rate.php
- - - - - - - Price.php
- - - - - - - Type.php

Rate/Block/Adminhtml/Catalog/Product/Edit/Tab
All these files are normaly for the new tab in the product edit page. (i have a problem with that)

Rate/controllers/Product/EditController.php
I have copyied this file like the Downloadable Products but i don’t see any rewrite rule in the config files, somebody can explane me that?

Rate/etc/config.xml
Just the config file.

Rate/Helper/Data.php
A helper, empty…

Rate/Model/CatalogIndex/Data/Rate.php
Rate/Model/Product/Type/Rate.php
Rate/Model/Price.php
Rate/Model/Type.php

All the files needed for new product type.

---

In the module config, i’ve declared my blocks, models, helpers, layouts and the special tag for product type:

<catalog>
    <
product>
        <
type>
            <
rate translate="label" module="catalog">
                <
label>Rateable Product</label>
                <
model>rate/product_type_rate</model>
                <
price_model>rate/product_price</price_model>
                <
index_data_retreiver>rate/catalogIndex_data_rate</index_data_retreiver>
            </
rate>
        </
type>
    </
product>
</
catalog>

In the rate.xml file placed in app/design/adminhtml/default/default, i have this:

<?xml version="1.0"?>
<adminhtml_catalog_product_rate>
    <
reference name="product_tabs">
        <
action method="addTab"><name>rates_infos</name><block>rate/adminhtml_catalog_product_edit_tab_rate</block></action>
    </
reference>
</
adminhtml_catalog_product_rate>

But i don’t see any new tab in admin panel…

I’m wrong… But where ?
Thank you for your help…

If you need some code, just ask it wink

Bye, Jona

Here some code:

Rate/Block/Adminhtml/Catalog/Product/Edit/Tab/Rate.php

<?php

class XXX_Rate_Block_Adminhtml_Catalog_Product_Edit_Tab_Rate extends Mage_Adminhtml_Block_Widget implements Mage_Adminhtml_Block_Widget_Tab_Interface
{

    
/**
     * Class constructor
     */
    
public function __construct()
    
{
        parent
::__construct();
        
$this->setTemplate('rate/product/edit/rate.phtml');
    
}
    
    
/**
     * Get tab label
     *
     * @return string
     */
    
public function getTabLabel()
    
{
        
return Mage::helper('rate')->__('Rate Information');
    
}

    
/**
     * Get tab title
     *
     * @return string
     */
    
public function getTabTitle()
    
{
        
return Mage::helper('rate')->__('Rate Information');
    
}

    
/**
     * Check if tab can be displayed
     *
     * @return boolean
     */
    
public function canShowTab()
    
{
        
return true;
    
}

    
/**
     * Check if tab is hidden
     *
     * @return boolean
     */
    
public function isHidden()
    
{
        
return false;
    
}
    
    
/**
     * Render block HTML
     * 
     * @return string
     */
    
protected function _toHtml()
    
{
        
        $accordion 
$this->getLayout()->createBlock('adminhtml/widget_accordion')
            ->
setId('rateInfo');

        
$accordion->addItem('rates', array(
            
'title'   => Mage::helper('adminhtml')->__('Rates'),
            
'content' => $this->getLayout()->createBlock('rate/adminhtml_catalog_product_edit_tab_rate_info')->toHtml(),
            
'open'    => false,
        ));

        
$this->setChild('accordion'$accordion);
        
        return 
parent::_toHtml();
    
}
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
JonathanJ
Member
 
Avatar
Total Posts:  60
Joined:  2008-08-27
Liege
 

I think an important part of the response is in the /controllers/Product/EditController.php

Why i can’t find the rewrite rule ?

Nobody know it ?

Thank you !

 
Magento Community Magento Community
Magento Community
Magento Community
 
JonathanJ
Member
 
Avatar
Total Posts:  60
Joined:  2008-08-27
Liege
 

Ok, i try to debug this…

In the Mage/Adminhtml/controllers/Catalog/ProductController.php -> editAction(), you can see:

$this->loadLayout(array(
            
'default',
            
strtolower($this->getFullActionName()),
            
'adminhtml_catalog_product_'.$product->getTypeId() . $_additionalLayoutPart
        
));

So i presume the layout update in adminhtml/default/default/layout/rate.xml :

<adminhtml_catalog_product_rate>
    <
reference name="product_tabs">
        <
action method="addTab"><name>rates_infos</name><block>rate/adminhtml_catalog_product_edit_tab_rate</block></action>
    </
reference>
</
adminhtml_catalog_product_rate>

Must be applied…
But when i do:

Zend_Debug::dump($this->getLayout()->getUpdate()->asSimplexml());

I cant see this layout update…
In my config file, i have this:

<adminhtml>
    <
translate>
        <
modules>
            <
XXX_Rate>
                <
files>
                    <default>
XXX_Rate.csv</default>
                </
files>
            </
XXX_Rate>
        </
modules>
    </
translate>
    <
layout>
        <
updates>
            <
rate>
                <
file>rate.xml</file>
            </
rate>
        </
updates>
    </
layout>
</
adminhtml>

I very dont understand… Thank you for help smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
JonathanJ
Member
 
Avatar
Total Posts:  60
Joined:  2008-08-27
Liege
 

Ok it was just because i have forgotted the <layout></layout> tags in my rate.xml ...

OMG… i’m so stupid…

 
Magento Community Magento Community
Magento Community
Magento Community
 
GenericSteele
Jr. Member
 
Total Posts:  8
Joined:  2009-07-31
 

This is ridiculously helpful. I’ll let you know if I can port it to my product type.

 
Magento Community Magento Community
Magento Community
Magento Community
 
JonathanJ
Member
 
Avatar
Total Posts:  60
Joined:  2008-08-27
Liege
 

I’m happy to help you with my problem wink
It works fantastic !

Keep me posted about your product type and if you have questions, maybe i can help you wink

Bye, Jona

 
Magento Community Magento Community
Magento Community
Magento Community
 
GenericSteele
Jr. Member
 
Total Posts:  8
Joined:  2009-07-31
 

I\’m trying to make a serial number based product type that has a tab allowing a store owner to manage serial number associated with that sku. This is my first extension, so I\’m banging my head trying to figure out how everything works.

Before I get into making everything work, I need to set up a framework to build inside. I just want to make a new product with a tab and I\’m not sure what the bare minimum code I need to extend an existing product, but have an extra tab. I\’m working on it some more today, but if you have any advice, it would be much appreciated. I\’ll post any developments as they come.

 
Magento Community Magento Community
Magento Community
Magento Community
 
JonathanJ
Member
 
Avatar
Total Posts:  60
Joined:  2008-08-27
Liege
 

Hi,

If you just need a tab with a barcode field, why not create an attribute set with this new tab?

Jona

 
Magento Community Magento Community
Magento Community
Magento Community
 
GenericSteele
Jr. Member
 
Total Posts:  8
Joined:  2009-07-31
 

The idea is that I have 3 different SKU’s for calling card numbers. The inventory availability will be based on how many card numbers (aka serial numbers) are still available. when a sale is made, a card number will be sent to the customer and will be marked in the system as sold.

 
Magento Community Magento Community
Magento Community
Magento Community
 
JonathanJ
Member
 
Avatar
Total Posts:  60
Joined:  2008-08-27
Liege
 

Hi,

I have never played with inventory features of a new product type sorry.
But if i understand correctly your concept, it can be simple i think.

You have Product A, B and C. The three products are ‘Serial Number based Products’.
In your product, you can define any serial numbers that you want.

Each time a product is sold, a SN is sent to the customer, flaged ‘sold’ in the product, and one item is substracted in the inventory (sorry for english i mean inventroy = inventory -1).

So i think you can use the normal inventory system, you just set the inventory value to the total number of SN available.

Good product type wink
What is your question ?

Bye, Jona

Bye, Jona

 
Magento Community Magento Community
Magento Community
Magento Community
 
GenericSteele
Jr. Member
 
Total Posts:  8
Joined:  2009-07-31
 

Heh, I haven’t even gotten into the coding of this yet. I’m still trying to just get a new product type “Serial Number Product” to show as an option when creating a new product. What is the bare minimum I need to get a copy of the abstract product type to show up?

 
Magento Community Magento Community
Magento Community
Magento Community
 
JonathanJ
Member
 
Avatar
Total Posts:  60
Joined:  2008-08-27
Liege
 

You need to create a new module (here called Serialnumber).
In the module config file:

paste that into global tags:

<catalog>
    <
product>
        <
type>
            <
serialnumber translate="label" module="catalog">
                <
label>Serial Number Product</label>
                <
model>serialnumber/product_type_serialnumber</model>
                <
index_data_retreiver>serialnumber/catalogIndex_data_serialnumber</index_data_retreiver>
            </
serialnumber>
        </
type>
    </
product>
</
catalog>

You need ‘Serialnumber/Model/CatalogIndex/Data/Serialnumber.php’ like that:

<?php

class Namespace_Serialnumber_Model_CatalogIndex_Data_Serailnumber extends Mage_CatalogIndex_Model_Data_Abstract
{
    
    
/**
     * 
     * Retreive product type code
     * 
     * @return string
     */
    
public function getTypeCode()
    
{
        
return Namespace_Serialnumber_Model_Product_Type::TYPE_SERIALNUMBER;
    
}
    
}

also: ‘Serialnumber/Model/Product/Type.php’ like that:

<?php

class Namespace_Serialnumber_Model_Product_Type extends Mage_Catalog_Model_Product_Type_Abstract
{
    
    
const TYPE_SERIALNUMBER "serialnumber";
    
    public function 
isVirtual()
    
{
        
return true;
    
}
    
}

also: ‘Serialnumber/Model/Product/Type/Serialnumber.php’ like that:

<?php

class Namespace_Serialnumber_Model_Product_Type_Serialnumber extends Mage_Catalog_Model_Product_Type_Abstract
{
    
}

it should work

 
Magento Community Magento Community
Magento Community
Magento Community
 
GenericSteele
Jr. Member
 
Total Posts:  8
Joined:  2009-07-31
 

I know I don’t say it nearly enough, but I love you. Off to implement!

Also, how do you know that?

 
Magento Community Magento Community
Magento Community
Magento Community
 
JonathanJ
Member
 
Avatar
Total Posts:  60
Joined:  2008-08-27
Liege
 

I work every day with Magento (i’m a professional developer), i’ve followed a Gabriel Bouhatous training, and i have searched and searched again over the net wink

Happy to help you wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
GenericSteele
Jr. Member
 
Total Posts:  8
Joined:  2009-07-31
 

I’m very close. It’s showing up in the new product options. I neglected to wrap everything in my config.xml file in <config> and <global> tags.

Now, once I select the new “Serial Number Product” type and set up a new product, I get:

Fatal error: Call to a member function setConfig() on a non-object in ~/app/code/core/Mage/Catalog/Model/Product/Type.php on line 78.

Line 78 of Type.php is:

$typeModel->setConfig($types[$product->getTypeId()]);

Here is my Model/CatalogIndex/SerialNumberProduct.php:

<?php

class Ready_SerialNumberProduct_Model_CatalogIndex_Data_SerialNumberProduct extends Mage_CatalogIndex_Model_Data_Abstract
{
    
public function getTypeCode()
    
{
        
return Ready_SerialNumberProduct_Model_Product_Type::TYPE_SERIALNUMBERPRODUCT;
    
}
}

And here is my Model/Product/Type.php:

<?php

class Ready_SerialNumberProduct_Model_Product_Type extends Mage_Catalog_Model_Product_Type_Abstract
{
    
const TYPE_SERIALNUMBERPRODUCT "serialnumberproduct";
    public function 
isVirtual()
    
{
        
return true;
    
}
}

I really can’t tell you how much I appreciate this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
JonathanJ
Member
 
Avatar
Total Posts:  60
Joined:  2008-08-27
Liege
 

hum, post your config file plz…
Thanks wink

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2