Skip to content

Instantly share code, notes, and snippets.

@stereoscott
Created March 31, 2010 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stereoscott/350759 to your computer and use it in GitHub Desktop.
Save stereoscott/350759 to your computer and use it in GitHub Desktop.
<?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