Hazzy
Hazzy

Reputation: 43

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.

Upvotes: 1

Views: 992

Answers (1)

KarambolNaA4
KarambolNaA4

Reputation: 29

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

Upvotes: 1

Related Questions