Magento get category id by category name and category parent name -
i'm able category id using category name in snippet below
$category = mage::getresourcemodel('catalog/category_collection')->addfieldtofilter('name', 'clothing'); $cat= $category->getdata(); $categoryid = $cat[0][entity_id];
the problem, however, if 2 parent categories have subcategories same name, how can category id using parent name
for instance category men has subcategory clothing , category women has subcategory clothing. using abve code return id clothing in women or clothing in men. want find way ensure subcategory id clothing men or vice versa.
any pointers appreciated
in case want parent first, appropriate child:
$category = mage::getresourcemodel('catalog/category_collection') ->addfieldtofilter('name', 'men') ->getfirstitem() // parent category ->getchildrencategories() ->addfieldtofilter('name', 'clothing') ->getfirstitem(); // child category $categoryid = $category->getid();
Comments
Post a Comment