Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Bootstrap pagination


ScottShipley

Recommended Posts

Pagination doesn't seem to work on the bootstrap version in the way that I think it should.

getPageSetLinks function within DbStatement.php is what produces the output.

$cur_window_num and $max_window_num appear to only ever = 1 regardless of the number of pages or the page you're on and at no point in the code is 'MAX_DISPLAY_PAGE_LINKS' referenced which is what should set the max links to show. The result is that all page links are shown. 

I have manufacturers with in some cases 100,000 products which results in 1000's of page links when realistically I want maybe 5. I can get around this by showing more products per page but that will be very slow!

 

I've tried playing with the code but I'm struggling to understand the logic.

 

Can anyone help me?

Scott

Link to comment
Share on other sites

yes that's correct, the value set under maximum values in configuration is not called by the code at all. I should point out that I use the github version (https://github.com/osCommerce/oscommerce2).

 

I've now come up with a fix which seems to work.

 

In product_listing.php change (actually all instances of getPageSetLinks() should be changed on various pages)

<div class="pull-right pagenav"><?php echo $Qlisting->getPageSetLinks(tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></div>

to 

<div class="pull-right pagenav"><?php echo $Qlisting->getPageSetLinks(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></div>

In DbStatement.php replace 

    public function getPageSetLinks($parameters = null)
    {
       ...
    }

 

with

    public function getPageSetLinks($max_page_links, $parameters = null)
    {
        global $PHP_SELF, $request_type;

        $number_of_pages = ceil($this->page_set_total_rows / $this->page_set_results_per_page);

        $display_links_string = '';

        if (!empty($parameters) && (substr($parameters, -1) != '&')) {
            $parameters .= '&';
        }

        $display_links_string = '<ul class="pagination">';

// previous button - not displayed on first page
        if ($this->page_set > 1) {
            $display_links_string .= '<li><a href="' . OSCOM::link($PHP_SELF, $parameters . $this->page_set_keyword . '=' . ($this->page_set - 1), $request_type) . '" title=" ' . PREVNEXT_TITLE_PREVIOUS_PAGE . ' ">«</a></li>';
        } else {
            $display_links_string .= '<li class="disabled"><span>«</span></li>';
        }

// check if number_of_pages > $max_page_links
        $cur_window_num = (int)($this->page_set / $max_page_links);
        if ($this->page_set % $max_page_links) $cur_window_num++;

        $max_window_num = (int)($number_of_pages / $max_page_links);
        if ($number_of_pages % $max_page_links) $max_window_num++;

// previous window of pages
        if ($cur_window_num > 1) $display_links_string .= '<li><a href="' . OSCOM::link($PHP_SELF, $parameters . $this->page_set_keyword . '=' . (($cur_window_num - 1) * $max_page_links), $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a></li>';

// page nn button
        for ($jump_to_page = 1 + (($cur_window_num - 1) * $max_page_links); ($jump_to_page <= ($cur_window_num * $max_page_links)) && ($jump_to_page <= $number_of_pages); $jump_to_page++) {
            if ($jump_to_page == $this->page_set) {
                $display_links_string .= '<li class="active"><a href="' . OSCOM::link($PHP_SELF, $parameters . $this->page_set_keyword . '=' . $jump_to_page, $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_PAGE_NO, $jump_to_page) . ' ">' . $jump_to_page . '<span class="sr-only">(current)</span></a></li>';
            } else {
                $display_links_string .= '<li><a href="' . OSCOM::link($PHP_SELF, $parameters . $this->page_set_keyword . '=' . $jump_to_page, $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_PAGE_NO, $jump_to_page) . ' ">' . $jump_to_page . '</a></li>';
            }
        }

// next window of pages
        if ($cur_window_num < $max_window_num) $display_links_string .= '<li><a href="' . OSCOM::link($PHP_SELF, $parameters . $this->page_set_keyword . '=' . (($cur_window_num) * $max_page_links + 1), $request_type) . '" class="pageResults" title=" ' . sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a></li>';

// next button
        if (($this->page_set < $number_of_pages) && ($number_of_pages != 1)) {
            $display_links_string .= '<li><a href="' . OSCOM::link($PHP_SELF, $parameters . $this->page_set_keyword . '=' . ($this->page_set + 1), $request_type) . '" title=" ' . PREVNEXT_TITLE_NEXT_PAGE . ' ">»</a></li>';
        } else {
            $display_links_string .= '<li class="disabled"><span>»</span></li>';
        }

        $display_links_string .= '</ul>';

        return $display_links_string;
    }

Scott

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...