0

i am using magento enterprise edition, i have created a module to add custom attributes to the categories , the attributes are visible in adminhtml and they are saved propertly but when i try to retrieve the category on frontend, it doesnot contain the attributes i just created and i alredy reindex all but nothing, the problem is magento enterprise because i tried in magento community and works fine, here is my code

   $installer = Mage::getResourceModel('catalog/setup','catalog_setup');
    $installer->startSetup();
    $label="whatever";

 $installer->addAttribute('catalog_category', $label, array(
                   'type' => 'int',
                   'label' => $label,
                   'input' => 'select',
                   'source'  => 'eav/entity_attribute_source_boolean',
                   'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
                   'visible' => true,
                   'required' => false,
                   'default' => '0',
                   "visible_on_front"  => true,
                   'group' => 'filter9',
               ));

here is the config file

 <?xml version="1.0"?>
 <config>

 <modules>
     <Qxd_Categories>
         <version>0.0.6</version>
     </Qxd_Categories>
 </modules>
         <admin>
             <routers>
                 <adminhtml>
                    <args>
                    <modules>
                             <Qxd_Categories before="Mage_Adminhtml">Qxd_Categories_Adminhtml</Qxd_Categories>
                         </modules>
                    </args>
                </adminhtml>
            </routers>
        </admin>

<global>
    <resources>
        <qxd_categories_setup>
            <setup>
                <module>Qxd_Categories</module>
                <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </qxd_categories_setup>
        <qxd_categories_setup_write>
            <connection>
                <use>core_write</use>
            </connection>
        </qxd_categories_setup_write>
        <qxd_categories_setup_read>
            <connection>
                <use>core_read</use>
            </connection>
        </qxd_categories_setup_read>
    </resources>
</global>

 </config>

And this is front end where i am trying to reindex data and retrieve the category:

 $categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*');
 $process = Mage::getModel('index/process')->load(5);   $process->reindexAll();
  $process = Mage::getModel('index/process')->load(6);    $process->reindexAll();
 foreach ($categories as $category) {



$cat = Mage::getModel("catalog/category")->load($category->getId());
if($cat->getData('entity_id')=='7'){
        var_dump($cat->getData()); // all but my attribute
        var_dump($cat); // my attribute is not there :(

        var_dump($cat->getName()); // My  Category Name
     }

 }

Any suggestion is welcome, please help me!!

0

Your attribute code is whatever when you can this field by $cat->getWhatever(); If this attribute is what_ever the _ (underscore make next letter of capital) thus

$cat->getWhatEver();
  • 1
    ignore that line, when i did var_dump($cat->getData()), my attribute is not there. or when i do var_dump($cat) my attribute is not there :( – MaynorSong Jun 26 '14 at 14:24
4

You can get all your categories for a specific store using a helper:

$helper = Mage::helper('catalog/category');
$categories = $helper->getStoreCategories();

Then you can add your attribute to this collection by adding the following to your modules config.xml.

<frontend>
    <category>
        <collection>
            <attributes>
                <your_attribute/>
            </attributes>
        </collection>
    </category>
</frontend> 
  • the problem is that the attributes must be created dynamically and in adminhtml the user decides the value so i cant use xml for this =S – MaynorSong Jun 26 '14 at 15:24

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.