2014-03-04 48 views
1

我在latest_content.tpl文件中使用此代碼獲取類別名稱。但它不顯示類別名稱。我如何獲得opencart中的類別名稱。在opencart主頁上獲取產品類別

$categories = $this->model_catalog_product->getCategories($product_id); 
if ($categories) 
    $categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']); 
$this->data['category_title'] = $categories_info['name']; 
echo echo $category_title; 

回答

1

在,前$this->data['products'][] = array(地址:

$categories = $this->model_catalog_product->getCategories($result['product_id']); 
if($categories){ 
    $categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']); 
    $category_title = $categories_info['name']; 
}else{ 
    $category_title = ''; 
} 

更新$this->data['products'][]排列如下:

$this->data['products'][] = array(
      'product_id' => $result['product_id'], 
      'category_title' => $category_title, 
      'thumb'  => $image, 
      'name'  => $result['name'], 
      'price'  => $price, 
      'special' => $special, 
      'rating'  => $rating, 
      'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']), 
      'href'  => $this->url->link('product/product', 'product_id=' . $result['product_id']), 
     ); 

現在latest.tpl,你會得到的類別標題$product['category_title']

附加信息: - 應在控制器內調用模型功能。控制器中定義的變量$this->data['variable_name']可以在模板文件中作爲$variable_name訪問。

有一個nayay!

+0

感謝Sankar V ........... – user3190238

相關問題