Magento – Magento 1.9 – How does pagination work on category pages

categorymagento-1.9pagination

On a category page when I choose to display 12 products per page it still shows all products from that category. Where does this actually get applied to the category product collection?

I'm using Magento 1.9.3.0 with SUPEE-9767 installed.

Here's the code that I'm using to list all products on category pages. and it worked fine before. I don't know what I did wrong.

app/design/frontend/mytheme/default/template/catalog/product/list.pthml

<?php
/**
 * Product list template
 *
 * @see Mage_Catalog_Block_Product_List
 */
?>
<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>
<?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 ?>
            <div class="amlabel-div">
                <?php echo Mage::helper('amlabel')->getLabels($_product) ?>
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(275); ?>" width="275" height="275" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
            </div>
            <?php // Product description ?>
            <div class="product-shop">
                <div class="f-fix">
                    <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
                    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h2>
                    <?php if($_product->getRatingSummary()): ?>
                    <?php echo $this->getReviewsSummaryHtml($_product) ?>
                    <?php endif; ?>
                    <?php echo $this->getPriceHtml($_product, true) ?>
                    <?php if($_product->isSaleable()): ?>
                        <p><button type="button" title="<?php echo Mage::helper('core')->quoteEscape($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>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <div class="desc std">
                        <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>" class="link-learn"><?php echo $this->__('Learn More') ?></a>
                    </div>
                    <ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?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 ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?>
                    </ul>
                </div>
            </div>
        </li>
    <?php endforeach; ?>
    </ol>
    <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>

    <?php else: ?>

    <?php // Grid Mode ?>

    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = 4;//$this->getColumnCount(); ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="products-grid">
        <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <div class="amlabel-div">
                    <?php echo Mage::helper('amlabel')->getLabels($_product) ?>
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(275); ?>" width="275" height="275" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
                </div>
                <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
                <p><?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?></p>

                <?php if($_product->getRatingSummary()): ?>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php endif; ?>

                <?php
                    $has_category=0;
                    $categoryIds = $_product->getCategoryIds();
                    if(count($categoryIds) ){
                        foreach($categoryIds as $catid) :
                            $_category = Mage::getModel('catalog/category')->load($catid);
                            if(strpos(strtolower($_category->getName()), 'hynder') !== false) :
                                $has_category=1;
                            endif;
                        endforeach;
                    }
                ?>
                <?php
                    if($_product->getTypeId()=="grouped" && $has_category) :
                        $_associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
                        $ogPrice = 0;
                        $ogStandardPrice = 0;
                        $hasSpecialPrice = false;
                        foreach($_associatedProducts as $_associatedProduct) :
                            foreach ($_associatedProduct->getTypeInstance(true)->getUsedProducts ( null, $_associatedProduct) as $simple) :
                                $simpleproduct=Mage::getModel('catalog/product')->load($simple->getId());
                                $standardProductPrice = $simpleproduct->getPrice();
                                $productPrice = $simpleproduct->getFinalPrice();

                                if ($productPrice < $standardProductPrice) {
                                    $hasSpecialPrice = true;
                                    $standardPrice = $standardProductPrice;
                                    if ($ogStandardPrice >= $standardPrice) {
                                        $ogStandardPrice = $standardPrice;
                                    }
                                }

                                //if ($ogPrice >= $productPrice) {
                                if ($ogPrice==0)
                                    $ogPrice = $productPrice;
                                elseif ($ogPrice >= $productPrice)
                                    $ogPrice = $productPrice;
                            endforeach;
                        endforeach;
                    ?>

                    <?php if ($hasSpecialPrice): ?>
                        <div class="price-box">
                            <p class="old-price">
                                <span class="price-label"><?php echo $this->__('From: ') ?></span>
                                <span class="price" id="old-price-<?php echo $_product->getId(); ?>"><?php echo Mage::helper('core')->currency($ogStandardPrice,true,false); ?></span>
                            </p>

                            <p class="special-price">
                                <span class="price-label"><?php echo $this->__('From: ') ?></span>
                                <span class="price" id="product-price-<?php echo $_product->getId(); ?>"><?php echo Mage::helper('core')->currency($ogPrice,true,false); ?></span>
                            </p>
                        </div>
                    <?php else: ?>
                        <div class="price-box">
                            <span class="regular-price" id="product-price-<?php echo $_product->getId(); ?>">
                                <span class="price"><?php echo $this->__('From: ') ?><?php echo Mage::helper('core')->currency($ogPrice,true,false); ?></span>
                            </span>
                        </div>
                    <?php endif; ?>

                <?php elseif($_product->getTypeId()=="grouped") : ?>
                    <?php
                        $_associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
                        $ogPrice = 0;
                        $ogQty = 0;
                        $ogTotalPrice = 0;
                        $ogStandardPrice = 0;
                        foreach($_associatedProducts as $_associatedProduct) :
                            $ogQty = $_associatedProduct->getQty();
                            $ogStandardPrice += ($_associatedProduct->getPrice() * $ogQty);
                            $ogPrice = $_associatedProduct->getFinalPrice();
                            $ogTotalPrice += ($ogPrice * $ogQty);
                        endforeach;
                    ?>

                    <div class="price-box">
                        <?php if ($ogTotalPrice < $ogStandardPrice) : ?>
                        <p class="old-price">
                            <span class="price" id="old-price-<?php echo $_product->getId(); ?>">
                                <?php echo Mage::helper('core')->currency($ogStandardPrice,true,false); ?>
                            </span>
                        </p>
                        <span class="special-price" id="product-price-<?php echo $_product->getId(); ?>">
                            <span class="price"><?php echo Mage::helper('core')->currency($ogTotalPrice,true,false); ?></span>
                        </span>
                        <?php else: ?>
                            <span class="regular-price" id="product-price-<?php echo $_product->getId(); ?>">
                                <span class="price"><?php echo Mage::helper('core')->currency($ogTotalPrice,true,false); ?></span>
                            </span>
                        <?php endif; ?>
                    </div>
                <?php else: ?>
                     <?php echo $this->getPriceHtml($_product, true) ?>
                <?php endif;?>

                <label class="btn" for="modal-1"><img src="<?php echo $this->getSkinUrl('images/van-icon.png');?>" alt="delivery" /></label>

            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
        <?php endforeach ?>
        <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
    <?php endif; ?>

</div>
<?php endif; ?>

Best Answer

  • You code has been changed, this is not the default listing script at all (that comes with magento installation).
  • Either changes by custom theme or custom development on the script
  • Add following lines before your last closing (3rd last line in your mentioned code script) :
<div class="toolbar-bottom">
    <?php echo $this->getToolbarHtml() ?>
</div>
  • Currently you have no bottom pager specified in your script.
  • By defining above line at the bottom will enable pagination on listing page
  • While adding same line of code <?php echo $this->getToolbarHtml() ?> above main listing div enables the toolbar (on top of products listing)
  • In your case I can clearly see bottom pager is missing
  • i.e. Pagination is missing

I hope this will resolve your problem.

EDIT :

  • Further you can refer to my answer here about how to apply custom pagination on a collection
Related Topic