如何在footer.tpl opencart

时间:2016-05-31 07:09:22

标签: opencart

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

1 个答案:

答案 0 :(得分: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>
  

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