试图在opencart中以特殊价格添加jQuery倒数计时器 [英] trying to add jquery countdown timer for special price in opencart

查看:97
本文介绍了试图在opencart中以特殊价格添加jQuery倒数计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在opencart中将jquery的倒数计时器设为特价.

i am trying to put jquery count down timer for special price in opencart.

因为我们在打开的购物车管理面板中有特价的开始日期和结束日期,

as we have start date and end date for special price in open cart admin panel,

我想让jquery计数计时器显示剩余的

I want to have jquery count timer to show remaining

(days:Hours:Min:SEC)

以那个特殊的价格.

我获得了jquery倒计时的代码,并将其放入产品的模板文件中,但是它不起作用,并且没有帮助或Internet上的代码.

i get the code for jquery countdown and put in template file of product but its not working and no help or code on internet.

谢谢

推荐答案

很好的问题.如您所述,您希望显示的数据已经是OpenCart的admin/后端的一部分,但在前端则不可用.我将向您展示如何添加它.

Excellent question. As you noted, the data you wish to display is already part of the admin/backend of OpenCart, but it is not available on the frontend. I'll show you how to add it.

由于 MVC 的架构, OpenCart,您必须在3个地方进行更改.模型,视图和控制器.首先,您必须从数据库中获取数据.因为我们正在寻求对前端进行更改,所以所有内容都将包含在 catalog 目录中.如果您看一下代码,就会发现 catalog/model/catalog/product.php .这是我们要做的第一个更改.特价可在ModelCatalogProduct中获得,但特价结束日期不可用.您可以修改现有的getProduct()方法,也可以创建自己的方法.我将向您展示后者,而前者则留给用户练习.

Due to the MVC architecture of OpenCart, you'll have to make changes in 3 places. The Model, the View and the Controller. First things first, you will have to get the data from the database. Because we're looking to make changes to the frontend, everything will be contained in the catalog directory. If you look at the code, you'll find catalog/model/catalog/product.php. This is where we're going to make our first change. Special price is available in the ModelCatalogProduct, but the special price end date is not. You can either modify the existing getProduct() method, or you can create your own method. I am going to show you the latter, while the former is left as an exercise for the user.

catalog/model/catalog/product.php

class ModelCatalogProduct extends Model {
    ...

    // Return an array containing special (price, date_start, date_end).
    // or false if no special price exists.
    public function getSpecialPriceDates($product_id) {
        if ($this->customer->isLogged()) {
            $customer_group_id = $this->customer->getCustomerGroupId();
        } else {
            $customer_group_id = $this->config->get('config_customer_group_id');
        }
        $query = $this->db->query("SELECT price, date_start, date_end FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' AND customer_group_id = '" . (int)$customer_group_id . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1");

        if ($query->num_rows) {
            return array(
                'special'    => $query->row['price'],
                'date_start' => $query->row['date_start'],
                'date_end'   => $query->row['date_end'],
            );
        } else {
            return false;
        }
    }

    ...
}

太好了,现在有了一个功能getSpecialPriceDates(),您可以调用该函数来查找特殊产品何时结束.让我们将此数据提供给视图.为此,我们将不得不将其添加到Controller中.在ControllerProductProduct中查找设置特殊"变量的位置.

Great, now there is a function getSpecialPriceDates() you can call to find out when a product special will end. Let's make this data available to the View. In order to to that, we're going to have to add it to the Controller. Look in the ControllerProductProduct for where the 'special' variable is set.

catalog/controller/product/product.php

...

if ((float)$product_info['special']) {
    $this->data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
    // +++ NEW CODE
    $special_info = $this->model_catalog_product->getSpecialPriceDates($product_id);
    if ($special_info) {
        $this->data['special_date_end'] = $special_info['date_end'];
    } else {
        $this->date['special_date_end'] = false;
    }
    // +++ END NEW CODE
} else {
    $this->data['special'] = false;
}

...

最后一个任务是在产品视图中实现您的计时器.该目录将位于 catalog/view/theme/default/template/product/product.tpl 之类的位置(如果您有自己的主题,请将 default 替换为 {您的主题} ). jQuery有很多不同的倒数计时器解决方案,请选择收藏夹

The last task is to implement your timer in the product view. This will be located somewhere like catalog/view/theme/default/template/product/product.tpl (if you have your own theme, replace default with {your-theme}). There are a lot of different countdown timer solutions for jQuery, pick your favorite.

目录/视图/主题/默认/模板/product/product.tpl

    <?php if (!$special) { ?>
    <?php echo $price; ?>
    <?php } else { ?>
    <span class="price-old"><?php echo $price; ?></span> <span class="price-new"><?php echo $special; ?></span>
      <?php if ($special_date_end): ?>
      <!-- TIMER CODE HERE -->
      <div class="timer"></div>
      <?php endif; ?>
    <?php } ?>

这篇关于试图在opencart中以特殊价格添加jQuery倒数计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆