Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 2
Create featured product and show in home page using custom attribute
 
razaul
Jr. Member
 
Total Posts:  4
Joined:  2009-10-29
Kolkata
 

Create featured product using custom attribute, show in home page:

1st step:- create a attribute featured with yes/no property from Catalog Input Type for Store Owner dropdown
include in attribute set
assign one product featured “yes” from manage products

2nd step: Cms pages -> home page content area write

{{block type="catalog/product_featured" name="product_featured" as="product_featured" template="catalog/product/featured.phtml"}}

3rd step: create custom module and block file “app/code/local/FeaturedProduct/Catalog/Block/Product/Featured.php”

<?php

class FeaturedProduct_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_Abstract
{
    
public function getFeaturedProduct()
    
{
        
//database connection object
        
$storeId Mage::app()->getStore()->getId();    
       
        
$resource Mage::getSingleton('core/resource');
        
$read $resource->getConnection('catalog_read');
        
$categoryProductTable $resource->getTableName('catalog/category_product');
      
        
$productEntityIntTable = (string)Mage::getConfig()->getTablePrefix() . 'catalog_product_entity_int';
        
$eavAttributeTable $resource->getTableName('eav/attribute');
    
        
// Query for featured product
        
$select $read->select()
                       ->
from(array('cp'=>$categoryProductTable))
                       ->
join(array('pei'=>$productEntityIntTable), 'pei.entity_id=cp.product_id', array())
                       ->
joinNatural(array('ea'=>$eavAttributeTable))
                       ->
where('pei.value=1')
                       ->
where('ea.attribute_code="featured"');
        
        
$row $read->fetchRow($select);

        return 
Mage::getModel('catalog/product')->setStoreId($storeId)->load($row['product_id']);
    
}
}

4th step: Create view file “app/design/frontend/base/default/template/catalog/product/featured.phtml”

<div>
      <
p><?php $_product=$this->getFeaturedProduct() ?></p>
<?php //print_r($_product);?>
   
<?php // Product Image ?>
           
<div style="float: left;"> <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" /></a>&nbsp;&nbsp;
           </
div>
<
div style="float: left;">
          <
p> <a href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></p>
          <
p><?php echo $this->htmlEscape($_product->getShortDescription()) ?></p>
           </
div>
</
div>

5th step: add this code under global tag in “app/etc/local.xml”

<blocks>
            <
catalog>
                <
rewrite>
                    <
product_featured>FeaturedProduct_Catalog_Block_Product_Featured</product_featured>
                </
rewrite>
            </
catalog>
        </
blocks>

Now you are ready to show featured product ....  grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
Trilby
Member
 
Total Posts:  31
Joined:  2009-07-05
 

Hi, I would be so happy if this would work for me, but I’m not getting anything.
It’s possible I don’t understand the beginning step, though I am sure I did the rest properly with your excellent details.
I have been using other versions of Magento, but this is my first time using 1.4.  I have set three Featured products, but maybe I am not doing this as you intended. 
I tried three other ways to get the featured products to display on the home page, but none of the methods are working.
The last one I tried almost worked - creating a category and putting the featured products in the category and using the ID to category ID to reference the group - but the result was a message that said there were no products matching the request.
Would you be so kind as to explain your first step better, if you think it will work with version 1.4?
Thank you so much for all the careful details.  .
Trilby

 
Magento Community Magento Community
Magento Community
Magento Community
 
lvekua
Jr. Member
 
Total Posts:  11
Joined:  2008-07-23
 

Works Great!!!
But couldn’t get multiple products to show as featured, only one product is showing…
Is there a way to display multiple products as featured???

 
Magento Community Magento Community
Magento Community
Magento Community
 
ggchamp
Sr. Member
 
Total Posts:  153
Joined:  2009-04-30
 

Hey thanks so nice and simple!

 
Magento Community Magento Community
Magento Community
Magento Community
 
webscot
Sr. Member
 
Total Posts:  192
Joined:  2009-05-12
 

We actually handled this a bit differently and have had no problems.

Although we are using 1.4.0.1, in System/Configuration/Design we are still using the “default” for Package with our own custom theme for the Themes (templates, skin, layout and default).

We used the same idea found at http://www.magentocommerce.com/wiki/how_to/add_featured_products_to_home_page.

Our Featured Items category id is 332.

We created a new file called featured.phtml and saved it in app/design/frontend/default/CUSTOM-THEME/template/catalog/product/featured.phtml

<p><img src="<?php echo $this->getSkinUrl('images/Featured.gif') ?>" width="130" height="20" border="0" /></p>
<?php $_productCollection=$this->getLoadedProductCollection() ?>
<?php 
if(!$_productCollection->count()): ?>
<div class="note-msg">
    
<?php echo $this->__('There are currently no Featured Items. Check back regularly as new products are featured regularly.'?>
</div>
<?php else: ?>

<div class="listing-type-grid catalog-listing">
<?php $_collectionSize $_productCollection->count() ?>

<ol class="ac-grid" style="margin-top:-10px;">
    
<?php $i=1; foreach ($_productCollection as $_product): ?>        
            
<li class="item">            
                <
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(135, 135) ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
            </
div>
            
        <
h5><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></h5>
                
<?php echo $this->getPriceHtml($_producttrue?>
                <?php 
if($_product->isSaleable()): ?>
                   
<a href="#" class="YOUR CLASS" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><img src="YOUR IMAGE FILE NAME.gif" width="95" border="0" /></a>
                
<?php else: ?>
                
<div class="out-of-stock"><?php echo $this->__('Out of stock'?></div>
                
<?php endif; ?>
                
<div class="clear"></div>
                <
class="add-to">
                    
<?php if ($this->helper('wishlist')->isAllow()) : ?>
                    
<a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-cart"><img src="YOUR IMAGE FILE NAME.jpg" align="absbottom" style="border:0;"><?php echo $this->__('Add to Wishlist'?></a>
                    
<?php endif; ?>
                    <?php 
if($_compareUrl=$this->getAddToCompareUrl($_product)): ?><br />
                    <
a href="<?php echo $_compareUrl ?>"><img src="YOUR IMAGE FILE NAME.gif" align="absbottom" style="border:0;"><?php echo $this->__('Add to Compare'?></a>
                    
<?php endif; ?>
                
</p>
            </
li>
        
<?php if($i%3==|| $i==$_collectionSize): ?>
<div style="clear:both"></div>
        
<?php endif; ?>
<?php $i
++; endforeach; $kol $_collectionSize?>
    
</ol>
</
div>
<?php endif; ?>

We kind of used the existing app/code/core/Mage/Catalog/Block/Product/List.php so as to not have to write new code and to prevent overwrites due to later upgrades to the core (unless of course, Varien completely changes the Abstract file in an upgrade) by copying List.php to app/code/local/Mage/Catalog/Block/Product/ and then renaming the file to Featured.php.

Be sure to change the class in the beginning of the file from:

class Mage_Catalog_Block_Product_List extends Mage_Catalog_Block_Product_Abstract
to
class Mage_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_Abstract

In our CMS home page we then added the following:

{{block type="catalog/product_list" name="home.catalog.product.featured" category_id="332" template="catalog/product/featured.phtml"}}

And, that is it. Works great for us.

 
Magento Community Magento Community
Magento Community
Magento Community
 
erictr1ck
Member
 
Total Posts:  56
Joined:  2009-02-12
 

just tried this in 1.4… don’t waste your time. it doesn’t work.

 
Magento Community Magento Community
Magento Community
Magento Community
 
webscot
Sr. Member
 
Total Posts:  192
Joined:  2009-05-12
 

Which method did not work for you?

 
Magento Community Magento Community
Magento Community
Magento Community
 
erictr1ck
Member
 
Total Posts:  56
Joined:  2009-02-12
 
webscot - 17 May 2010 04:38 PM

Which method did not work for you?

sorry, the original method posted didn’t work. your category method however did work. thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Amol Kharat
Jr. Member
 
Total Posts:  2
Joined:  2010-06-15
 

I have tried this for fetching multiple featured products.

$sql = ‘SELECT `cp`.*, `ea`.* FROM `catalog_category_product` AS `cp` INNER JOIN `catalog_product_entity_int` AS `pei` ON pei.entity_id=cp.product_id NATURAL JOIN `eav_attribute` AS `ea` WHERE (pei.value=1) AND (ea.attribute_code=\"featured\") group by cp.product_id’;
$data = Mage::getSingleton(\’core/resource\’) ->getConnection(\’core_read\’)->fetchAll($sql);
foreach($data as $row)
$arr[] = Mage::getModel(\’catalog/product\’)->setStoreId($storeId)->load($row[\’product_id\’]);
return $arr;

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kangaroos
Jr. Member
 
Total Posts:  18
Joined:  2009-09-30
 

I feel the link below works better for me:

http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/cms_and_home_page/add_featured_products_to_home_page

Remove this <?php echo $this->getToolbarHtml() ?> from the list.phtml

You can have:

multiple featured products
Products show in list or grid
Show “As Low As” Price

Cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ouisri
Jr. Member
 
Total Posts:  3
Joined:  2010-07-13
 
Kangaroos - 12 August 2010 06:21 PM

I feel the link below works better for me:

http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/cms_and_home_page/add_featured_products_to_home_page

Remove this <?php echo $this->getToolbarHtml() ?> from the list.phtml

You can have:

multiple featured products
Products show in list or grid
Show “As Low As” Price


Cheers

Yes, I’ve got it and its work. Thank you so much....

 
Magento Community Magento Community
Magento Community
Magento Community
 
mhunkler
Guru
 
Total Posts:  304
Joined:  2009-05-30
 

This is not working for me at all… I followed webscot’s post exactly and my home page just shows up blank… any ideas, i’m using 1.4.0.1

 
Magento Community Magento Community
Magento Community
Magento Community
 
mhunkler
Guru
 
Total Posts:  304
Joined:  2009-05-30
 

neither method here worked for me in 1.4.0.1.  I get a blank content area....

 
Magento Community Magento Community
Magento Community
Magento Community
 
M H Rasel
Jr. Member
 
Total Posts:  10
Joined:  2011-01-28
 
razaul - 05 March 2010 10:05 PM

Create featured product using custom attribute, show in home page:

1st step:- create a attribute featured with yes/no property from Catalog Input Type for Store Owner dropdown
include in attribute set
assign one product featured “yes” from manage products

2nd step: Cms pages -> home page content area write

{{block type="catalog/product_featured" name="product_featured" as="product_featured" template="catalog/product/featured.phtml"}}

3rd step: create custom module and block file “app/code/local/FeaturedProduct/Catalog/Block/Product/Featured.php”
<?php

class FeaturedProduct_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_Abstract
{
    
public function getFeaturedProduct()
    
{
        
//database connection object
        
$storeId Mage::app()->getStore()->getId();    
       
        
$resource Mage::getSingleton('core/resource');
        
$read $resource->getConnection('catalog_read');
        
$categoryProductTable $resource->getTableName('catalog/category_product');
      
        
$productEntityIntTable = (string)Mage::getConfig()->getTablePrefix() . 'catalog_product_entity_int';
        
$eavAttributeTable $resource->getTableName('eav/attribute');
    
        
// Query for featured product
        
$select $read->select()
                       ->
from(array('cp'=>$categoryProductTable))
                       ->
join(array('pei'=>$productEntityIntTable), 'pei.entity_id=cp.product_id', array())
                       ->
joinNatural(array('ea'=>$eavAttributeTable))
                       ->
where('pei.value=1')
                       ->
where('ea.attribute_code="featured"');
        
        
$row $read->fetchRow($select);

        return 
Mage::getModel('catalog/product')->setStoreId($storeId)->load($row['product_id']);
    
}
}


4th step: Create view file “app/design/frontend/base/default/template/catalog/product/featured.phtml”

<div>
      <
p><?php $_product=$this->getFeaturedProduct() ?></p>
<?php //print_r($_product);?>
   
<?php // Product Image ?>
           
<div style="float: left;"> <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" /></a>&nbsp;&nbsp;
           </
div>
<
div style="float: left;">
          <
p> <a href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></p>
          <
p><?php echo $this->htmlEscape($_product->getShortDescription()) ?></p>
           </
div>
</
div>

5th step: add this code under global tag in “app/etc/local.xml”

<blocks>
            <
catalog>
                <
rewrite>
                    <
product_featured>FeaturedProduct_Catalog_Block_Product_Featured</product_featured>
                </
rewrite>
            </
catalog>
        </
blocks>


Now you are ready to show featured product ....  grin

i have used this same code but i showed that to the home page. that way i add a xml for the home page layout like following

<block type="catalog/product_featured" name="product_featured" as="product_featured" template="catalog/product/featured.phtml"></block>

Thanks this code help me a lot.

 
Magento Community Magento Community
Magento Community
Magento Community
 
medlington2
Member
 
Total Posts:  63
Joined:  2011-02-04
 

Hi,

I’ve managed to get the products to show correctly in my middle column ‘content’ by using the method on the wiki and assigning the products to an inactive category but now I need to move it to the right hand column.

How would I go about this?

I tried changing the line

{{block type="catalog/product_list" category_id="8" template="catalog/product/list.phtml"}}

to

<block type="catalog/product_list" category_id="8" template="catalog/product/list.phtml"/>

and placed this in the design section rather than the content section and this did show the products but it wasnt limited to the inactive category and seemed to show all the products. It was as if it wasnt getting the information about the category number.

Is there a simple way to move the block to the right? or failing that could I hard code the category number into the file catalog/product/list.phtml somehow?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tusher Khan
Member
 
Total Posts:  66
Joined:  2011-01-07
 

You can easily display featured product on homepage by createting specific category.

Here is a simple way to do that:

http://www.xpressbangla.com/how-to-show-products-on-magento-homepage-from-specific-category/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2