Jump to content

Error in selecting next page under category.php


Recommended Posts

Thanks!

Please see my pagination page as below:


<?php

$nArray = array(10, 20, 50);
$n = abs(intval(Tools::getValue('n', intval(Configuration::get('PS_PRODUCTS_PER_PAGE')))));
$p = abs(intval(Tools::getValue('p', 1)));
$range = 2; // how many pages around page selected

if (!$n)
   $n = $nArray[0];
if ($p < 0)
   $p = 0;

if ($p > ($nbProducts / $n))
   $p = ceil($nbProducts / $n);
$pages_nb = ceil($nbProducts / intval($n));

$start = $p-$range;
if ($start < 1)
   $start = 1;
$stop = $p+$range;
if ($stop > $pages_nb)
   $stop = $pages_nb;

$smarty->assign(array(
   'pages_nb' => $pages_nb,
   'p' => intval($p),
   'n' => intval($n),
   'nArray' => $nArray,
   'range' => intval($range),
   'start' => intval($start),
   'stop' => intval($stop)
));

?>

Link to comment
Share on other sites

code in pagination.tpl

{if isset($p) AND $p}
<!-- Pagination -->

{if $start!=$stop}

   {if $p != 1}
<< {l s='Previous'}
   {else}
<< {l s='Previous'}
   {/if}
   {if $start>3}
1
...
   {/if}
   {section name=pagination start=$start loop=$stop+1 step=1}
       {if $p == $smarty.section.pagination.index}
{$p|escape:'htmlall':'UTF-8'}
       {else}
{$smarty.section.pagination.index|escape:'htmlall':'UTF-8'}
       {/if}
   {/section}
   {if $pages_nb>$stop+2}
...
{$pages_nb|intval}
   {/if}
   {if $pages_nb > 1 AND $p != $pages_nb}
{l s='Next'} >>
   {else}
{l s='Next'} >>
   {/if}

{/if}
   <form action="{$request_uri|escape:'htmlall':'UTF-8'}" method="get" class="pagination">


           {if isset($category) AND $category}<input type="hidden" name="id_category" value="{$category->id|intval}" />{/if}
           {if isset($manufacturer) AND $manufacturer}<input type="hidden" name="id_manufacturer" value="{$manufacturer->id|intval}" />{/if}
           {if isset($supplier) AND $supplier}<input type="hidden" name="id_supplier" value="{$supplier->id|intval}" />{/if}
           {if isset($orderway) AND $orderway}<input type="hidden" name="orderway" value="{$orderway|escape:'htmlall':'UTF-8'}" />{/if}
           {if isset($orderby) AND $orderby}<input type="hidden" name="orderby" value="{$orderby|escape:'htmlall':'UTF-8'}" />{/if}
           {if isset($query) AND $query}<input type="hidden" name="search_query" value="{$query|escape:'htmlall':'UTF-8'}" />{/if}
           {if isset($tag) AND $tag}<input type="hidden" name="tag" value="{$tag|escape:'htmlall':'UTF-8'}" />{/if}
           <input type="submit" class="button_mini" value="{l s='OK'}" />
{l s='items:'}

           {foreach from=$nArray item=nValue}
{$nValue|escape:'htmlall':'UTF-8'}
           {/foreach}


   </form>

<!-- /Pagination -->
{/if}

Link to comment
Share on other sites

replace your pagination.tpl with this:

{if isset($p) AND $p}
   {if $smarty.get.id_category|intval}
       {assign var='requestPage' value=$link->getPaginationLink('category', $category, false, false, true, false)}
       {assign var='requestNb' value=$link->getPaginationLink('category', $category, true, false, false, true)}
   {elseif $smarty.get.id_manufacturer|intval}
       {assign var='requestPage' value=$link->getPaginationLink('manufacturer', $manufacturer, false, false, true, false)}
       {assign var='requestNb' value=$link->getPaginationLink('manufacturer', $manufacturer, true, false, false, true)}
   {elseif $smarty.get.id_supplier|intval}
       {assign var='requestPage' value=$link->getPaginationLink('supplier', $supplier, false, false, true, false)}
       {assign var='requestNb' value=$link->getPaginationLink('supplier', $supplier, true, false, false, true)}
   {else}
       {assign var='requestPage' value=$link->getPaginationLink(false, false, false, false, true, false)}
       {assign var='requestNb' value=$link->getPaginationLink(false, false, true, false, false, true)}
   {/if}
   <!-- Pagination -->

   {if $start!=$stop}

       {if $p != 1}
           {assign var='p_previous' value=$p-1}
« {l s='Previous'}
       {else}
« {l s='Previous'}
       {/if}
       {if $start>3}
1
...
       {/if}
       {section name=pagination start=$start loop=$stop+1 step=1}
           {if $p == $smarty.section.pagination.index}
{$p|escape:'htmlall':'UTF-8'}
           {else}
{$smarty.section.pagination.index|escape:'htmlall':'UTF-8'}
           {/if}
       {/section}
       {if $pages_nb>$stop+2}
...
{$pages_nb|intval}
       {/if}
       {if $pages_nb > 1 AND $p != $pages_nb}
           {assign var='p_next' value=$p+1}
{l s='Next'} »
       {else}
{l s='Next'} »
       {/if}

   {/if}
       <form action="{if !is_array($requestNb)}{$requestNb}{else}{$requestNb.requestUrl}{/if}" method="get" class="pagination">


               {if isset($query) AND $query}<input type="hidden" name="search_query" value="{$query|escape:'htmlall':'UTF-8'}" />{/if}
               {if isset($tag) AND $tag AND !is_array($tag)}<input type="hidden" name="tag" value="{$tag|escape:'htmlall':'UTF-8'}" />{/if}
               <input type="submit" class="button_mini" value="{l s='OK'}" />
{l s='items:'}

               {foreach from=$nArray item=nValue}
{$nValue|escape:'htmlall':'UTF-8'}
               {/foreach}

               {if is_array($requestNb)}
                   {foreach from=$requestNb item=requestValue key=requestKey}
                       {if $requestKey != 'requestUrl'}
                           <input type="hidden" name="{$requestKey|escape:'htmlall':'UTF-8'}" value="{$requestValue|escape:'htmlall':'UTF-8'}" />
                       {/if}
                   {/foreach}
               {/if}

       </form>

   <!-- /Pagination -->
{/if}

Link to comment
Share on other sites

thanks so much amwdesign!

however it showed as below error:

Fatal error: Call to undefined method Link::getPaginationLink() in /home/.bedouin/heartdis/heartdisk/store/tools/smarty/compile/%j^6AB^6ABEC739%%pagination.tpl.php on line 7


could you pls help me?
many thankssssss!
Link to comment
Share on other sites

  • 2 weeks later...

I have the same problem and not only for pagination but also for sorting.
Instead of http://domain.com/category-name&p=2 it links to http://domain.com/category-name?p=3 with "?" instead of "&"

Sorting the products dispalys URLs like ?orderby=price&orderway=asc instead of &orderby=price&orderway=asc

The solutions above for pagination.tpl doesn't work and I don't have any error messages.

Link to comment
Share on other sites

  • 3 weeks later...

My problem is only with the manufacturers list page. (the category page paginated properly, as did the product list for each manufacturer)
The complete list of manufacturers is shown all at once (all 36 of them) instead of only showing the first 10. At the bottom, the pagination links also show giving me the option of page 1, 2, 3. However since all of the manufacturers are already showing, when i click one of the other page links, the url seems correct (manufacturer.php?p=2) but the manufacturer list still only shows the complete list of 36 products and not 10 per page like it should be.

Has anyone else had this problem and worked out how to fix it?

Link to comment
Share on other sites

  • 5 months later...
For anyone who is getting this problem when upgrading - as I was getting this problem - All I did was REPLACE the .htaccess file in the root with the htaccess.txt in V1.0..0.8

All is working well now


Hello Pcbob
Can you list your htaccess file as I have the same seo rewrite error.

FIXED
I needed to add SetEnv DEFAULT_PHP_VERSION 5 to my htaccess file so that the server used PHP5 instead of 4
Hope this helps ;-)
Link to comment
Share on other sites

×
×
  • Create New...