Magento Adding New Field in the product Custom Options

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

12 comments on “Magento Adding New Field in the product Custom Options

  1. Anonymous October 4, 2012 10:51 am

    Big Thanks for your post.

  2. Anonymous January 23, 2013 3:53 pm

    Dont mess in the Core files…so this a bad tweak!

  3. Sandeep Gulati January 24, 2013 4:13 pm

    ya very true messing the core file is bad idea..i will try to make customize module …

  4. Pratik April 15, 2013 1:19 pm

    Not Work in magento 1.7 please Help…

  5. Sandeep Gulati April 15, 2013 4:08 pm

    @pratik can you tell me what error you are getting

  6. Ravi Soni June 8, 2013 7:30 am

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

    To :

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

  7. Ravi Soni June 8, 2013 7:44 am

    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() ?>);

  8. Ravi Soni June 8, 2013 7:55 am

    Found it here :
    app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Option.php

Leave a Reply