获取产品页面Opencart的父类别 [英] Get parent category for product page Opencart

查看:69
本文介绍了获取产品页面Opencart的父类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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 add after 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的父类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆