问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/42858151/opencart-get-category-id-in-category-page