Friday, 6 July 2012

Display special priced products on your Magento homepage

Step one
Open your homepage CMS page and click on the design tab. Paste the following:





9

 
Step two:
 
First of all this is the code were that we're going to be using to do this.
 
Mage::getSingleton('core/session', array('name' => 'frontend'));
$_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addStoreFilter();

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($_productCollection);

$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);

$_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('special_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $tomorrowDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left');


echo '
';
$_collectionSize = $_productCollection->count();
$i=0; foreach($_productCollection as $_product):
if($i++%3==0)
echo '
    ';

    echo '
  1. ';
    echo '
    ';
    echo '';
    echo ''.$this->htmlEscape($this->getImageLabel($_product, 'small_image')).'
    ';
    echo '
    '.$this->htmlEscape($_product->getName()).'
    ';

    echo $this->getPriceHtml($_product, true) ?>




 

You can then paste this into a file and name it specials.phtml and save it into your frontend template folder catalog/product.

No comments: