获取产品页面Opencart的父类别

Lea*_*Lea 7 php opencart

有没有办法在Opencart的产品页面中获取产品的父类别?谢谢

小智 13

是的你可以.我在OpenCart 1.5.1.x中测试了我的代码

首先,您必须修改文件/catalog/controller/product/product.php以在第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']; }

然后,您可以<?php echo $category_id ?>在模板文件(product.tpl)中使用该变量.

希望这对你有所帮助