Setting a new theme for a developer only

I found a really simple solution:

– I made another store wiew
– I assigned a new theme to it
– I removed store view list from pages

now, I can easily switch between themes:
……/?___store=new_theme – new theme for developing purposes
……/?___store=default – current theme

and customers will still see and old theme

How to set the default sort order for catalog pages?

If you only want to change default sort order you can do it in catalog.xml just by adding the following action:

<action method="setDefaultDirection"><dir>desc</dir></action>

This action will work in any block of type “catalog/product_list_toolbar”, so the XML snippet would be:

<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
        <action method="setDefaultDirection"><dir>desc</dir></action>
    <!-- The following code shows how to set your own pager increments -->
    <!--
        <action method="setDefaultListPerPage"><limit>4</limit></action>
        <action method="setDefaultGridPerPage"><limit>9</limit></action>
        <action method="addPagerLimit"><mode>list</mode><limit>2</limit></action>
        <action method="addPagerLimit"><mode>list</mode><limit>4</limit></action>
        <action method="addPagerLimit"><mode>list</mode><limit>6</limit></action>
        <action method="addPagerLimit"><mode>list</mode><limit>8</limit></action>
        <action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
    -->
</block>

This block is used twice in catalog.xml once for normal product lists and once for layered navigation product lists, so just make the same change in both places.

///////////// uncompleted //////////////

<action method="setDefaultOrder"><field>entity_id</field></action>

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 [email protected] 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 <[email protected]>
 */

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

Page 2 of 512345

Pin It on Pinterest