Get custom category attribute value in Magento

I added a special category attribute to my Magento installation with the following code:

<?php // initialize magento environment for 'default' store require_once 'app/Mage.php'; Mage::app('default'); echo "initialising"; echo runAdd(); echo "finishing"; function runAdd() { $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); // below code will add text attribute $setup->addAttribute('catalog_category', 'test_field', array( 'group' => 'General', 'input' => 'text', 'type' => 'varchar', 'label' => 'a new text field', 'backend' => '', 'visible' => 1, 'required' => 0, 'user_defined' => 1, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, )); } 

It is very difficult for me to get the value that I set at the end. I tried all the options:

 $_category = Mage::getModel('catalog/category')->load(1000); $data = $_category->getData(); $atts= $_category->getAttributes(); var_dump($data ); var_dump($atts); 

etc. but stuck.

Does anyone know how I can get this data?

+4
source share
2 answers

You should not update the database in stand-alone scripts, but you should use update scripts ...

If you had, you would not have to manually create the installer and not create an instance error: you must use Mage_Catalog_Model_Resource_Setup (or Mage_Catalog_Model_Resource_Eav_Mysql4_Setup depending on your version of magento), because Mage_Catalog uses the custom setup.xml file configured:

 <resources> <catalog_setup> <setup> <module>Mage_Catalog</module> <class>Mage_Catalog_Model_Resource_Setup</class> </setup> </catalog_setup> </resources> 

I suggest you adapt this in your config.xml module and use the install / update script to properly modify your database.

+4
source

you can write the following line that can help you

 $_category = Mage::getModel('catalog/category')->load(1000)->getData('test_field'); 
+4
source

Source: https://habr.com/ru/post/1442035/


All Articles