M
M
maks789452019-04-16 16:04:21
opencart
maks78945, 2019-04-16 16:04:21

How to display conditional 404 on product page in OpenCard?

Good afternoon, there is a get parameter with the page number, but the problem is that if you specify the page 999999, it returns that there are no products, how to make it return 404 when requesting a page on which there are no products?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zoozag, 2019-04-16
@maks78945

For example 2.3:
ControllerProductCategory
Find

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');
      }

add after
if ($limit && ceil($product_total / $limit) < $page) {
  $url = '';

  if (isset($this->request->get['path'])) {
    $url .= '&path=' . $this->request->get['path'];
  }

  if (isset($this->request->get['filter'])) {
    $url .= '&filter=' . $this->request->get['filter'];
  }

  if (isset($this->request->get['sort'])) {
    $url .= '&sort=' . $this->request->get['sort'];
  }

  if (isset($this->request->get['order'])) {
    $url .= '&order=' . $this->request->get['order'];
  }

  if (isset($this->request->get['page'])) {
    $url .= '&page=' . $this->request->get['page'];
  }

  if (isset($this->request->get['limit'])) {
    $url .= '&limit=' . $this->request->get['limit'];
  }

  $data['breadcrumbs'][] = array(
    'text' => $this->language->get('text_error'),
    'href' => $this->url->link('product/category', $url)
  );

  $this->document->setTitle($this->language->get('text_error'));

  $data['heading_title'] = $this->language->get('text_error');

  $data['text_error'] = $this->language->get('text_error');

  $data['button_continue'] = $this->language->get('button_continue');

  $data['continue'] = $this->url->link('common/home');

  $this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found');

  $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');

  $this->response->setOutput($this->load->view('error/not_found', $data));
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question