1

I'm having problems trying to create a new option "Manage Options" when creating an attribute, do not know how to save the data correctly in the database, I'm overwriting "Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options" with my module to create custom fields, I want he save these fields when I save the attribute.

My Module:

config.xml

<config>
        <blocks>
            <adminhtml>
                <rewrite>
                     <catalog_product_attribute_edit_tabs>Ceicom_Swatches_Block_Adminhtml_Tabs</catalog_product_attribute_edit_tabs>
                     <catalog_product_attribute_edit_tab_options>Ceicom_Swatches_Block_Adminhtml_Options</catalog_product_attribute_edit_tab_options>
                 </rewrite>
             </adminhtml>
        </blocks>
</config>

Ceicom/Swatches/Block/Adminhtml/Options.php

class Ceicom_Swatches_Block_Adminhtml_Options extends Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Options
{
    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('ceicom/attribute/options.phtml');
    }
}

in the phtml file I put in the custom fields

enter image description here

any idea how I can save the values ​​of these fields in the bank correctly?

0

To do that you need to add new columns to eav_attribute_option table.

For example field_1, field_2.

To make your additional fields save rewrite

Mage_Eav_Model_Resource_Entity_Attribute::_saveOption()

Find code:

$sortOrder = !empty($option['order'][$optionId]) ? $option['order'][$optionId] : 0;
if (!$intOptionId) {
    $data = array(
        'attribute_id'  => $object->getId(),
        'sort_order'    => $sortOrder
    );
    $adapter->insert($optionTable, $data);
    $intOptionId = $adapter->lastInsertId($optionTable);
} else {
    $data  = array('sort_order'    => $sortOrder);
    $where = array('option_id =?' => $intOptionId);
    $adapter->update($optionTable, $data, $where);
}

And change it to

$sortOrder = !empty($option['order'][$optionId]) ? $option['order'][$optionId] : 0;
$field1 = !empty($option['field1'][$optionId]) ? $option['field1'][$optionId] : '';
$field2 = !empty($option['field2'][$optionId]) ? $option['field2'][$optionId] : '';
$data = array(
    'sort_order'    => $sortOrder,
    'field1'        => $field1,
    'field2'        => $field2
);
if (!$intOptionId) {
    $data['attribute_id'] = $object->getId();
    $adapter->insert($optionTable, $data);
    $intOptionId = $adapter->lastInsertId($optionTable);
} else {
    $where = array('option_id =?' => $intOptionId);
    $adapter->update($optionTable, $data, $where);
}

The only thing that left is to display saved values in edit form.

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.