I was looking for an answer in different forums, seems like people encounter it, but wasn't able to find the fix.
Shortly: Pagination doesn't work when I search for something.
Here is how search URL is looking: /index.php?route=product/category&path=1&search=pink%20floyd
Here is what I see on the web page source as a generated pagination pages:
Code: Select all
<div class="pages"><ul class="pagination"><li class="active"><span>1</span></li>
<li><a href="***/index.php?route=product/category&path=1&page=2">2</a></li>
<li><a href="***/index.php?route=product/category&path=1&page=3">3</a></li>
<li><a href="***/index.php?route=product/category&path=1&page=4">4</a></li>
<li><a href="***/index.php?route=product/category&path=1&page=2">></a></li>
<li><a href="***/index.php?route=product/category&path=1&page=4">>|</a></li></ul>
</div>
oclayerednavigation.php:
Code: Select all
$pagination = new Pagination();
$pagination->total = $product_total;
$pagination->page = $page;
$pagination->limit = $limit;
$pagination->url = $base_url . 'index.php?route=product/category&path=' . $category_id . $url . '&page={page}';
$data['pagination'] = $pagination->render();
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
if ($limit && ceil($product_total / $limit) > $page) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page + 1), true), 'next');
}
$data['sort'] = $sort;
$data['order'] = $order;
$data['limit'] = $limit;
$json['result_html'] = $this->load->view('extension/module/oclayerednavigation/occategoryfilter', $data);
Code: Select all
$pagination = new Pagination();
$pagination->total = $product_total;
$pagination->page = $page;
$pagination->limit = $limit;
$pagination->url = $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&page={page}');
$data['pagination'] = $pagination->render();
$paginationOld = new Pagination();
$paginationOld->total = $product_total;
$paginationOld->page = $page;
$paginationOld->limit = $limit;
$paginationOld->url = $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&page={page}');
$data['link'] = $this->url->link('product/category', 'path=' . $this->request->get['path']);
$data['paginationOld'] = $paginationOld->render();
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
if ($page == 1) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id']), 'canonical');
} else {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. $page), 'canonical');
}
if ($page > 1) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . (($page - 2) ? '&page='. ($page - 1) : '')), 'prev');
}
if ($limit && ceil($product_total / $limit) > $page) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page + 1)), 'next');
}
$data['vinyl_states'] = $this->model_catalog_product->getVinylStates();
$data['cover_states'] = $this->model_catalog_product->getCoverStates();
$data['vinyl_types'] = $this->model_catalog_product->getVinylTypes();
$data['price_min'] = $this->model_catalog_product->getMinPrice();
$data['price_max'] = $this->model_catalog_product->getMaxPrice();
$data['year_min'] = $this->model_catalog_product->getMinYear();
$data['year_max'] = $this->model_catalog_product->getMaxYear();
$data['sort'] = $sort;
$data['order'] = $order;
$data['limit'] = $limit;
$data['continue'] = $this->url->link('common/home');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$json = json_encode(['content' => $this->load->view('extension/module/oclayerednavigation/occategory', $data)]);
$this->response->addHeader('Content-Type: application/json');
echo json_encode($json);
die();
}
$this->response->setOutput($this->load->view('product/category', $data));
Code: Select all
public function mainSearch($term)
{
$products = $this->searchByProductName($term);
$manufactures = $this->searchByManufacturer($term);
$items = [];
$this->load->model('tool/image');
foreach ($products as $product) {
$id = $product['product_id'];
$items[$id]['id'] = $id;
$items[$id]['text'] = $product['name'];
$items[$id]['type'] = 'product';
$items[$id]['manufacturer'] = $product['manufacturer'];
if ($product['image']) {
$image = $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
}
$items[$id]['image'] = $image;
$items[$id]['link'] = $this->url->link('product/product', 'product_id=' . $id);
}
foreach ($manufactures as $manufacture) {
$id = $manufacture['manufacturer_id'];
$items[$id]['id'] = $id;
$items[$id]['text'] = $manufacture['name'];
$items[$id]['type'] = 'manufacturer';
if ($manufacture['image']) {
$image = $this->model_tool_image->resize($manufacture['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
}
$items[$id]['image'] = $image;
$items[$id]['link'] = $this->url->link('product/category/index', 'path=' . MAIN_CATEGORY . '&filters[manufacturer]=' . $id);
}
return $items;
}
Thank you.