Magento Adding New Field in the product Custom Options

By | August 10, 2012
Magento had limited field in custom Options so if we required the New or To add the New field in the magento product Custom options just follow the steps

Note : Here DEAL is the new field you have to replace by your field name 


1) Open the file  adminhtml/default/default/catalog/product/edit/options/option.phtml

Just after this

  'jsQuoteEscape(Mage::helper('catalog')->__('Is Required')) ?>'+


Add the new field

 'jsQuoteEscape(Mage::helper('catalog')->__('Is Deal')) ?>'+

2) In the same file just after this

  'getRequireSelectHtml() ?>'+

Add the new field

  'getDealSelectHtml() ?>'+

3) In the same file check for the

  if (data.is_require) {
            $A($('getFieldId() ?>_'+data.id+'_is_require').options).each(function(option){
                if (option.value==data.is_require) option.selected = true;
            });
        }

And below that add

if (data.is_deal) {
            $A($('getFieldId() ?>_'+data.id+'_is_deal').options).each(function(option){
                if (option.value==data.is_deal) option.selected = true;
            });
        }

4) Open the file  app\code\core\Mage\Adminhtml\Block\Catalog\Product\Edit\Tab\Options\Option.php
and add in local folder app\code\core\Mage\Adminhtml\Block\Catalog\Product\Edit\Tab\Options\Option.php

search function getOptionValues()

 $value['is_require'] = $option->getIsRequire();

Add the follwoing code

 $value['is_deal'] = $option->getIsDeal();

 
and in the same file check this Fucntion  getRequireSelectHtml()

add new function

public function getDealSelectHtml()
    {
        $select = $this->getLayout()->createBlock('adminhtml/html_select')
            ->setData(array(
                'id' => $this->getFieldId().'_{{id}}_is_deal',
                'class' => 'select'
            ))
            ->setName($this->getFieldName().'[{{id}}][is_deal]')
            ->setOptions(Mage::getSingleton('adminhtml/system_config_source_yesno')->toArray());

        return $select->getHtml();
    }

6) and add the new filed in the db in the table catalog_product_option or you can upgrade the script for adding the new field for the product custom options

 That’s it just clear the cache and and refresh your Browser

14 thoughts on “Magento Adding New Field in the product Custom Options

  1. Ravi Soni

    Edit your path from :
    adminhtml/default/default/catalog/product/edit/options/option.phtml

    To :

    adminhtml/default/default/template/catalog/product/edit/options/option.phtml

    Reply
  2. Ravi Soni

    Cant find the function getOptionValues() i just have this line of code .
    //adding data to templates
    getOptionValues() as $_value): ?>
    productOption.add(toJson() ?>);
    productOptionType.addDataToValues(toJson() ?>);

    Reply
    1. Vinnie

      Were you able to figure this out? I need to do exactly this. Thank you.

      Reply

Leave a Reply