2

When adding/editing an attribute it is possible to set a number of frontend properties such as "allow HTML tags on frontend" or "used in product listing". I would like to add some additional frontend properties. I am thinking of things like "include in pdf" and "logged in users only".

I have tried modifying the catalog_eav_attribtes table directly and adding some new columns. I have then overridden the

core/Mage/Adminhtml/Block/Catgalog/Product/Attribute/Edit/Tab/Main.php

$fieldset->addField('is_in_simple_list', 'select', array(
    'name' => 'is_in_simple_list',
    'label' => Mage::helper('catalog')->__('Visible in Simple Lists on Frontend'),
    'title' => Mage::helper('catalog')->__('Visible in Simple Lists on Frontend'),
     'note'      => Mage::helper('catalog')->__('Custom field for project'),
    'values' => $yesnoSource,
));   

to include controls for the new fields.

However, whilst the controls appear, the value of the data does not save. Any thoughts as the the next step which I am missing and if there are any ramifications down the line to doing this?

Thanks

  • If I set it in the database manually then the form control correctly says "yes" but am unable to save the change made in the admin. – Jon Holland Apr 10 '17 at 15:45
1
+50

Move your core file to app/code/local/Mage/Adminhtml/Block/Catalog/Product/Attribute/Edit/Tab/Main.php

Your code is correct. Put the same code in above file.

Make sure you are using correct data type for the database table field. You can use int(1) for Yes/No field.

Use the same column name in database table as you have field name in form. e.g. add a column is_in_simple_list in catalog_eav_attribute table for is_in_simple_list field.

Remove var/cache folder manually. If you have compilation enabled, recompile your code.

Now check by changing the attribute field value and saving attribute in admin panel.

  • actually if you read my post I have overridden that file and not changed the core file. – Jon Holland Apr 25 '17 at 9:03
  • What you have said is what I have already done and the field is in the DB and the form field is showing and will show the value in the DB. However the value set in the form does not save. I guess I will need to trawl through the process step by step and see what is and is not happening. Thanks for taking the time to respond though. – Jon Holland Apr 25 '17 at 9:06
  • I have tried the same thing on my setup and I can save values in database. Just try to remove var/cache and var/session. It should work. – Jaimin Sutariya Apr 25 '17 at 16:34
  • will give it another crack – Jon Holland Apr 26 '17 at 13:38
  • Have given you the 50 rep as I offered it but haven't yet had time to look at it again as have been on another project. I have caching switched off on my dev area anyhow. – Jon Holland May 2 '17 at 8:37
0

I have finally discovered what was missing. One needs to overwrite the Mage_Catalog_Model_Resource_Setup class

and add the new fieldname into the _prepareValues() function/method.

...
        'apply_to'                      => $this->_getValue($attr, 'apply_to'),
        'position'                      => $this->_getValue($attr, 'position', 0),
        'is_configurable'               => $this->_getValue($attr, 'is_configurable', 1),
        'is_used_for_promo_rules'       => $this->_getValue($attr, 'used_for_promo_rules', 0),
        'is_in_simple_list'             => $this->_getValue($attr, 'is_in_simple_list', 0),
...

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.