2016-05-31 54 views

回答

1

要顯示頁腳上的精選產品,我們需要手動獲取產品。

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> 

還可以顯示主頁和其他頁面上的特色產品爲 類似添加下面的代碼過程

相關問題