Question

I have an array with 3 categories names:

$arr = ['onecat','twocat','threecat'];

How can I get the IDs from this categories? For example in other array.

Was it helpful?

Solution

Make a category Collection in 1.x Version then filter That Collection in condtion;

    $collection=Mage::getResourceModel('catalog/category_collection')
->addAttributeToFilter('name',['in' =>$arr]);

Then those category ids by getAllids()

$collection->getAllIds();

Or:

 $collection=Mage::getResourceModel('catalog/category_collection')
->addAttributeToFilter('name',['in' =>$arr])->addAttributeToSelect('*');
foreach ($collection as $category) {
echo $category->getId();

}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top