0

once i use

$category = Mage::getModel('catalog/category')->getCollection();
            $category->addAttributeToFilter("Top_Menu" , array('eq' => '146'));
            $category->addAttributeToSelect('name','parent_id','entity_id','url');
            $category->setOrder("parent_id", "ASC");
            //$category->load();

How do i access 'name','parent_id','entity_id','url' with out using get I don't want to call the Database as its making my server slow.

0

to see what attributes (and values) are contained within $category you should use something like:

mage::log($category, null, 'mylogfile.log', true);

or more primitively:

var_dump($category);

This will tell you exactly what is within your model. You can then use magentos magic functions to retrieve certain attributes within your category object.

For example, let's say you used something similar to above to create a $product. And price is an attribute of product you can use things like this to retrieve that information from the object model:

$product = Mage::registry('current_product'); <---this is a db call
$price = $product->getPrice() <--- this is not
|improve this answer|||||
  • but getPrice() will be a database call right? – nikhil carvalho Nov 17 '14 at 18:30
  • No, it's a function call against the instantiated product model. – hownowbrowncow Nov 17 '14 at 18:33
  • can you comment here magento.stackexchange.com/questions/44391/optimizing-code – nikhil carvalho Nov 17 '14 at 18:44
  • Is there any other way other than using "Get"? – nikhil carvalho Nov 17 '14 at 19:36
  • I'll take a look over there. other than a generic getData($x), I don't think so. You should check which functions are resulting in db queries because, as described above, things like 'name', 'parentid', and 'price' are usually attributes of the instantiated model and do not result in db queries. – hownowbrowncow Nov 17 '14 at 19:45
0

In your case $category is actually a collection of categories.
You can access the values like this:

foreach ($category as $categoryItem) {
    $entityId = $categoryItem->getId();
    $name[$entityId] = $categoryItem->getName();
    $parentId[$entityId] = $categoryItem->getParentId();
    $url[$entityId] = $categoryItem->getUrl();
}

with out using get I don't want to call the Database as its making my server slow.

you cannot retrieve db values without touching the db.

|improve this answer|||||

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.