如何在footer.tpl中显示精选产品列表opencart

问题描述:

注意:未定义的变量:/mnt/E/webdev/practice/opencart/bigshop_2/site/upload/catalog/view/theme/default/template/common/footer.tpl on line 42如何在footer.tpl中显示精选产品列表opencart

要显示页脚上的精选产品,我们需要手动获取产品。

becuse在管理页面布局只有我们有“上,下,左,右”

我有准备下面的代码,我们可以从 功能模块拿到产品

页脚控制器页:下加代码

/*Featued product*/ 


    $this->load->model('catalog/product'); 
          $this->load->language('catalog/category'); 
          $this->load->model('tool/image'); 
          $this->load->language('module/featured'); 
          $data['heading_title'] = $this->language->get('heading_title'); 

         $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'); 
         $featured_module_id=32; 
         $featured_detail = $this->model_catalog_product->getFeaturedProductId($featured_module_id); 

          foreach ($featured_detail['product'] as $product_id) { 
           $product_info = $this->model_catalog_product->getProduct($product_id); 

           if ($product_info) { 
            if ($product_info['image']) { 
             $image = $this->model_tool_image->resize($product_info['image'], $featured_detail['width'], $featured_detail['height']); 
            } else { 
             $image = $this->model_tool_image->resize('placeholder.png', $featured_detail['width'], $featured_detail['height']); 
            } 

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

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

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

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

            $data['products'][] = array(
             'product_id' => $product_info['product_id'], 
             'thumb'  => $image, 
             'name'  => $product_info['name'], 
             'description' => utf8_substr(strip_tags(html_entity_decode($product_info['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=' . $product_info['product_id']) 
            ); 
           } 
          } 

页脚模型页:添加下面的代码

public function getFeaturedProductId($data){ 
        $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . $this->db->escape($data) . "'"); 

         if ($query->row) { 
          return json_decode($query->row['setting'], true); 
         } else { 
          return array(); 
         } 
       } 

和页脚视图页面:你喜欢的地方显示

<div class="row"> 
    <?php foreach ($products as $product) { ?> 
    <div class="product-layout col-lg-3 col-md-3 col-sm-6 col-xs-12"> 
    <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> 
     <p><?php echo $product['description']; ?></p> 
     <?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> 

还可以显示主页和其他页面上的特色产品为 类似添加下面的代码过程