<?php
class MyCompany_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_Abstract
{
public function getFeaturedProducts(){
$ids = $this->_getFeaturedProductsIds();
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->getSelect()->where('e.entity_id in (?)', $ids);
$collection->addAttributeToSelect('*');
$productList = $collection->load();
return $productList;
}
public function _getFeaturedProductsIds(){
// instantiate database connection object
$categoryId = $this->getRequest()->getParam('id', false);
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('catalog_read');
$categoryProductTable = $resource->getTableName('catalog/category_product');
//$productEntityIntTable = $resource->getTableName('catalog/product_entity_int'); // doesn't work
$productEntityIntTable = (string)Mage::getConfig()->getTablePrefix().'catalog_product_entity_int';
$eavAttributeTable = $resource->getTableName('eav/attribute');
var_dump($productEntityIntTable); exit;
// Query database for featured product
$select = $read->select()
->from(array('cp'=>$categoryProductTable))
->join(array('pei'=>$productEntityIntTable),'pei.entity_id=cp.product_id', array())
->joinNatural(array('ea'=>$eavAttributeTable))
->where('cp.category_id=?', $categoryId)
->where('pei.value=1')
->where('ea.attribute_code="terry"');
$rows = $read->fetchAll($select);
$ids = array();
foreach($rows AS $row) {
$ids[] = $row['product_id'];
}
$ret = implode(',', $ids);
return $ids;
}
}
?>