Pages

Friday 29 March 2013

Show all products in magento

Please follow my Instructions for showing all products in magento

You have to create some directories for it.

1) Add Special.php on the following location :
app/code/core/Mage/Catalog/Block/Product/Special.php

2) Create Folder Special and Add Toolbar.php on the following location :
app/code/core/Mage/Catalog/Block/Product/Special/Toolbar.php

3) After you are done with this you have to now move to
/app/design/frontend/YourTheme/YourTheme/template/catalog/product
folder and add special.phtml

4) Now you can go to Admin Panel->CMS->Pages create a New Page and in the content paste this line and call your cms page also you can call using static block.
{{block type="catalog/product_special" template="catalog/product/special.phtml"}} 

---------------------------------------------------------------------------------
First step:
app/code/core/Mage/Catalog/Block/Product/Special.php 
Create Special.php and past bellow code:
===============================
<?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) 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_Special extends Mage_Catalog_Block_Product_Abstract
{
    protected $_productsCount = null;

    protected $_defaultToolbarBlock = "catalog/product_list_toolbar";
     
    const DEFAULT_PRODUCTS_COUNT = "";

    protected function _beforeToHtml()
    {    
        $toolbar = $this->getToolbarBlock();
         
        $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
        
        $collection = Mage::getResourceModel("catalog/product_collection");
        Mage::getSingleton("catalog/product_status")->addVisibleFilterToCollection($collection);
        Mage::getSingleton("catalog/product_visibility")->addVisibleInCatalogFilterToCollection($collection);
        
        $collection = $this->_addProductAttributesAndPrices($collection)
            ->addStoreFilter()

            ->setPageSize($this->getProductsCount())
            ->setCurPage(1)
        ;
        $this->setProductCollection($collection);
        
         if ($orders = $this->getAvailableOrders()) {
            $toolbar->setAvailableOrders($orders);
        }
        if ($sort = $this->getSortBy()) {
            $toolbar->setDefaultOrder($sort);
        }
        if ($modes = $this->getModes()) {
            $toolbar->setModes($modes);
        }

        // set collection to tollbar and apply sort
        $toolbar->setCollection($collection);

        $this->setChild("toolbar", $toolbar);
        Mage::dispatchEvent("catalog_block_product_list_collection", array(
            "collection"=>$collection,
        ));
        
        return parent::_beforeToHtml();
    }
    
    public function getToolbarBlock()
    {
        if ($blockName = $this->getToolbarBlockName()) {
            if ($block = $this->getLayout()->getBlock($blockName)) {
                return $block;
            }
        }
        $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime());
        return $block;
    }
    
    public function setProductsCount($count)
    {
        $this->_productsCount = $count;
        return $this;
    }

    public function getProductsCount()
    {
        if (null === $this->_productsCount) {
            $this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
        }
        return $this->_productsCount;
    }
    
    
     public function getMode()
    {
        return $this->getChild("toolbar")->getCurrentMode();
    }

    public function getToolbarHtml()
    {
        return $this->getChildHtml("toolbar");
    }
}  

===========================================
Second step:

app/code/core/Mage/Catalog/Block/Product/Special/Toolbar.php 
Got to this directory we have to create Special name folder and in this folder we have to create one php file Toolbar.php   and past bellow code:
========================================
<?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) 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_Special extends Mage_Catalog_Block_Product_Abstract
{
    protected $_productsCount = null;

    protected $_defaultToolbarBlock = "catalog/product_list_toolbar";
     
    const DEFAULT_PRODUCTS_COUNT = "";

    protected function _beforeToHtml()
    {    
        $toolbar = $this->getToolbarBlock();
         
        $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
        
        $collection = Mage::getResourceModel("catalog/product_collection");
        Mage::getSingleton("catalog/product_status")->addVisibleFilterToCollection($collection);
        Mage::getSingleton("catalog/product_visibility")->addVisibleInCatalogFilterToCollection($collection);
        
        $collection = $this->_addProductAttributesAndPrices($collection)
            ->addStoreFilter()

            ->setPageSize($this->getProductsCount())
            ->setCurPage(1)
        ;
        $this->setProductCollection($collection);
        
         if ($orders = $this->getAvailableOrders()) {
            $toolbar->setAvailableOrders($orders);
        }
        if ($sort = $this->getSortBy()) {
            $toolbar->setDefaultOrder($sort);
        }
        if ($modes = $this->getModes()) {
            $toolbar->setModes($modes);
        }

        // set collection to tollbar and apply sort
        $toolbar->setCollection($collection);

        $this->setChild("toolbar", $toolbar);
        Mage::dispatchEvent("catalog_block_product_list_collection", array(
            "collection"=>$collection,
        ));
        
        return parent::_beforeToHtml();
    }
    
    public function getToolbarBlock()
    {
        if ($blockName = $this->getToolbarBlockName()) {
            if ($block = $this->getLayout()->getBlock($blockName)) {
                return $block;
            }
        }
        $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime());
        return $block;
    }
    
    public function setProductsCount($count)
    {
        $this->_productsCount = $count;
        return $this;
    }

    public function getProductsCount()
    {
        if (null === $this->_productsCount) {
            $this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
        }
        return $this->_productsCount;
    }
    
    
     public function getMode()
    {
        return $this->getChild("toolbar")->getCurrentMode();
    }

    public function getToolbarHtml()
    {
        return $this->getChildHtml("toolbar");
    }
}  

===================================
Third Step:

/app/design/frontend/YourTheme/YourTheme/template/catalog/product
folder and Create special.phtml   and past bellow code:
-------------------------------------------------------------------------------------------------

<?php $_productCollection=$this->getProductCollection() ?>
<div class="indent-col-main specials">
<div class="page-title category-title">
        <h1>All Products</h1>
</div>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
    <?php echo $this->getToolbarHtml() ?>

    <?php // List mode ?>
    <?php if($this->getMode()!='grid'): ?>
    <?php $_iterator = 0; ?>
    <ol class="products-list" id="products-list">
    <?php foreach ($_productCollection as $_product): ?>
        <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
            <?php // Product Image ?>
            <a class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
                <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(211, 211); ?>" width="211" height="211" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" /></a>

            <?php // Product description ?>
            <div class="product-shop">
            <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName())?></a></h3>
                <?php if($_product->getRatingSummary()): ?>
                <?php echo $this->getReviewsSummaryHtml($_product) ?>
                <?php endif; ?>
                <?php echo $this->getPriceHtml($_product, true) ?>
                <?php if($_product->isSaleable()): ?>
                <p><button class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button></p>
                <?php else: ?>
                <p class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock') ?></span></p>
                <?php endif; ?><br class="clear-block" />
                <div class="desc std">
                    <?php //echo nl2br($_product->getShortDescription()) ?>
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->__('Learn More') ?></a>
                </div>
                <div class="block-add-to-links"><ul class="add-to-links">
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <li><a class="wishlist-link" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>"><?php echo $this->__('Add to Wishlist') ?></a></li>
                    <?php endif; ?>
                    <?php //if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                       <!-- <li><span class="separator">|</span> <a href="<?php //echo $_compareUrl ?>"><?php //echo $this->__('Add to Compare') ?></a></li>-->
                    <?php //endif; ?>
                </ul></div>
            </div>
            <div class="clear-block"></div>
        </li>
    <?php endforeach; ?>
    </ol>
    <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>

    <?php endif; ?>
    <?php echo $this->getToolbarHtml() ?>
</div>
<?php endif; ?>
</div>

======================================
Finally copy and past this code in CMS page or Static block as you like
----------------------------------------------------------------------------
{{block type="catalog/product_special" template="catalog/product/special.phtml"}}  
----------------------------------------------------------
Now call your cms page or static block...it's default working in list mode not Grid mode if you want to also grid mode than we have to edit it according to grid 
Use code and enjoy.....:)

2 comments:

  1. Hi this is very good blog. i use it and now working well at my magento latest version 1.7.2 Thanks a lot

    ReplyDelete
  2. Hello Dear blog provider it's really very good code and working well.

    ReplyDelete