Get Category by Product and Store – Magento with direct SQL

Posted on Updated on

  private static function getCategoryByProductAndStore($productId, $storeId, $isParent = 0)
{
$query = ‘SELECT category_id FROM `catalog_category_product_index` WHERE product_id = ‘ . $productId
. ‘ AND store_id=’ . $storeId . ‘ AND is_parent=’ . $isParent . ‘;’;
$data = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’)->fetchAll($query);
return $data;
}

Advertisements