XML : Featured products in magento home page

I want to show featured product in home page.So I Created custom module and block file in app/code/local/FeaturedProduct/Catalog/Block/Product/Featured.php

Code :

  class FeaturedProduct_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_List  {  protected $_productCollection;  public function fetchProducts()  {     $this->productCollection =Mage::getModel('catalog/product')->getCollection()      ->addAttributeToSelect('*')      ->addFieldToFilter('featured_products', array('eq' => '1'));    return $this->productCollection;  }  }    

Created a configuration file in app/code/local/FeaturedProduct/Catalog/etc/config.xml

Code:

  <!--?xml version="1.0" encoding="UTF-8"?-->  <config>  <modules>      <featuredproduct_catalog>          <version>1.0.0</version>                              </featuredproduct_catalog>  </modules>  <global>      <blocks>          <featuredproducts>              <class>FeaturedProduct_Catalog_Block</class>          </featuredproducts>      </blocks>  </global>  <frontend>      <layout>          <updates>              <featuredproducts>                  <file>featuredproduct.xml</file>              </featuredproducts>          </updates>      </layout>  </frontend>  </config>    

Created featuredproducts.xml in location app/design/frontend/rwd/default/layout/featuredproduct.xml

Code:

  <!--?xml version="1.0" encoding="UTF-8"?-->  <layout version="0.1.0">  <cms_index_index translate="label">      <reference name="content">          <block type="featuredproducts/products_featured" name="featured_product_collection" template="catalog/product/featured.phtml">              <action method="setColumnCount">                  <columns>4</columns>              </action>          </block>      </reference>  </cms_index_index>  </layout>    

Created a view file "app/design/frontend/rwd/default/template/catalog/product/featured.phtml"

Code:

  <!--?php  $_featuredProductCollection = $this--->fetchProducts();  $_helper = $this->helper('catalog/output');  ?>  <div>  <!--?php if (!$_featuredProductCollection--->count()): ?>  <h2><p><!--?php echo $this--->__('There are no products in the featured product list!!') ?></p></h2>  <!--?php else: ?-->  <div class="category-products-grid">   <!--?php // Grid Mode ?-->   <!--?php $_collectionSize = $_featuredProductCollection--->count() ?>   <!--?php $_columnCount = $this--->getColumnCount(); ?>   <!--?php $i = 0;    foreach ($_featuredProductCollection as $_product): ?-->      <!--?php if ($i++ % $_columnCount == 0): ?-->      <ul class="products-grid first last odd">      <!--?php endif ?-->      <li class="item<?php if (($i - 1) % $_columnCount == 0): ?> first                 <?php elseif ($i % $_columnCount == 0): ?> last<?php endif; ?>">      <div class="productGrid-description">      <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo          $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo          $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'),                  null, true) ?>"></a>       <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><!--?php echo     $_helper--->productAttribute($_product, $_product->getName(), 'name') ?></a></h3></div>    <!--?php if ($_product--->getRatingSummary()): ?>    <!--?php echo $this--->getReviewsSummaryHtml($_product, 'short') ?>    <!--?php endif; ?-->    <!--?php echo $this--->getPriceHtml($_product, true) ?>    <!--?php if ($_product--->isSaleable()): ?>      <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo                 $this->getAddToCartUrl($_product) ?>')">        <span class="btn-cart-container"><!--?php echo $this--->__('Add to Cart') ?></span>     </button>   <!--?php else: ?-->       <p class="availability out-of-stock">         <span><!--?php echo $this--->__('Out of stock') ?></span></p>   <!--?php endif; ?-->       </li>           <!--?php if ($i % $_columnCount == 0 || $i == $_collectionSize): ?-->   </ul>  <!--?php endif ?-->  <!--?php endforeach ?-->  </div>  <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd', 'even', 'first', 'last'])</script>   </div>   <!--?php endif; ?-->    

Created a Featured Attribute in Magento Backend with yes/no property from Catalog Input Type for Store Owner dropdown, then include it in attribute set and assign one product as Featured "yes" from Catalog->Manage Products. And after I load the home page it displays nothing.No idea where i have made mistake.I do not want to change local.xml so took this aproach.Is there any thing more I have to do or create other files? Please help .

No comments:

Post a Comment