Call-back icon  Enterprise Sales: +1.310.775.2674 (N. America)   +44 20.3286.4137 (UK)

Magento

eCommerce Software for Online Growth

Magento Forum

   
Adding pagination to Product page
 
shamone
Jr. Member
 
Avatar
Total Posts:  14
Joined:  2008-07-09
 

Usibility wise I think it would be great to allow the user to page back and forward through the products in the order they displayed on the product list page/category page (sort by order as well).

I gave it a go and came up with the following solution - would appreciate it if anyone could better the code:

In the list template I created a session variable that holds all the product url’s of the products listed:
.../templates/catalog/product/list.phtml after the 1st else statement around line #36

<?php 
    
    $prodPgNavArr 
= array();
    
$i=0; foreach ($_productCollection as $_product
    
        $prodPgNavArr[$i] 
$_product->getProductUrl();  
        
$i++;
        
    
}
    
    
// put the array in a session variable
    
$_SESSION['prodPgNav']=$prodPgNavArr;

?>

and retrieve these on the product page and conditionally display ‘previous’ and ‘next’ links:
.../templates/catalog/product/view/media.phtml at the top:

<?php

    
// get current product URl
    
$currentPath "http://" $_SERVER['HTTP_HOST'$_SERVER['REQUEST_URI'];
     
    
//
    
$prodPgNavArr $_SESSION['prodPgNav'];
    
    
// loop through the session array to find index of current product in product list/array
    
foreach($prodPgNavArr as $key=>$value{
    
        
if($currentPath == $value{
            $prevIndex 
$key 1;            
            
$nextIndex $key 1;
        
}    
    }
       
if (isset($prevIndex) && $prevIndex!=-1{
        
echo "<div>&#8220;&nbsp;<a href='$prodPgNavArr[$prevIndex]'>previous</a></div>";
    
}
    
if (isset($nextIndex) && $nextIndex<sizeof($prodPgNavArr)) {
        
echo "<div>&#8221;&nbsp;<a href='$prodPgNavArr[$nextIndex]'>next</a></div>";
    
}
?>

Okay this works, but only lists the first 8 products from my product listing page, because that’s what I set my listing limit per page at. Instead I would appreciate advice on how to retrieve ALL the products in the listing. 

I hope this makes sense. If there’s a better (object orientated) way of solving this, please let me know.

 
Magento Community Magento Community
Magento Community
Magento Community
 
fenixf
Member
 
Total Posts:  35
Joined:  2008-04-08
 

You must change the show items per page in admin->configuration->catalog to “all” or a high number.
Then will get all the products in that category.

 
Magento Community Magento Community
Magento Community
Magento Community
 
shamone
Jr. Member
 
Avatar
Total Posts:  14
Joined:  2008-07-09
 

I probably didn’t make that clear ... this is where I butt heads with my designer partner - who only wants a max of 8 items to show per page.

Is there a way I could replicate the load of All products (not the whole page - just loop through and grab their urls) in an include on the list page and thus have all the url’s store in the session variable?

Help please!

 
Magento Community Magento Community
Magento Community
Magento Community
 
trrill
Jr. Member
 
Total Posts:  3
Joined:  2008-08-28
 

I’m up against this very problem. This thread’s been inactive for a while, and I’m wondering if you ever figured out a solution to it. I’m sort of wanting to do two things:

1) Paginate “Next product” and “Previous” product based on the list view.
2) Display thumbnails from the Product’s deepest category/collection.

You can see my progress (and stagnation) with #2 at:
http://www.magentocommerce.com/boards/viewthread/19090/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
© Copyright 2009 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
108779 users|275 users currently online|199889 forum posts