N
N
Nikita2019-03-29 13:11:09
opencart
Nikita, 2019-03-29 13:11:09

How to display links to OCFilter categories in the product card of OpenCart 2.3?

Hello. The well-known OCFilter filtering module is installed on the site. Landing pages are created with it. Question: how to display on the product card page links to the landing pages to which this product belongs?
There is a code to display these links in categories:
catalog/controller/product/category.php

$data['ocfilter_pages'] = array();

      $this->load->model('catalog/ocfilter');

      $ocfilter_pages = $this->model_catalog_ocfilter->getPages();

      foreach ($ocfilter_pages as $ocfilter_page) {
        if ($ocfilter_page['category_id'] != $category_id) {
          continue;
        }

        if (isset($this->request->get['path'])) {
          $link = rtrim($this->url->link('product/category', 'path=' . $this->request->get['path']), '/');
        } else {
          $link = rtrim($this->url->link('product/category', 'path=' . $ocfilter_page['category_id']), '/');
        }

        if ($ocfilter_page['keyword']) {
          $link .= '/' . $ocfilter_page['keyword'];
        } else {
          $link .= '/' . $ocfilter_page['params'];
        }

        if ($this->config->get('config_seo_url_type') == 'seo_pro') {
          $link .= '/';
        }

        $data['ocfilter_pages'][] = array(
          'text' => $ocfilter_page['title'],
          'selected' => (!empty($ocfilter_page_info) && $ocfilter_page_info['ocfilter_page_id'] == $ocfilter_page['ocfilter_page_id']),
          'href' => $link
        );
      }

Output in the template catalog/view/theme/*/template/product/category.tpl
<?php if (!empty($ocfilter_pages)) { ?>
    <hr />
    <ul class="list-inline">
      <?php foreach ($ocfilter_pages as $ocfilter_page) { ?>
      <li>
        <?php if ($ocfilter_page['selected']) { ?>
        <strong><?php echo $ocfilter_page['text']; ?></strong>
        <?php } else { ?>
        <a href="<?php echo $ocfilter_page['href']; ?>"><?php echo $ocfilter_page['text']; ?></a>
        <?php } ?>
      </li>
      <?php } ?>
    </ul>
    <?php } ?>

How should I modify the category.php controller code for product.php? The developer himself does not deal with such improvements.
As I understand it, we need to modify this part of the code, which will skip all links that this product does not belong to:
if ($ocfilter_page['category_id'] != $category_id) {
          continue;
        }

Or not only that? Please help in solving.

Answer the question

In order to leave comments, you need to log in

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

In $ocfilter_page, store an array of products that are on it.
And instead

if ($ocfilter_page['category_id'] != $category_id) {
          continue;
        }

Check the availability of the product on the page:
if (!in_array($product_id, $ocfilter_page['products'])) {
          continue;
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question