Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
class Stereo_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_Abstract
{
protected $_productsCount = null;
const DEFAULT_PRODUCTS_COUNT = 12;
protected function _beforeToHtml()
{
$collection = $this->_addProductAttributesAndPrices(Mage::getResourceModel('catalog/product_collection'))
->addStoreFilter()
->addAttributeToFilter('featured', array('yes'=>true))
->setPageSize($this->getProductsCount())
->setOrder('RAND()')
->setCurPage(1)
;
$this->setProductCollection($collection);
return parent::_beforeToHtml();
}
public function setProductsCount($count)
{
$this->_productsCount = $count;
return $this;
}
public function getProductsCount()
{
if (null === $this->_productsCount) {
$this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
}
return $this->_productsCount;
}
/*
public function getFeaturedProducts() {
$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('catalog_read');
$productEntityIntTable = (string)Mage::getConfig()->getTablePrefix() . 'catalog_product_entity_int';
$eavAttributeTable = $resource->getTableName('eav/attribute');
$categoryProductTable = $resource->getTableName('catalog/category_product');
$select = $read->select()
->distinct(true)
->from(array('cp'=>$categoryProductTable), 'product_id')
->join(array('pei'=>$productEntityIntTable), 'pei.entity_id=cp.product_id', array())
->joinNatural(array('ea'=>$eavAttributeTable))
->where('pei.value=1')
->where('ea.attribute_code="featured"');
$res = $read->fetchAll($select);
return $res;
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment