Friday, August 10, 2012

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
  '<th class="opt-req"><?php echo $this->jsQuoteEscape(Mage::helper('catalog')->__('Is Required')) ?></th>'+

Add the new field

 '<th class="opt-deal"><?php echo $this->jsQuoteEscape(Mage::helper('catalog')->__('Is Deal')) ?></th>'+

2) In the same file just after this
  '<td class="opt-req"><?php echo $this->getRequireSelectHtml() ?></td>'+

Add the new field
  '<td class="opt-deal"><?php echo $this->getDealSelectHtml() ?></td>'+

3) In the same file check for the
  if (data.is_require) {
            $A($('<?php echo $this->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($('<?php echo $this->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:

  1. Good tweaks! can you post some on Magento GO

    ReplyDelete
  2. Big Thanks for your post.

    ReplyDelete
  3. Dont mess in the Core files...so this a bad tweak!

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

    ReplyDelete
  5. Not Work in magento 1.7 please Help...

    ReplyDelete
  6. @pratik can you tell me what error you are getting

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

    To :

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

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

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

    ReplyDelete
  10. Can you please post a tutorial for how to do this: please check this
    http://postimg.org/image/sxe25labr/

    ReplyDelete

Thankyou for your Comments

LinkWithin

Blog has moved, searching new blog...