【问题标题】:how to display featured-product list in footer.tpl opencart如何在footer.tpl opencart中显示特色产品列表
【发布时间】:2016-05-31 07:09:22
【问题描述】:

注意:未定义变量:/mnt/E/webdev/practice/opencart/bigshop_2/site/upload/catalog/view/theme/default/template/common/footer 中的产品.tpl 第 42 行

【问题讨论】:

    标签: opencart


    【解决方案1】:

    要在页脚显示特色产品,我们需要手动获取产品。

    因为在管理页面布局上只有“上、下、左、右”

    我已经准备了以下代码,我们可以从中获取产品 特色模块

    页脚控制器页面:添加以下代码

    /*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>
    

    您还可以在主页和其他页面上显示特色产品 类似的过程

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-20
      • 1970-01-01
      相关资源
      最近更新 更多