Get parent category for product page Opencart

China☆狼群 提交于 2019-12-09 17:05:02

问题


is there a way to get the parent category of a product, in the product page for Opencart? Thanks


回答1:


Yes you can. I've tested my code in OpenCart 1.5.1.x

First, you must modify the file /catalog/controller/product/product.php to add after the line 94: $product_info = $this->model_catalog_product->getProduct($product_id);

ADD this:

$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']; }

Then, you can use the variable <?php echo $category_id ?> in your template file (product.tpl).

Hope this help you



来源:https://stackoverflow.com/questions/9883105/get-parent-category-for-product-page-opencart

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