Call-back icon  Enterprise Sales: +1.310.775.2674 (N. America)   +44 20.3286.4137 (UK)

Magento

eCommerce Software for Online Growth

Magento Forum

   
ways to show products at the home page
 
flyingoat
Jr. Member
 
Total Posts:  3
Joined:  2008-07-26
 
dan_w - 27 March 2008 06:53 AM

Now to get the products to appear on the homepage, place this in your homepage cms page wherever you want the products to appear:

{{block type="catalog/product_homepage" name="home.catalog.product.homepage" alias="product_homepage" template="catalog/product/homepage.phtml"}}

Hi, dan, I followed the steps and the featured products did show in homepage, but I also got a fatal error: 
Fatal error: Class ‘Mage_Review_Helper_Product’ not found in E:\xampp\htdocs\app\code\core\Mage\Core\Model\App.php on line 779

Any suggestions?

 
Magento Community Magento Community
Magento Community
Magento Community
 
scriptnewbie
Jr. Member
 
Total Posts:  3
Joined:  2008-08-03
 
mikej165 - 04 August 2008 09:22 AM

Aha! When it doubt, it’s probably a typo.


I was using this:
{{block type=”category/product_list” category_id=”15” template=”catalog/product/list.phtml”}}

After re-reading your post, I changed it to this:
{{block type="catalog/product_list" category_id="15" template="catalog/product/list.phtml"}}

All is well and good in the universe now. Thank you very much!

Thank you mikej165. That works on me. But now, can anybody show how to display the “Shop By” box on the LEFT side so we can sort the items by attribute? because it didnt appear. Thank you very much

 
Magento Community Magento Community
Magento Community
Magento Community
 
tilzinger
Sr. Member
 
Total Posts:  80
Joined:  2007-12-27
 

Don’t know if anyone has posted this, but I used a combination of dan_w’s post (#9 in this thread) and the following info: http://www.magentocommerce.com/boards/viewthread/4780/

Dan’s solution added code to the core files, which isn’t the best way to go about this.

In app/code/local/STORENAME/Catalog/Block/Product/Homepage.php

class STORENAME_Catalog_Block_Product_Homepage 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_store_front', 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);

    
}
}

app/design/frontend/STORENAME/default/template/catalog/product/homepage.phtml

<?php if (($_products $this->getProductCollection()) && $_products->getSize()): ?>
<?php $i
=0; foreach ($_products->getItems() as $_product): ?>
    <?php 
if ($i>3): continue; endif; ?>
        
        
<div class="product">
            <
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(185, 165); ?>" width="185" height="165" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
            </
a>
            <
h3><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>
        </
div>

<?php $i++; endforeach; ?>
<?php 
endif; ?>

app/etc/local.xml

<global>
.... 
bunch of stuff...
<
blocks>
           <
catalog>
<!-- 
block from the other tutorial for featured products on catalog pages -->
               <
rewrite>
                   <
product_featured>STORENAME_Catalog_Block_Product_Featured</product_featured>
              </
rewrite>
               <
rewrite>
                   <
category_view>STORENAME_Catalog_Block_Category_View</category_view>
               </
rewrite>
<!-- 
block for the homepage feature and goes along with the rest of these changes -->
               <
rewrite>
                   <
product_homepage>STORENAME_Catalog_Block_Product_Homepage</product_homepage>
               </
rewrite>
            </
catalog>
       </
blocks>
     </global>

finally in the CMS > Manage Pages > Home page > Custom Design

<reference name="content">
<
block type="catalog/product_homepage" name="home.catalog.product.homepage" alias="product_homepage" template="catalog/product/homepage.phtml" />
</
reference>
I think that is it smile So now you get featured products on the homepage, without adding files to the core.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tilzinger
Sr. Member
 
Total Posts:  80
Joined:  2007-12-27
 

My client turned out to not ‘need’ the featured products on the homepage, but I have a feeling they’ll use it more than they know. So to accompany the possibility of not having any products selected as featured I changed the Homepage.php to load the 3 most recently added products (regardless of the new from/to date). I also commented out the getSingleton lines and it still worked, so I don’t know what purpose they served, but it probably reduced some overhead by commenting them out.

So yeah… contributing back smile

Use in place of the class in my previous post

class STORENAME_Catalog_Block_Product_Homepage 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_store_front', 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('created_at''desc')->setPageSize(3)->setCurPage(1);
        
$this->setProductCollection($products);    
    
        
$_products $this->getProductCollection();
        
$_size $_products->getSize();
       
// if less than 3 products have been entered as featured, fall back and get the 3 more recently added products 
        
if($_size 3)
        
{
            $products   
$product->setStoreId($storeId)->getCollection()
                ->
addAttributeToSelect(array('name''price''small_image'), 'inner')
                ->
addAttributeToSelect(array('special_price''special_from_date''special_to_date'), 'left')
            ;
            
            
$products->setOrder('created_at''desc')->setPageSize(3)->setCurPage(1);
            
$this->setProductCollection($products);
        
}        
    }
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
pepto
Jr. Member
 
Total Posts:  24
Joined:  2008-03-26
 
flyingoat - 11 August 2008 12:31 PM

dan_w - 27 March 2008 06:53 AM

Now to get the products to appear on the homepage, place this in your homepage cms page wherever you want the products to appear:
{{block type="catalog/product_homepage" name="home.catalog.product.homepage" alias="product_homepage" template="catalog/product/homepage.phtml"}}

Hi, dan, I followed the steps and the featured products did show in homepage, but I also got a fatal error: 
Fatal error: Class ‘Mage_Review_Helper_Product’ not found in E:\xampp\htdocs\app\code\core\Mage\Core\Model\App.php on line 779

Any suggestions?

I’m having this same issue. Any suggestions?!

 
Magento Community Magento Community
Magento Community
Magento Community
 
ia
Jr. Member
 
Total Posts:  4
Joined:  2008-04-03
 

Question: How do you list the most viewed products / most popular products on the homepage? I know that the site admin has a section that displays the most viewed products under the Reports section, so there *should* be a way to display that on the frontend. I hope you can point me in the right direction. :D

 
Magento Community Magento Community
Magento Community
Magento Community
 
The Sunday Paper
Sr. Member
 
Total Posts:  148
Joined:  2008-08-06
 
Andrea, Argentina - 16 March 2008 06:18 AM

SOLVED:

Adding
{{block type="catalog/product_new" template="catalog/product/new.phtml"}}

to my cms home page I can see the new products.

Hope this helps
Andrea

I added that to the CMS here…
http://halfoffd.nexcess.net/index.php/new

None of those items are currently new, nor are any of them out of stock (as you can see by viewing them on any other page of the store)! How can that be?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lataz
Jr. Member
 
Total Posts:  22
Joined:  2008-08-19
 

Under the ‘General’ tab on the edit product page you can set as from DATE to DATE, those items will show up.

 Signature 

Lataz.com

 
Magento Community Magento Community
Magento Community
Magento Community
 
The Sunday Paper
Sr. Member
 
Total Posts:  148
Joined:  2008-08-06
 
Lataz - 21 August 2008 05:50 PM

Under the ‘General’ tab on the edit product page you can set as from DATE to DATE, those items will show up.

Should’ve been clearer: I get how it’s supposed to work, and I double- and triple-checked all the settings (make sure the stock setting is correct in multiple places, make sure I know what’s set to “new” for today, etc.), but the items showing up on that “new” page are marked to have stopped being “new” back in July, and other items that are marked “new” aren’t showing up.

On a potentially related note, since I noticed a bizarre date flaw in the Pricing section, what format do you suppose dates are meant to be in? They appear to work correctly when in mm/dd/yy, but if I leave one blank under pricing it autofills in dd/mm/yy — but still behaves as though it were mm/dd/yy, which makes me think that the system reads mm/dd/yy but writes dd/mm/yy. So I’m using mm/dd/yy. But I could be wrong to do so.

 
Magento Community Magento Community
Magento Community
Magento Community
 
DDMAN
Sr. Member
 
Total Posts:  165
Joined:  2008-01-08
 

Trying to get this to work but I’m a little confused on “STORENAME”

Is that the code found in system > configuration > Manage stores

I have the code under website, the name under Store name and the code under store view.

Please advise

 
Magento Community Magento Community
Magento Community
Magento Community
 
finch8243
Member
 
Total Posts:  64
Joined:  2007-08-31
 

Question—what if you only want to display products that are in stock?  Can you somehow modify addAttributeToFilter?

->addAttributeToFilter(’qty’, 1)

doesn’t work, but something like that?

 
Magento Community Magento Community
Magento Community
Magento Community
 
DDMAN
Sr. Member
 
Total Posts:  165
Joined:  2008-01-08
 

I found this wiki http://www.magentocommerce.com/wiki/groups/248/display_products_on_home_page and used the method outlined and it worked like a charm. Didn’t have to adjust any code and I restyled the new.phtml to fit my needs (i.e. got rid of table layout and did a vertical div so products stacked floating left)

 
Magento Community Magento Community
Magento Community
Magento Community
 
The Sunday Paper
Sr. Member
 
Total Posts:  148
Joined:  2008-08-06
 
DDMAN - 25 August 2008 06:57 AM

I found this wiki http://www.magentocommerce.com/wiki/groups/248/display_products_on_home_page and used the method outlined and it worked like a charm. Didn’t have to adjust any code and I restyled the new.phtml to fit my needs (i.e. got rid of table layout and did a vertical div so products stacked floating left)

Then this is an even greater mystery than I realized, because I copy/pasted exactly the text off that same Wiki page, and I’ve got all the wrong products and they’re marked “out of stock” when they’re not. I saw in another thread (http://www.magentocommerce.com/boards/viewreply/54761/) that someone has put together a patch for the issue, but I would like to see it approved by someone who knows patches (and Magento) before I try it. I’d feel a lot better if I understood why the anomaly affects some installations and not others, though.

 
Magento Community Magento Community
Magento Community
Magento Community
 
DDMAN
Sr. Member
 
Total Posts:  165
Joined:  2008-01-08
 
The Sunday Paper - 26 August 2008 08:07 AM

I copy/pasted exactly the text off that same Wiki page, and I’ve got all the wrong products and they’re marked “out of stock” when they’re not.

@ Sunday Paper

I apologize I forgot that I had to make one change to a file to get this working

I made a copy of /app/code/Mage/Catalog/Block/Product/New.php and moved it to/app/code/local/Catalog/Block/Product/New.php

I added a line to grab the status of the product so that it knows if it is instock or outofstock. I found this on another post but don’t remember where. With the code change I simply set some products with a date for new in the manage product page and it worked great

The original code looks like this for New.php

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */


/**
 * New products block
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Catalog_Block_Product_New 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('news_from_date', array('date'=>true'to'=> $todayDate))
            ->
addAttributeToFilter(array(array('attribute'=>'news_to_date''date'=>true'from'=>$todayDate), array('attribute'=>'news_to_date''is' => new Zend_Db_Expr('null'))),'','left')
            ->
addAttributeToSort('news_from_date','desc')
            ->
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('news_from_date')->setPageSize(5)->setCurPage(1);

        
$this->setProductCollection($products);
    
}
}

The new code I added a line after line 46

$products->addAttributeToSelect('status');

so that you now have in your local copy of New.php

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */


/**
 * New products block
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Catalog_Block_Product_New 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('news_from_date', array('date'=>true'to'=> $todayDate))
            ->
addAttributeToFilter(array(array('attribute'=>'news_to_date''date'=>true'from'=>$todayDate), array('attribute'=>'news_to_date''is' => new Zend_Db_Expr('null'))),'','left')
            ->
addAttributeToSort('news_from_date','desc')
            ->
addAttributeToSelect(array('name''price''small_image'), 'inner')
            ->
addAttributeToSelect(array('special_price''special_from_date''special_to_date'), 'left')
        ;
        
$products->addAttributeToSelect('status');
        
/* @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('news_from_date')->setPageSize(5)->setCurPage(1);

        
$this->setProductCollection($products);
    
}
}

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
zero cool
Jr. Member
 
Total Posts:  5
Joined:  2008-08-26
 

Hi all, I followed your steps, but it had errors.

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 53: parser error : Opening and ending tag mismatch: block line 47 and reference in C:\wamp\www\magento\app\code\core\Mage\Core\Model\Layout\Update.php on line 276
Trace:
#0 [internal function]: mageCoreErrorHandler(2, ‘simplexml_load_...’, ‘C:\wamp\www\mag...’, 276, Array)
#1 C:\wamp\www\magento\app\code\core\Mage\Core\Model\Layout\Update.php(276): simplexml_load_string(’fetchFileLayoutUpdates()
#3 C:\wamp\www\magento\app\code\core\Mage\Core\Model\Layout\Update.php(233): Mage_Core_Model_Layout_Update->fetchPackageLayoutUpdates(’default’)
#4 C:\wamp\www\magento\app\code\core\Mage\Core\Model\Layout\Update.php(211): Mage_Core_Model_Layout_Update->merge(’default’)
#5 C:\wamp\www\magento\app\code\core\Mage\Core\Controller\Varien\Action.php(247): Mage_Core_Model_Layout_Update->load()
#6 C:\wamp\www\magento\app\code\core\Mage\Core\Controller\Varien\Action.php(206): Mage_Core_Controller_Varien_Action->loadLayoutUpdates()
#7 C:\wamp\www\magento\app\code\core\Mage\Cms\Helper\Page.php(74): Mage_Core_Controller_Varien_Action->loadLayout(Array, false, false)
#8 C:\wamp\www\magento\app\code\core\Mage\Cms\controllers\IndexController.php(26): Mage_Cms_Helper_Page->renderPage(Object(Mage_Cms_IndexController), ‘home’)
#9 C:\wamp\www\magento\app\code\core\Mage\Core\Controller\Varien\Action.php(343): Mage_Cms_IndexController->indexAction()
#10 C:\wamp\www\magento\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(144): Mage_Core_Controller_Varien_Action->dispatch(’index’)
#11 C:\wamp\www\magento\app\code\core\Mage\Core\Controller\Varien\Front.php(168): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#12 C:\wamp\www\magento\app\Mage.php(420): Mage_Core_Controller_Varien_Front->dispatch()
#13 C:\wamp\www\magento\index.php(46): Mage::run()
#14 {main}

Anybody helps me?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
© Copyright 2009 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
108753 users|368 users currently online|199858 forum posts