0

How to get category using url_key and parent category_id? If category structure is as follows

-Root
  --Mobile
    ---Android
    ---Windows
    ---iOs
  --Tablet
    ---Android
    ---Windows
    ---iOs

Then using following code if try to load iOs category using url_key it load always load root->Mobile->iOS

$category = Mage::getModel('catalog/category')
    ->setStoreId(Mage::app()->getStore()->getId())
    ->loadByAttribute('url_key', 'cat_urlkey');

How I can modify code so that, sub category load by url_key and respective parent category_id?

3

You can load the attributes collection and get it's first element:

$categories = Mage::getResourceModel('catalog/category_collection');
$categories->addAttributeToSelect('*');

$categories->addAttributeToFilter('url_key', 'cat_urlkey');
$categories->addAttributeToFilter('path', array('like' => '1/15/%');

The second condition tells to take subcategories of the category with id 15.

| 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.