Advertisement
andhiirawan

Magento : Catalog Product List - Result per page

Dec 7th, 2015
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.01 KB | None | 0 0
  1. <!-- app\design\frontend\rwd\default\template\catalog\product\list.phtml -->
  2.  
  3. <?php
  4. /**
  5.  * Magento
  6.  *
  7.  * NOTICE OF LICENSE
  8.  *
  9.  * This source file is subject to the Academic Free License (AFL 3.0)
  10.  * that is bundled with this package in the file LICENSE_AFL.txt.
  11.  * It is also available through the world-wide-web at this URL:
  12.  * http://opensource.org/licenses/afl-3.0.php
  13.  * If you did not receive a copy of the license and are unable to
  14.  * obtain it through the world-wide-web, please send an email
  15.  * to license@magento.com so we can send you a copy immediately.
  16.  *
  17.  * DISCLAIMER
  18.  *
  19.  * Do not edit or add to this file if you wish to upgrade Magento to newer
  20.  * versions in the future. If you wish to customize Magento for your
  21.  * needs please refer to http://www.magento.com for more information.
  22.  *
  23.  * @category    design
  24.  * @package     rwd_default
  25.  * @copyright   Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
  26.  * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
  27.  */
  28. ?>
  29. <?php
  30. /**
  31.  * Product list template
  32.  *
  33.  * @see Mage_Catalog_Block_Product_List
  34.  */
  35. /* @var $this Mage_Catalog_Block_Product_List */
  36. ?>
  37. <?php
  38.     $_productCollection=$this->getLoadedProductCollection();
  39.    
  40.     $_category = Mage::registry('current_category');
  41.     if($_category)
  42.         $currentCategoryId= $_category->getId();
  43. ?>
  44. <!-- No Product -->
  45. <?php if(!$_productCollection->count()): ?>
  46. <p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
  47. <?php else: ?>
  48. <div class="category-products">
  49.     <?php echo $this->getToolbarHtml() ?>
  50.     <?php
  51.         if($currentCategoryId){
  52.             $order = Mage::getSingleton('catalog/session')->getSortOrder();
  53.             $direction = Mage::getSingleton('catalog/session')->getSortDirection();
  54.             $display = Mage::getSingleton('catalog/session')->getDisplayMode();
  55.             $limit = Mage::getSingleton('catalog/session')->getLimitPage();
  56.  
  57.              if($order == 'name') {
  58.                 if($direction == '') {
  59.                     $direction = 'asc';
  60.                 }                
  61.                 $_productCollection = Mage::getModel('catalog/category')->load($currentCategoryId)
  62.                      ->getProductCollection()
  63.                      ->addAttributeToSelect('*')
  64.                      ->addAttributeToFilter('status', 1)
  65.                      ->addAttributeToFilter('visibility', 4)                    
  66.                                          ->setPageSize('name', $limit)
  67.                      ->setCurPage($limit)
  68.                      ->setOrder('name', $direction);
  69.  
  70.                 echo $_productCollection->getSelect();
  71.                 //$_productCollection->printLogQuery(true);
  72.              }
  73.  
  74.              if($order == 'price') {
  75.                 if($direction == '') {
  76.                     $direction = 'asc';
  77.                 }
  78.                 $_productCollection = Mage::getModel('catalog/category')->load($currentCategoryId)
  79.                      ->getProductCollection()
  80.                      ->addAttributeToSelect('*')
  81.                      ->addAttributeToFilter('status', 1)
  82.                      ->addAttributeToFilter('visibility', 4)
  83.                      ->setOrder('price', $direction);
  84.              }
  85.  
  86.              if($order == 'position') {
  87.                 if($direction == '') {
  88.                     $direction = 'asc';
  89.                 }
  90.                 $_productCollection = Mage::getModel('catalog/category')->load($currentCategoryId)
  91.                      ->getProductCollection()
  92.                      ->addAttributeToSelect('*')
  93.                      ->addAttributeToFilter('status', 1)
  94.                      ->addAttributeToFilter('visibility', 4)
  95.                      ->setOrder('position', $direction);
  96.              }
  97.  
  98.              if($order == '') {
  99.                 if($direction == '') {
  100.                     $direction = 'asc';
  101.                 }
  102.                 $_productCollection = Mage::getModel('catalog/category')->load($currentCategoryId)
  103.                      ->getProductCollection()
  104.                      ->addAttributeToSelect('*')
  105.                      ->addAttributeToFilter('status', 1)
  106.                      ->addAttributeToFilter('visibility', 4)
  107.                      ->setOrder('news_from_date', 'desc')
  108.                      ->setOrder('created_at', 'desc');
  109.             }
  110.         }
  111.        
  112.     ?>
  113.     <!-- List mode -->
  114.     <?php if($this->getMode()!='grid'): ?>
  115.     <?php $_iterator = 0; ?>
  116.     <ol class="products-list" id="products-list">
  117.     <?php foreach ($_productCollection as $_product): ?>
  118.         <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
  119.             <!-- Product Image -- >
  120.             <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">                
  121.                 <?php $_imgSize = 300; ?>
  122.                 <img id="product-collection-image-<?php echo $_product->getId(); ?>"
  123.                      src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->keepFrame(false)->resize($_imgSize); ?>"
  124.                      alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
  125.             </a>
  126.             <!-- Product description -->
  127.             <div class="product-shop">
  128.                 <div class="f-fix">
  129.                     <div class="product-primary">
  130.                         <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
  131.                         <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h2>
  132.                         <?php if($_product->getRatingSummary()): ?>
  133.                         <?php echo $this->getReviewsSummaryHtml($_product) ?>
  134.                         <?php endif; ?>
  135.                         <?php
  136.                         if ($this->getChild('name.after')) {
  137.                             $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
  138.                             foreach ($_nameAfterChildren as $_nameAfterChildName) {
  139.                                 $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
  140.                                 $_nameAfterChild->setProduct($_product);
  141.                                 echo $_nameAfterChild->toHtml();
  142.                             }
  143.                         }
  144.                         ?>
  145.                     </div>
  146.                     <div class="product-secondary">
  147.                         <?php echo $this->getPriceHtml($_product, true) ?>
  148.                     </div>
  149.                     <div class="product-secondary">
  150.                         <?php if(!$_product->canConfigure() && $_product->isSaleable()): ?>
  151.                             <p class="action"><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
  152.                         <?php elseif($_product->getStockItem() && $_product->getStockItem()->getIsInStock()): ?>
  153.                             <p class="action"><a title="<?php echo $this->__('View Details') ?>" class="button" href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->__('View Details') ?></a></p>
  154.                         <?php else: ?>
  155.                             <p class="action availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
  156.                         <?php endif; ?>
  157.                         <ul class="add-to-links">
  158.                             <?php if ($this->helper('wishlist')->isAllow()) : ?>
  159.                                 <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
  160.                             <?php endif; ?>
  161.                             <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
  162.                                 <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
  163.                             <?php endif; ?>
  164.                         </ul>
  165.                     </div>
  166.                     <div class="desc std">
  167.                         <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
  168.                         <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>" class="link-learn"><?php echo $this->__('Learn More') ?></a>
  169.                     </div>
  170.                 </div>
  171.             </div>
  172.         </li>
  173.     <?php endforeach; ?>
  174.     </ol>
  175.     <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>
  176.  
  177.     <?php else: ?>
  178.  
  179.     <!-- Grid Mode -->
  180.  
  181.     <?php $_collectionSize = $_productCollection->count() ?>
  182.     <?php
  183.         //$_columnCount = $this->getColumnCount
  184.         $_columnCount = 4;
  185.     ?>
  186.     <ul class="products-grid ali-grid products-grid--max-<?php echo $_columnCount; ?>-col">
  187.         <?php $i=0;
  188.         foreach ($_productCollection as $_product): ?>
  189.             <?php /*if ($i++%$_columnCount==0): ?>
  190.             <?php endif*/ ?>
  191.             <?php //echo $_productCollection->getSelect()->assemble() ?>
  192.             <?php //echo '<pre>'; //print_r(debug_print_backtrace()); //echo '</pre>'; ?>
  193.             <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
  194.                        
  195.                 <div class="img-prod">
  196.                     <?php                    
  197.                     if($_product->getSpecialPrice()):
  198.                     ?>
  199.                     <div class="embel-embel sale"><?php echo $this->__('Sale')?><span class="sale"></span></div>
  200.                     <?php endif;?>
  201.                     <?php                    
  202.                         $date = date("Y-m-d 00:00:00");
  203.                         $newtodate = $_product['news_to_date'];
  204.                         $newfromdate = $_product['news_from_date'];
  205.                
  206.                         if (isset($newfromdate) and isset($newtodate) and $date >= $newfromdate and $date <= $newtodate) :
  207.                     ?>                                        
  208.                     <div class="embel-embel new"><?php echo $this->__('New')?><span class="new"></span></div>
  209.                    
  210.                     <?php
  211.                         elseif(isset($newfromdate)):
  212.                     ?>
  213.                     <div class="embel-embel new"><?php echo $this->__('New')?><span class="new"></span></div>
  214.                     <?php endif;?>
  215.                     <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
  216.                         <?php $_imgSize = 210; ?>
  217.                         <img id="product-collection-image-<?php echo $_product->getId(); ?>"
  218.                              src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(238,317); ?>"
  219.                              alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
  220.                     </a>
  221.                 </div>
  222.                 <div class="product-info">
  223.                     <div class="prod-title"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></div>
  224.                     <h2 style="display:none" class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
  225.                     <?php
  226.                     // Provides extra blocks on which to hang some features for products in the list
  227.                     // Features providing UI elements targeting this block will display directly below the product name
  228.                     /*if ($this->getChild('name.after')) {
  229.                         $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
  230.                         foreach ($_nameAfterChildren as $_nameAfterChildName) {
  231.                             $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
  232.                             $_nameAfterChild->setProduct($_product);
  233.                             echo $_nameAfterChild->toHtml();
  234.                         }
  235.                     }*/
  236.                     ?>
  237.                     <?php echo $this->getPriceHtml($_product, true) ?>
  238.                     <?php //if($_product->getRatingSummary()): ?>
  239.                     <?php //echo $this->getReviewsSummaryHtml($_product, 'short') ?>
  240.                     <?php //endif; ?>
  241.                     <div class="actions" style="display:none">
  242.                         <?php if(!$_product->canConfigure() && $_product->isSaleable()): ?>
  243.                             <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
  244.                         <?php elseif($_product->getStockItem() && $_product->getStockItem()->getIsInStock()): ?>
  245.                             <a title="<?php echo $this->__('View Details') ?>" class="button" href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->__('View Details') ?></a>
  246.                         <?php else: ?>
  247.                             <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
  248.                         <?php endif; ?>
  249.                         <ul class="add-to-links">
  250.                             <?php if ($this->helper('wishlist')->isAllow()) : ?>
  251.                                 <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
  252.                             <?php endif; ?>
  253.                             <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
  254.                                 <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
  255.                             <?php endif; ?>
  256.                         </ul>
  257.                     </div>
  258.                 </div>
  259.             </li>
  260.             <?php /*if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
  261.             <?php endif*/ ?>
  262.         <?php endforeach ?>
  263.     </ul>
  264.     <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
  265.     <?php endif; ?>
  266.  
  267.     <div class="toolbar-bottom">
  268.         <?php echo $this->getToolbarHtml() ?>
  269.     </div>
  270. </div>
  271. <?php endif; ?>
  272. <?php
  273. // Provides a block where additional page components may be attached, primarily good for in-page JavaScript
  274. if ($this->getChild('after')) {
  275.     $_afterChildren = $this->getChild('after')->getSortedChildren();
  276.     foreach ($_afterChildren as $_afterChildName) {
  277.         $_afterChild = $this->getChild('after')->getChild($_afterChildName);
  278.         //set product collection on after blocks
  279.         $_afterChild->setProductCollection($_productCollection);
  280.         echo $_afterChild->toHtml();
  281.     }
  282. }
  283. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement