Post by forkintheass » Mon Aug 20, 2018 8:04 am

Greetings colleagues,

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&amp;path=1&amp;page=2">2</a></li>
	<li><a href="***/index.php?route=product/category&amp;path=1&amp;page=3">3</a></li>
	<li><a href="***/index.php?route=product/category&amp;path=1&amp;page=4">4</a></li>
	<li><a href="***/index.php?route=product/category&amp;path=1&amp;page=2">&gt;</a></li>
	<li><a href="***/index.php?route=product/category&amp;path=1&amp;page=4">&gt;|</a></li></ul>
	</div>
The problem is also that I can't understand what controller generates that. I found the pagination code with product/category in two files:

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 . '&amp;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);
and in category.php:

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));
The search function in product.php looks like the following (however this may be irrelevant to the problem):

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;
	}
It seems like the answer is something near, but I cannot figure how to correct so that it works.

Thank you.

Newbie

Posts

Joined
Mon Jun 04, 2018 6:23 pm

Post by straightlight » Tue Aug 21, 2018 6:15 am

Request is about an installed extension. Contact the extension developer or create a new service request in the Commercial Support section of the forum to get this done as a custom job to resolved this issue.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: DigitCart, rod4OpenCart, winter and 29 guests