0

How can I extend the "Custom Options" in a configurable product? I need to add a new field named Identifier. Where can I find the necessary templates?

Custom Field in Backend

I figured out that the template is in app\design\adminhtml\default\default\template\catalog\product\edit\options\option.phtml, and I added my custom code to it:

enter image description here

But I have no clue to which table I have to add the new attribute "identifier" ?

How can I figure this out?

I thought I have to add it to the table Catalog_Product_Edit_Options_Option because the template is in app\design\adminhtml\default\default\template\catalog\product\edit\options\option.phtml but this threw an error that the table could not be found.

How do I know the right table name where the attribute belongs to?

I tried to install it to the table catalog_product_option_type_value with this install script but it is not the right table, because if I enter something and save something then it is not saved:

<?php

Mage::log("Add attribute 'identifier' to table 'catalog_product_edit_options_option'", 7, "system.log");

$installer = $this;
$connection = $installer->getConnection();

$installer->startSetup();

$installer->getConnection()
    ->addColumn($installer->getTable('catalog_product_option_type_value'),
        'identifier',
        array(
            'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
            'input' => 'text',
            'nullable' => true,
            'default' => null,
            'comment' => 'Identifier of the Option, used to perform specific actions in scripts only on options with certain identifiers.'
        )
    );

$installer->endSetup();

I also added it to the table catalog_product_option but it still does not save.

Update: I noticed that the value is actually stored into the database, but magento fails to load it in the backend so it looks like it is empty. I used this query

SELECT * FROM `magecatalog_product_option` WHERE `option_id` = 443`

enter image description here

Why does it not show in the backend?

1

You are more than half the way done :-)

You have to overwrite the block Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option also and add your new column identifier in the method getOptionValues().

Add $value['identifier'] = $option->getIdentifier(); for example after $value['sort_order'] = $option->getSortOrder(); and with that you should have the data in the backend

  • 2
    Thx!! You saved my day :) Note: You should first search for classes which extends the class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option to figure out if there are already overrides. I had a overwrite in one of my extensions in app/code/local. Never edit core files! – Black Apr 9 at 12:11
  • 2
    I didn't say 'change code in Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option', but 'overwrite the block Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option' which means for me to create your own block extending that block. Sorry if the answer can be misunderstood. – HelgeB Apr 9 at 12:14
  • Yes I know, I just added the note in case someone does not know it – Black Apr 9 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.