|
Hi all,
I had referred to the post
http://www.magentocommerce.com/boards/viewthread/4454/
and attempted to use this functionality of displaying products on the home page driven by a custom attribute ‘featured_yn’ which when set for a product will display this on my store home page. The Block class gets instantiated but the template HTML is not rendering :(
Followed the below steps:
1. Create an attribute “featured_yn” and set possible values to be “Yes” and “No”.
2. Attach the attribute to the attributeset.
3. Create the Block class app/code/local/XYZ/Catalog/Block/Product/Featured.php
<?php class XYZ_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_Abstract { public function __construct() { parent::__construct();
$storeId = Mage::app()->getStore()->getId(); $product = Mage::getModel('catalog/product'); /* @var $product Mage_Catalog_Model_Product */ $todayDate = $product->getResource()->formatDate(time()); $products = $product->setStoreId($storeId)->getCollection() ->addAttributeToFilter('featured_yn', array('Yes'=>true)) ->addAttributeToSelect(array('name', 'price', 'small_image'), 'inner') ->addAttributeToSelect(array('special_price', 'special_from_date', 'special_to_date'), 'left') ; /* @var $products Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
$products->setOrder('hot_deals')->setPageSize(5)->setCurPage(1);
$this->setProductCollection($products);
} }
4. Create the template file app/design/frontend/xyzInterface/default/template/catalog/product/featured.phtml
<?php echo 'Test check calling featured products =='.$_products->getSize(); if (($_products = $this->getProductCollection()) && $_products->getSize()): ?> <div class="home-page-cntr"> <?php $i=0; foreach ($_products->getItems() as $_product): ?> <?php if ($i>5): continue; endif; ?>
<div class="home-page-item"> <div class="home-page-img"> <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"> <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(65,65); ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/> </a> </div> <div class="home-page-txt"> <p><a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $_product->getName() ?></a></p> <?php echo $this->helper('review/product')->getSummaryHtml($_product, 'short') ?> <?php echo $this->helper('catalog/product')->getPriceHtml($_product) ?> </div> </div> <?php $i++; endforeach; ?> <?php for($i;$i%5!=0;$i++): ?> <?php endfor ?> </div> <?php endif; ?>
5. Add CSS markup. Added the required CSS markup in boxes.css
/* CUSTOM STYLES */ /* Controls featured items on home page */ .home-page-cntr{ margin: 15px 0 0 0; font-size: 11px; } .home-page-cntr a{ text-decoration: none; font-weight: normal; } .home-page-cntr a:hover { color: #000000;} .homeContent h3 { width: 150px; font-size: 12px; padding: 2px 5px; color: #fff; background-color: #4F3E2E; } .home-page-item, .home-page-item1{ float: left; width: 110px; height: 120px; padding: 8px 8px 8px 0; margin: 5px 5px 10px 0px; line-height: 16px; }
.home-page-img{ text-align: center; border: 1px solid #eee; width: 100px; height: 125px; padding: 2px; } .home-page-img:hover { border: 1px solid #006699;} .home-page-txt{ font-size: 11px; color: #003366; }
6. Update homepage CMS from admin login (CMS->Manage Pages->LayoutUpdate XML)
<reference name="content"> <block type="catalog/product_featured" name="home.catalog.product.featured" alias="product_featured" template="catalog/product/featured.phtml"/> <block type="reports/product_viewed" name="home.reports.product.viewed" template="reports/home_product_viewed.phtml" after="product_new"/> </reference>
<reference name="right"> <block type="reports/product_viewed" before="right.permanent.callout" name="left.reports.product.viewed" template="reports/product_viewed.phtml" /> <action method="unsetChild"><name>cart_sidebar</name></action> <action method="unsetChild"><name>right.poll</name></action> <action method="unsetChild"><alias>right.reports.product.viewed</alias></action> <action method="unsetChild"><alias>right.reports.product.compared</alias></action> </reference>
7. Added block class in custom local module catalog config.xml file (app\code\local\XYZ\Catalog\etc\config.xml)
.... .. . <blocks> <catalog> <rewrite> <product_featured>XYZ_Catalog_Block_Product_Featured</product_featured> </rewrite> </catalog> </blocks> <global> .. ..
Cache was disabled. The design interface is correctly set to “xyzInterface” in admin configuration for my store.
Can’t think of checking anything else :( ...can someone please help?
Thanks in advance!!!
|