2015-10-01 60 views
1

我用MOD bycategory显示在主页上 现在的产品,IM”想显示描述类别(不要产物)(上主页) 代码目录/控制器/模块/ bycategory.php显示说明类别为Opencart的2.0

<?php 
    class ControllerModuleBycategory extends Controller { 
     public function index($setting) { 
      $this->load->language('module/bycategory'); 

      $data['heading_title'] = $setting['name']; 

      $data['text_tax'] = $this->language->get('text_tax'); 

      $data['button_cart'] = $this->language->get('button_cart'); 
      $data['button_wishlist'] = $this->language->get('button_wishlist'); 
      $data['button_compare'] = $this->language->get('button_compare'); 

      $this->load->model('catalog/product'); 

      $this->load->model('tool/image'); 

      $data['products'] = array(); 

      $filter_data = array(
       'sort' => 'p.date_added', 
       'order' => 'DESC', 
       'start' => 0, 
       'limit' => $setting['limit'], 
       'filter_category_id'=>$setting['category'] 
      ); 

      $data['type'] = $setting['type']; 

      $results = $this->model_catalog_product->getProducts($filter_data); 

      if ($results) { 
       foreach ($results as $result) { 
        if ($result['image']) { 
         $image = $this->model_tool_image->resize($result['image'], $setting['width'], $setting['height']); 
        } else { 
         $image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']); 
        } 

        if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { 
         $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))); 
        } else { 
         $price = false; 
        } 

        if ((float)$result['special']) { 
         $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'))); 
        } else { 
         $special = false; 
        } 

        if ($this->config->get('config_tax')) { 
         $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']); 
        } else { 
         $tax = false; 
        } 

        if ($this->config->get('config_review_status')) { 
         $rating = $result['rating']; 
        } else { 
         $rating = false; 
        } 

        $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'  => $rating, 
         'href'  => $this->url->link('product/product', 'product_id=' . $result['product_id']), 
        ); 
       } 

       if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/bycategory.tpl')) { 
        return $this->load->view($this->config->get('config_template') . '/template/module/bycategory.tpl', $data); 
       } else { 
        return $this->load->view('default/template/module/bycategory.tpl', $data); 
       } 
      } 
     } 
    } 

和代码目录/视图/主题/默认/模板/模块/ bycategory.tpl

<?php foreach ($products as $product) { ?> 
    <?php 
    if($type=="vertical"){ 
     ?> 
     <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> 
     <?php 
    }else{ 
     ?> 
     <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12"> 
     <?php 
    } 
    ?> 
    <div class="product-thumb transition"> 
     <div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></a></div> 
     <div class="caption"> 
     <h4><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></h4> 
     <?php if ($product['rating']) { ?> 
     <div class="rating"> 
      <?php for ($i = 1; $i <= 5; $i++) { ?> 
      <?php if ($product['rating'] < $i) { ?> 
      <span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span> 
      <?php } else { ?> 
      <span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span> 
      <?php } ?> 
      <?php } ?> 
     </div> 
     <?php } ?> 
     <?php if ($product['price']) { ?> 
     <p class="price"> 
      <?php if (!$product['special']) { ?> 
      <?php echo $product['price']; ?> 
      <?php } else { ?> 
      <span class="price-new"><?php echo $product['special']; ?></span> <span class="price-old"><?php echo $product['price']; ?></span> 
      <?php } ?> 
      <?php if ($product['tax']) { ?> 
      <span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span> 
      <?php } ?> 
     </p> 
     <?php } ?> 
     </div> 
     <div class="button-group"> 
     <button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button> 
     <button type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-heart"></i></button> 
     <button type="button" data-toggle="tooltip" title="<?php echo $button_compare; ?>" onclick="compare.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-exchange"></i></button> 
     </div> 
    </div> 
    </div> 
    <?php } ?> 
</div> 

如何显示[![类别描述] [1]] [1](按主页分类)? 帮帮我! 链接演示http://duhocaaumy.com/demo.jpg

回答

0

尝试这种解决方案,

添加以下代码目录/控制器/模块/ bycategory.php

$category_info = $this->model_catalog_category->getCategory($setting['category']); 
$data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8'); 

转到目录/视图/主题/默认/模板/module/bycategory.tpl

将下面的代码添加到您想要显示类别描述的地方

<?php echo $description; ?>