I am trying to pull category that belongs to current store only but it doesn\'t seem to work. Can anyone see any issue in my code?
$categoryCollection = Mage
i know it is an old question, but if someone is looking for the answer as i just was:
->addStoreFilter( {storeID} )
did it for me...
In Magento 1.9
$storeId=2;
$rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
$categories = Mage::getModel('catalog/category')
->getCollection()
->setStoreId($storeId)
->addFieldToFilter('is_active', 1)
->addAttributeToFilter('path', array('like' => "1/{$rootCategoryId}/%"))
->addAttributeToSelect('*');
foreach($categories as $categorie)
{
$catid=$cat->getId();
$catname=$categorie->getName();
$catp=catp$categorie->getParent_id();
}
I spent a lot of time.... this exaple work for me...
$store = Mage::app()->getStore()->getId();
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$rootpath = Mage::getModel('catalog/category')
->setStoreId($store)
->load($rootCategoryId)
->getPath();
$categories = Mage::getModel('catalog/category')->setStoreId($store)
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('path', array("like"=>$rootpath."/"."%"));
fix for multistore :)
setStoreId - not work, can remove
Neither setStoreId()
nor addAttributeToFielter('store_id', $storeId)
don't work because there's no store_id
in the category tables. The code below works perfectly:
$storeId = 21; // your store id
$rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCollection();
$categories->addAttributeToFilter('path', array('like' => "1/{$rootCategoryId}/%"));
Try this
$categoriesCollection = Mage::getModel('catalog/category')
->getCollection()
->setStoreId(1)
->addFieldToFilter('include_in_menu', array('eq' => 1))
->addFieldToFilter('level', array('eq' => 2))
->addFieldToFilter('is_active', array('eq'=>'1'))
->setOrder('position', 'asc')
->addAttributeToSelect('*');
Hello check following code may be help you
->addFieldToFilter('store_id', Mage::app()->getStore()->getId());
OR
$storeId =Mage::app()->getStore()->getStoreId();
$collection->setStoreId($storeId);
$collection->addStoreFilter($storeId);