问题描述
在Opencart的产品页面中是否可以获取产品的父类别?谢谢
is there a way to get the parent category of a product, in the product page for Opencart? Thanks
推荐答案
可以.我已经在OpenCart 1.5.1.x中测试了我的代码
Yes you can.I've tested my code in OpenCart 1.5.1.x
首先,您必须修改/catalog/controller/product/product.php文件以添加在第94行之后:$ product_info = $ this-> model_catalog_product-> getProduct($ product_id);
First, you must modify the file /catalog/controller/product/product.php to addafter the line 94:$product_info = $this->model_catalog_product->getProduct($product_id);
添加此内容:
$categories = $this->model_catalog_product->getCategories($product_info['product_id']);if ($categories){$categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);$this->data['category_id'] = $categories_info['category_id'];}
$categories = $this->model_catalog_product->getCategories($product_info['product_id']);if ($categories){$categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);$this->data['category_id'] = $categories_info['category_id'];}
然后,您可以在模板文件(product.tpl)中使用变量<?php echo $category_id ?>
.
Then, you can use the variable <?php echo $category_id ?>
in your template file (product.tpl).
希望对您有帮助
这篇关于获取产品页面Opencart的父类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!