2016-12-04 102 views
0

我正在使用Opencart。我想显示搜索产品搜索的类别。在搜索页面上显示产品类别

Normally: Search-> product name, 

我想告诉喜欢我的结果:

Search-> Category-> subcategory-> product name 

版本:2.1.0.1

+0

您想在搜索结果中显示每个产品类别? – DigitCart

+0

是的...... – ismail

+0

试试这个:http://stackoverflow.com/questions/40803997/opencart-to-show-category-for-each-product-in-search-results-page – DigitCart

回答

0

转到您的检索算法控制器

catalog/controller/product/search.php 

约行数没有。 247将这段代码

  $data['products'][] = array(
       'product_id' => $result['product_id'], 
       'thumb'  => $image, 
       'name'  => $result['name'], 
       'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..', 
       'price'  => $price, 
       'special'  => $special, 
       'tax'   => $tax, 
       'rating'  => $result['rating'], 
       'href'  => $this->url->link('product/product', 'product_id=' . $result['product_id'] . $url) 
      ); 

有了这一个

  $cats = $this->model_catalog_product->getCategories($result['product_id']); 
      $sep = ''; 
      $catnames = ''; 

      foreach ($cats as $cat){ 

       $catarr = $this->model_catalog_category->getCategory($cat['category_id']); 

       $catnames .= $sep.$catarr['name']; 
       $sep = ', '; 
      } 

      $data['products'][] = array(
       'product_id' => $result['product_id'], 
       'thumb'  => $image, 
       'name'  => $result['name'], 
       'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..', 
       'price'  => $price, 
       'special'  => $special, 
       'tax'   => $tax, 
       'rating'  => $result['rating'], 
       'href'  => $this->url->link('product/product', 'product_id=' . $result['product_id'] . $url), 
       'category' => $catnames 
      ); 

而在你的模板文件(我要提到的默认主题的路径,如果你使用任何其他的主题,那么你可以改变它按您的主题)

catalog/view/theme/default/tempate/product/seach.tpl 

可以使用$产品[“类”]只需调用它在你的循环

就是这样!

+0

@ismail它工作吗为你? –

相关问题