opencart 2.x没有将最新产品模块的值传递给查看

时间:2015-09-16 07:22:12

标签: php opencart2.x

默认情况下,Opencart最新产品显示产品名称,产品描述和价格,但现在我想要产品预订价格(所有产品的新字段添加)在最新产品部分,所以我更改了我的最新产品代码并添加了代码来显示预订价格。这是最新产品的完整代码。

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

        $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');

        $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']
        );
        $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['product']=$result['product_id'];

                $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,
                    'booking_price' => $result['booking_price'],
                    '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/latest.tpl')) {
                return $this->load->view($this->config->get('config_template') . '/template/module/latest.tpl', $data);
            } else {
                return $this->load->view('default/template/module/latest.tpl', $data);
            }
        }
    }
}

latest.tpl

  <script>
jQuery(document).ready(function(){

    $(".quickview-latest").fancybox({
            maxWidth    : 800,
            maxHeight   : 600,
            fitToView   : false,
            width       : '70%',
            height      : '70%',
            autoSize    : false,
            closeClick  : false,
            openEffect  : 'elastic',
            closeEffect : 'elastic',

        });
});
</script>
<div class="box latest">
    <div class="box-heading"><h3><?php echo $heading_title; ?></h3></div>
    <div class="box-content">       
            <div class="row">
            <?php $g=0; foreach ($products as $product) { $g++ ?>
            <div class="product-layout col-lg-3 col-md-3 col-sm-3 col-xs-6">
                <div class="product-thumb transition">
                <a class="quickview quickview-latest" data-rel="details" href="#quickview_latest_<?php echo $g?>">
                    <?php echo $text_quick; ?>
                </a>
                <div class="quick_info">
                    <div id="quickview_latest_<?php echo $g?>">
                        <div>
                            <div class="left col-sm-4">
                                    <div class="quickview_image image"><a href="<?php echo $product['href']; ?>"><img alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" src="<?php echo $product['thumb']; ?>" /></a></div>
                                </div>
                                <div class="right col-sm-8">
                                    <h2><?php echo $product['name']; ?></h2>
                                    <div class="inf">
                                        <?php if ($product['author']) {?>
                                            <p class="quickview_manufacture manufacture manufacture"><?php echo $text_manufacturer; ?> <a href="<?php echo $product['manufacturers'];?>"><?php echo $product['author']; ?></a></p>
                                        <?php }?>
                                        <?php if ($product['model']) {?>
                                            <p class="product_model model"><?php echo $text_model; ?> <?php echo $product['model']; 
                                             ?></p>
                                        <?php }?>

                                        <?php if ($products['booking_price']) {?>
                                        <p class="product_model model"><?php echo $text_model; ?> <?php echo $products['booking_price']; 
                                             ?></p>
                                        <?php }?>


                                        <?php if ($product['price']) { ?>
                                        <div 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 } ?>
                                        </div>
                                        <?php } ?>
                                    </div>
                                    <div class="cart-button">                                   
                                        <button type="button" class="btn btn-icon" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-star"></i></button><button type="button" class="btn btn-icon" data-toggle="tooltip" title="<?php echo $button_compare; ?>" onclick="compare.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-exchange"></i></button><button type="button" class="btn btn-icon btn-add" data-toggle="tooltip" title="<?php echo $button_cart; ?>" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i></button>
                                    </div>
                                    <div class="clear"></div>
                                    <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 fa-stack-2x"></i></span>
                                        <?php } else { ?>
                                        <span class="fa fa-stack"><i class="fa fa-star active fa-stack-2x"></i></span>
                                        <?php } ?>
                                        <?php } ?>
                                    </div>

                                </div>
                                <div class="col-sm-12">
                                    <div class="quickview_description description">
                                        <?php echo $product['description1'];?>
                                    </div>
                                </div>
                        </div>
                    </div>
                </div>                  
                    <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 class="new_pr"><?php echo $text_new; ?></div>
                    </div>
                    <div class="caption">
                        <?php if ($product['price']) { ?>
                        <div 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 } ?>
                        </div>
                        <?php } ?>

                        <?php if ($product['booking_price']) {?>
                            <p class="product_model model"><?php echo $text_model; ?> <?php echo $product['booking_price']; 
                                             ?></p>
                                        <?php }?>

                        <div class="name">
                            <a href="<?php echo $product['href']; ?>">
                                <?php echo $product['name']; ?>
                            </a>
                        </div>
                        <div class="description"><?php echo mb_substr($product['description'],0,84,'UTF-8').'...'; ?></div>

                        <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 fa-stack-2x"></i></span>
                            <?php } else { ?>
                            <span class="fa fa-stack"><i class="fa fa-star active fa-stack-2x"></i></span>
                            <?php } ?>
                            <?php } ?>
                        </div>

                    </div>
                    <div class="cart-button">
                        <button class="btn btn-icon" type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-star"></i></button><button class="btn btn-add" type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><span><?php echo $button_cart;  ?></span></button>
                    </div>
                </div>
            </div>
            <?php } ?>

        </div>
    </div>
</div>

我收到此错误 注意:第114行的C:\ wamp \ www \ royal \ catalog \ view \ theme \ theme546 \ template \ module \ latest.tpl中的未定义索引:booking_price

任何帮助和建议都会很明显。谢谢。

1 个答案:

答案 0 :(得分:0)

如果我理解您的问题,并且您希望在商店中显示未在控制器中设置的值,我会亲自使用vQmod扩展名(例如this one而不是直接影响控制器文件。