How to create a Random Featured Product list on home page in Magento?

If you want to show products from a specific category on your home page you can do this simply with

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

on your home page which works fine.. however, if you want these products to be randomly selected you hit problems.

The obvious thing to try is

{{block type="catalog/product_list_random" category_id="12" template="catalog/product/list.phtml"}}

however, this displays random products from EVERY category!!

The reason for this is that the file random.php does not work as advertised so we need to create a new version that does. We do not want to break upgrade compatibility so create the following directory structure.

in app/code/local create Mage/Catalog/Block/Product/List

eg mkdir -p Mage/Catalog/Block/Product/List

In your new List directory create the following file called Random.php

<?php
class Mage_Catalog_Block_Product_List_Random extends Mage_Catalog_Block_Product_List
{
    protected function _getProductCollection()
    {
        if (is_null($this->_productCollection)) {
            $categoryID = $this->getCategoryId();
            if($categoryID)
            {
              $category = new Mage_Catalog_Model_Category();
              $category->load($categoryID); // this is category id
              $collection = $category->getProductCollection();
            } else
            {
              $collection = Mage::getResourceModel('catalog/product_collection');
            }
            Mage::getModel('catalog/layer')->prepareProductCollection($collection);
            $collection->getSelect()->order('rand()');
            $collection->addStoreFilter();
            $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 3;
            $collection->setPage(1, $numProducts)->load();

            $this->_productCollection = $collection;
        }
        return $this->_productCollection;
    }
}

To call this on your home page open your Home page in CMS > Static Pages

and in Content add

{{block type="catalog/product_list_random" category_id="YOUR_CATEGORY_ID" template="catalog/product/list.phtml" column_count="4" num_products="12"}}

Create a new hidden category and add the products you wish to randomly select from. Find the category ID of this category and enter this number in the above place marker.

You will find that although you are seeing the Category display tool bar (drid view / list view / show.. etc) it has no effect on the layout. the default layout is 3 x 3 grid which is where column_count=”4″ comes into play. Alter this to meet your themes needs. Same goes for num_products=”12″.

And that is that.

Don’t want to be looking at the grid.. hide it. (evil hack alert)

Add

<style type="text/css">
.toolbar {display:none;}
</style>

at the top of your Content area on the homepage CMS. this will hide the tool bar for just the homepage.
References:
Thanks to mac75a here : http://www.magentocommerce.com/boards/viewthread/72319/ and andytm here: http://www.magentocommerce.com/boards/viewthread/72319/

Magento – How to create a special price (sale) page? (with new products first)

I’ve created a Magento site for a client who wants to have a special price page, wherein she could put products having special price/discounted price..
Requirements:

app/code/local/Mage/Catalog/Block/Product/List/Special.php
Magento backend – CMS>Pages>create-a-special-price-page

Special.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.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Mage
 * @package     Mage_Catalog
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * Catalog product random items block
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @author      Magento Core Team <core@magentocommerce.com>
 */

class Mage_Catalog_Block_Product_List_Special extends Mage_Catalog_Block_Product_List
{
    protected function _getProductCollection()
    {
        if (is_null($this->_productCollection)) {
            $categoryID = $this->getCategoryId();
            if($categoryID)
            {
              $category = new Mage_Catalog_Model_Category();
              $category->load($categoryID); // this is category id
              $collection = $category->getProductCollection();
            } else
            {
              $collection = Mage::getResourceModel('catalog/product_collection');
            }
            
            $todayDate = date('m/d/y');
            $tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y'));
            $tomorrowDate = date('m/d/y', $tomorrow);
            
            Mage::getModel('catalog/layer')->prepareProductCollection($collection);
            //$collection->getSelect()->order('rand()');
            $collection->addAttributeToSort('created_at', 'desc');
            $collection->addStoreFilter();
            
            $collection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
                ->addAttributeToFilter('special_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $tomorrowDate),
                1 => array('is' => new Zend_Db_Expr('null')))
                ), 'left');
            
            
            $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0;
            $collection->setPage(1, $numProducts)->load();
 
            $this->_productCollection = $collection;
        }
        return $this->_productCollection;
    }
}

==============================================

In the CMS Page that you created, click Content tab then put this code..

{{block type="catalog/product_list_Special" template="catalog/product/list.phtml" column_count="3" num_products="0"}}

There you have it… Don’t forget to put a special price, special-from-date and special-to-date in your products…

Magento Cron Job

On your cPanel: Advanced -> Cron Jobs
Scroll to “Add New Cron Job”

/usr/local/bin/php -f /home/your-directory/public_html/cron.php

Where “/home/your-directory/public_html/cron.php” is the path for the cron job file

///////////// uncomplete //////////////
php5-cli -f /home/USERNAME/public_html/cron.php
Source: http://www.magentocommerce.com/wiki/groups/227/setting_up_magento_in_cron

Tag pages say “No matches found.”

Hello, I created few tags on admin and tagged some products. So tags are shown like this in product pages;

    Product Tags
    Other people marked this product with these tags:
    my tag(2), my tag2(5)

Each tag’s name is a link, so I expected tagged products are listed on the tag page when I clicked the tag name.

But the tag page says;

    Products tagged with ‘my tag’
    No matches found.

I have no idea why the page doesn’t show tagged products. I cleared cache in case the cache caused this, but nothing was changed.
Could someone help me please?

Solution
just got to index manager and re-index

Move ‘My Cart’ from top-links to new block

In app/design/frontend/default/default/template/page/html/header.phtml add the following code:

<?php echo $this->getChildHtml('cart_link_container') ?>

in the page.xml add the following code:

<block type="page/html_header" name="header" as="header">
.
.
.
            <block type="page/template_links" name="cart_link_container" as="cart_link_container">
                <block type="checkout/links" name="cart_link">
                    <action method="addCartLink"></action>
                </block>
            </block>
.
.
.
</block>

Magento: Remove white space around product images

Alright, the file that I needed to edit was:
list.phtml
In list.phtml there are two sections. One that says //List Mode// and one that says //Grid Mode//. Under both sections you need to add
keepFrame(false)
just before the resize code. I found it in my version on line 47 (list mode) and line 91 (grid mode).
I have included the code from line 91 below to show my small change of adding keepFrame(false)
here it is:

<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')->keepFrame(false)->resize(135); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" /></a>

Remember to remove

width="135" height="135"

attributes from the img tag

Page 6 of 8«2345678

Pin It on Pinterest