简体   繁体   中英

Opencart get category_id in category page

Trying to get "new" sticker in category page. For example if product have category 219 it would have sticker.

What I have added in controller category.php

$product_info = $this->model_catalog_product->getProduct($product_id);

$categories = $this->model_catalog_product->getCategories($product_info['$product_id']);

$categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);

$this->data['category_id'] = $categories_info['category_id'];

In category.tpl

<?php if($category_id=="219") { ?>
<img src="new.jpg">
<?php } ?>

But nothing have appeared.

UPD: change a code

$categories = $this->model_catalog_product->getCategories($result['product_id']);

    $categories_info = $this->model_catalog_category->getCategory($categories[3]['category_id']);

    $this->data['category_id'] = $categories_info['category_id'];

category.tpl

  <?php if ($category_id=="219") { ?>                           

            <?php } else {  ?>

            <?php } ?>

It works only if i use $categories[3]['category_id'] but I can't search value it array with php function in_array.

If you want send some data for template you have to use $data array.

For example:

$data['category_id'] = $categories_info['category_id'];

Then call it in your templase using $category_id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM