Opencart get category_id in category page

别来无恙 提交于 2021-02-11 09:21:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!