Call-back icon  Sales: Call 800.374.8146 (N America)|757.278.0920 (International)

Magento

Open Source eCommerce Evolved

Magento Forum

   
Page 2 of 2
“Featured Product” feature
 
nafnaf1000
Sr. Member
 
Total Posts:  107
Joined:  2008-02-21
 

@pelted

did you forget to put a “<?php” on the top?

ps… I never get this code to work for me…

 
Magento Community Magento Community
Magento Community
Magento Community
 
redpen
Sr. Member
 
Total Posts:  174
Joined:  2008-01-23
 

Just got this working.  Can it be used to show more than one featured product per category?

 
Magento Community Magento Community
Magento Community
Magento Community
 
altansar
Member
 
Total Posts:  31
Joined:  2008-07-08
 

Hi everybody,

to begin I want to thanks Andy for this usefull “featured product” module.

It works for me, but I have a little question :

I would like to use this module to display products of any categories on my home page, instead of displaying a product in a category page.
So I tried to modify the code of the function getFeaturedProduct() in the app/code/local/MyCompany/Catalog/Block/Product/Featured.php file.
But I didn’t found how to select every products of my catalog, instead of selecting products from a particular category.

Thank you, and sorry for my english.

 
Magento Community Magento Community
Magento Community
Magento Community
 
altansar
Member
 
Total Posts:  31
Joined:  2008-07-08
 

I finally found a solution, it was not hard at least.

Here is the code to select all product marked as featured from any category :

public function getFeaturedProduct()
        
{
            $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()
                ->
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')->load($row['product_id'])));
        
}

Now i’m going to try to display a random item from all the items marked as featured, because I actually get the same item at every refresh.
I’ll post the code here if I find something.

 
Magento Community Magento Community
Magento Community
Magento Community
 
altansar
Member
 
Total Posts:  31
Joined:  2008-07-08
 

Ok, I finally have a working function to display a random article from theire who are marked as featured on my home page. You have to follow this tutorial and just change the function getFeaturedProduct() from app/code/local/MyCompany/Catalog/Block/Product/Featured.php by this code :

public function getFeaturedProduct()
        
{
            $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()
                ->
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"');
            
            
$res $read->fetchAll($select);
            return ((
Mage::getModel('catalog/product')->load($res[array_rand($res)]['product_id'])));
        
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
brianpat
Jr. Member
 
Total Posts:  19
Joined:  2008-04-05
 

I did as being said in the tutorial in wiki page. But it doesn’t show on any page. Is it working for any person? If so can anyone put this in the extension?

 
Magento Community Magento Community
Magento Community
Magento Community
 
cibernoid
Sr. Member
 
Avatar
Total Posts:  174
Joined:  2008-02-12
 
brianpat - 09 July 2008 07:35 AM

I did as being said in the tutorial in wiki page. But it doesn’t show on any page. Is it working for any person? If so can anyone put this in the extension?

I’ve just tried this and it doesn’t wokr to me. When I add the block on file “local.xml” all category pages are blank (without products).

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ron Phillips
Member
 
Total Posts:  42
Joined:  2008-04-16
 

Not to steal the significance of Andy’s thread, http://www.magentocommerce.com/boards/viewthread/4780/P0/, as it’s what got me started modding out my functions. And to get this to work you need to follow the same steps as far as getting this in place, so I won’t be redundant. Also I’m not the best of documenters.

Simply though looking at the way the Magento team handled New and Random, I simply thought, why don’t we do this with the Featured function. It would make it cleaner and utilize more of the core functions instead of using Zend DB to figure out how to build a query statement. So I don’t take much credit for this. It was already there, finding it was a chore though.

I did want it to be flexible though so that I can make it global or by category, change the order and the product number. And please note that it still is a bit custom for my needs and I’m pulling only the attributes I need.

public function getProductFeatured(){
        
    $product 
Mage::getModel('catalog/product');
    if(
$this->getCategoryId())
        
$category Mage::getModel('catalog/category')->load($this->getCategoryId());
    
    
$collection $product->getCollection()
            ->
addAttributeToSelect('name')
            ->
addAttributeToSelect('price')
            ->
addAttributeToSelect('image')
            ->
addAttributeToSelect('tax_class_id')
            ->
addAttributeToFilter('featured',array('yes'=>true));

    if(
$category)
    
$collection->addCategoryFilter($category);

    
$collection ->addStoreFilter();        
        
    if(
$this->getOrderby())    
        
$collection->getSelect()->order($this->getOrderby());
    if(
$this->getNumProducts())
        
$collection->getSelect()->limit($this->getNumProducts());

    
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);
    
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

    return 
$collection;

}

This a snippet from my singlebycategory.phtml template that I utilize on the “Shop Now” block of my current project: http://www.netizenron.com/boomsite.php.

<?php 
$chosen_category 
Mage::getModel('catalog/category')->load($this->getCategoryId());

$_productCollection $this->getProductFeatured();
?>

<?php 
if(!$_productCollection):?>
<div class="note-msg">
    
<?=$this->__('There are no products matching the selection.')?>
</div>
<?php else:?>

<?php 
foreach($_productCollection->getItems() as $_product): ?>

<div class="random" style="width:120px; text-align:center; float:left; margin:10px 8px;">
    <
class="image" href="<?=$_product->getProductUrl()?>"><img src="<?=$this->helper('catalog/image')->init($_product, 'image')->resize(100, 150);?>" alt="<?=$this->htmlEscape($_product->getName())?>"  border="0"/></a>
    <
div style="font-size:.75em"><a href="<?=$chosen_category->getUrl()?>" title="<?=$this->__('More products from this category ...')?>" style="text-decoration:none; color:#333333;"><?=$this->__("Browse All<br>")?><b style="font-size:1.35em;"><?=$chosen_category->getName()?>  <span style="color:#CC0000; margin-bottom:3px;">&raquo;</span></b></a></div>
</
div>

<?php endforeach;?>

//unset catalog to allow using template for multiple categories on single page
<?php endif; Mage::unregister("_singleton/catalog/layer");?>
Block invocation in the CMS
{{block type="catalog/product_custom" category_id="8" num_products="1" orderby="rand()" template="catalog/product/singlesbycategory.phtml"}}

 Signature 

Ron Phillips

 
Magento Community Magento Community
Magento Community
Magento Community
 
HueCity
Jr. Member
 
Total Posts:  1
Joined:  2008-07-12
 

It didn’t worked for me.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tilzinger
Jr. Member
 
Total Posts:  22
Joined:  2007-12-27
 

I successfully got this module working, however, I’m lacking a couple of things.

1. I have my featured product displayed on the same page as several other products on the category page, and the featured product is listed at the top of the page as a featured item (created from this module) then it’s also shown further down in the page with the rest of the product collection. How do I avoid repetition of the featured item?

2. I can only display the featured items name, SKU, description, and photo. I need to display all the options so a user can purchase the featured item without having to click into it’s detail page… how do I do this? Below is the code I have in featured.phtml

<script type="text/javascript">
    var 
optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<?php $_product
=$this->getFeaturedProduct() ?>
<div class="productDetail">
    <
form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form">
        <
div class="productPhoto">
            <
img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(400, 390); ?>" width="400" height="390" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
        </
div>
        <
div class="productInfo">
            <
h2><?php echo $this->htmlEscape($_product->getName()) ?></h2>
            <
class="small">Style# T608J01</p>
            
<?php if ($_product->getDescription()):?>
            
<p><?php echo nl2br($_product->getDescription()) ?></p>
            
<?php endif;?> 
            
            <?php 
if (!$this->hasOptions()):?>
                <?php 
echo $this->getChildHtml('tierprices'?>
                
<div class="add-to-holder">
                    
<?php if($_product->isSaleable()): ?>
                        <?php 
echo $this->getChildHtml('addtocart'?>
                        <?php 
if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
                            
<span class="add-or"><?php echo $this->__('OR'?></span>
                        
<?php endif; ?>
                    <?php 
endif; ?>
                    <?php 
echo $this->getChildHtml('addto'?>
                
</div>
            
<?php else:?>
                <?php 
echo $this->getChildHtml('addto'?>
            <?php 
endif; ?> 
            
            <?php 
if ($this->hasOptions()):?>
                <?php 
echo $this->getChildChildHtml('container1'''truetrue?>
                <?php 
echo $this->getChildChildHtml('container2'''truetrue?>
            <?php 
endif;?>  
            
            <?php 
//echo $this->getChildHtml('product_additional_data') ?>  
        
</div>
    
          <
input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
          <
input type="hidden" name="related_product" id="related-products-field" value="" />
    </
form>
    <
script type="text/javascript">
            var 
productAddToCartForm = new VarienForm('product_addtocart_form');
            
productAddToCartForm.submit = function(){
                    
if (this.validator.validate()) {
                            this
.form.submit();
                    
}
            }
.bind(productAddToCartForm);
    
</script>
</div>

 
Magento Community Magento Community
Magento Community
Magento Community
 
davidgrun
Jr. Member
 
Total Posts:  26
Joined:  2008-07-10
 

I got this error:

class MyCompany_Catalog_Block_Category_View extends Mage_Catalog_Block_Category_View { public function getFeaturedProductHtml() { return $this->getBlockHtml(’product_featured’); } } class MyCompany_Catalog_Block_Category_View extends Mage_Catalog_Block_Category_View { public function getFeaturedProductHtml() { return $this->getBlockHtml(’product_featured’); } }
Fatal error: Class ‘MyCompany_Catalog_Block_Category_View’ not found in /nfs/c02/h04/mnt/45486/domains/kehot.com.ar/html/app/code/core/Mage/Core/Model/Layout.php on line 445

What should I do??

THANKS!!

 Signature 

I love Magento!  (...just, please, make it run a bit faster...)

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 2 of 2
 
Sales: Call 800.374.8146 (North America) 757.278.0920 (International)
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
33726 users|317 users currently online|74734 forum posts