如何在特殊模块中添加倒数计时器(opencart v.1.5.3.1)

时间:2012-07-15 16:36:42

标签: opencart

我想在主页中显示的特殊模块(opencart 1.5.3.1)中添加倒数计时器。看起来像这样 http://opencart-themes.com/index.php?route=product/product&product_id=109

谁愿意帮助我?我根据你的代码尝试了几次。它不起作用。我真的很感谢你可以帮助我。

3 个答案:

答案 0 :(得分:0)

首先,你必须从数据库中获取date_start和date_end。编辑catalog / model / catalog / product.php。

更改

public function getProduct($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 DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.sort_order, p.date_expires >= NOW(), p.date_expires <= NOW() DESC");

public function getProduct($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 DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT date_start FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS date_start, (SELECT date_end FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS date_ends, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.sort_order, p.date_expires >= NOW(), p.date_expires <= NOW() DESC");

注意:如果您对此进行了修改并希望保留它们,我只添加了这两个值的部分。

然后你需要将值发送到视图文件,你可以在catalog / controller / module / special.php中这样做

        $this->data['products'][] = array(
            'product_id' => $result['product_id'],
            'thumb'      => $image,
            'name'       => $result['name'],
            'price'      => $price,
            'special'    => $special,
            'rating'     => $rating,
            'reviews'    => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
            'href'       => $this->url->link('product/product', 'product_id=' . $result['product_id']),
        );

更改为:

        $this->data['products'][] = array(
            'product_id' => $result['product_id'],
            'thumb'      => $image,
            'name'       => $result['name'],
            'price'      => $price,
            'special'    => $special,
            'rating'     => $rating,
            'reviews'    => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
            'href'       => $this->url->link('product/product', 'product_id=' . $result['product_id']),
            'date_start'     => $result['date_start'],
            'date_end'       => $result['date_end'],
        );

在catalog / view / theme / * your_theme * / template / module / special.tpl中,我们需要做一些事情。我们需要添加倒计时脚本,添加倒数计时器,然后拉取值。

1)添加脚本 - 如果至少有一个特殊的话,还有一个if语句只放置脚本。把它放在你的tpl的顶部

<?php if ($products) { ?>
<script type="text/javascript">
jQuery.fn.countdown = function (date, options, dateparse) {
    options = jQuery.extend({
        lang:{
            years:   [' year, ', ' years, '],
            months:  [' month, ', ' months, '],
            days:    [' day, ', ' days, '],
            hours:   [':', ':'],
            minutes: [':', ':'],
            seconds: ['', ''],
            plurar:  function(n) {
                return (n == 1 ? 0 : 1);
            }
        },
        prefix: "end: ",
        finish: "End!",
        redirect: '',
        dateparse: "2050-01-01 00:00:00" 
    }, options);

    var timestamp       = Date.parse(options.dateparse);

    var timeDifference  = function(begin, end) {
        if(end < begin){
            return false;
        }
        var diff = {
            seconds: [end.getSeconds() - begin.getSeconds(), 60],
            minutes: [end.getMinutes() - begin.getMinutes(), 60],
            hours: [end.getHours() - begin.getHours(), 24],
            days: [end.getDate()  - begin.getDate(), new Date(begin.getYear(), begin.getMonth(), 0).getDate()],
            months: [end.getMonth() - begin.getMonth()-1, 12],
            years: [end.getYear()  - begin.getYear(), 0]
        };

        var result = new Array();
        var flag = false;
        for(i in diff){
            if((i=='seconds' || i=='minutes') && diff[i][0]==0){
                result.push('00' + options.lang[i][options.lang.plurar(diff[i][0])]);
            }else{
                if(flag){
                    diff[i][0]--;
                    flag = false;
                }       
                if(diff[i][0] < 0){
                    flag = true;
                    diff[i][0] += diff[i][1];
                }
                if(!diff[i][0]) continue;
                if(i=='days' && diff[i][0]<0){
                    diff['days'][0]=Math.abs(1+diff['days'][0]);
                    diff['months'][0]++;
                }
                if(i=='years' && diff[i][0]<0)
                    return '';
                if((i=='seconds' || i=='minutes') && diff[i][0]<10)
                    diff[i][0]  = '0' + diff[i][0];

                if(diff[i][0]!=0)
                    result.push(diff[i][0] + '' + options.lang[i][options.lang.plurar(diff[i][0])]);
            }
        }
        return result.reverse().join('');
    };

    var timeCurrent = function(date){
        var hou     = date.getHours().toString();
        var min     = date.getMinutes().toString();
        var sec     = date.getSeconds().toString();
        hou         = (hou<10)?0+hou:hou;
        min         = (min<10)?0+min:min;
        sec         = (sec<10)?0+sec:sec;
        return hou+':'+min+':'+sec;
    };

    var elem        = $(this);
    var timeUpdate  = function(){
        dateJS      = new Date();

        timestamp   = parseInt(timestamp) + 1000;
        dateJS.setTime(timestamp);

        /*if(elem.parents('.timedependent-form-content').find('#currentTime').length)
            elem.parents('.timedependent-form-content').find('#currentTime').html(timeCurrent(dateJS));*/
        var s       = timeDifference(dateJS, date);
        if(s.length){
            elem.html(options.prefix + s);
        }else{
            clearInterval(timer);
            elem.html(options.finish);
            if(options.redirect != '')
                window.location.href    = options.redirect;
        }       
    };
    timeUpdate();
    var timer = setInterval(timeUpdate, 1000);      
};


</script>
<?php } ?>

更改

<?php foreach ($products as $product) { ?>

要:

<?php $now = time();
$count = 0;
foreach ($products as $product) {
$count++; ?>

在您喜欢的地方添加:

<?php $time_remaining = $result['date_end'];
    $countdown = strtotime("$time_remaining"); ?>

  <div class="timerbar">
        <h2 id="product<?php echo $count; ?>"></h2>
    </div><br/>
    <script>
        jQuery("#product<?php echo $count; ?>").countdown(new Date(<?php echo date('Y, m, d, H, i, s',$countdown); ?>), {
                                                                prefix:"",
                                                                finish:"Expired",
                                                                redirect:"",
                                                                dateparse:"<?php echo date('d F Y H:i:s',$now); ?>",
                                                                lang:{
            years:   [' year, ', ' years, '],
            months:  [' month, ', ' months, '],
            days:    [' day, ', ' days, '],
            hours:   [':', ':'],
            minutes: [':', ':'],
            seconds: ['', ''],
            plurar:  function(n) {
                return (n == 1 ? 0 : 1);
            }
        }});
    </script>

自定义输出:

  • finish =过期文字
  • redirect =如果您希望它在到期时重定向,请输入网址
  • lang =更改倒计时输出

答案 1 :(得分:0)

谢谢,这是代码:

public function updateViewed($product_id) {
    $this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = (viewed + 1) WHERE product_id = '" . (int)$product_id . "'");
}

public function getProduct($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 DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");

    if ($query->num_rows) {
        $query->row['price'] = ($query->row['discount'] ? $query->row['discount'] : $query->row['price']);
        $query->row['rating'] = (int)$query->row['rating'];

        return $query->row;
    } else {
        return false;
    }
}

答案 2 :(得分:0)

@Cleverbot答案很棒,但有一些遗漏或某些错误代码已经建立,正确答案如下:

第一步

编辑目录/ model / catalog / product.php。

更改

public function getProduct($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 DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.sort_order, p.date_expires >= NOW(), p.date_expires <= NOW() DESC");

public function getProduct($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 DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT date_start FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS date_start, (SELECT date_end FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS date_ends, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.sort_order, p.date_expires >= NOW(), p.date_expires <= NOW() DESC");

和上面代码搜索中的同一个地方文件

'special'          => $query->row['special'],

然后添加此代码

'date_ends'          => $query->row['date_ends'],
'date_start'          => $query->row['date_start'],

第二步:

然后你需要将值发送到视图文件,你可以在catalog / controller / module / special.php中这样做

$this->data['products'][] = array(
        'product_id' => $result['product_id'],
        'thumb'      => $image,
        'name'       => $result['name'],
        'price'      => $price,
        'special'    => $special,
        'rating'     => $rating,
        'reviews'    => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
        'href'       => $this->url->link('product/product', 'product_id=' . $result['product_id']),
    );

到这个

$this->data['products'][] = array(
            'product_id' => $result['product_id'],
            'thumb'      => $image,
            'name'       => $result['name'],
            'price'      => $price,
            'special'    => $special,
            'rating'     => $rating,
            'reviews'    => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
            'href'       => $this->url->link('product/product', 'product_id=' . $result['product_id']),
            'date_start'     => $result['date_start'],
            'date_ends'       => $result['date_ends'],

        );

第三步

目录/视图/主题/ your_theme /template/module/special.tpl 中,我们需要做一些事情。我们需要添加倒计时脚本,添加倒数计时器,然后拉取值。

1)添加倒计时脚本

将以下代码放在special.tpl文件的顶部(重要

<?php if ($products) { ?>
<script type="text/javascript">
jQuery.fn.countdown = function (date, options, dateparse) {
options = jQuery.extend({
    lang:{
        years:   [' year, ', ' years, '],
        months:  [' month, ', ' months, '],
        days:    [' day, ', ' days, '],
        hours:   [':', ':'],
        minutes: [':', ':'],
        seconds: ['', ''],
        plurar:  function(n) {
            return (n == 1 ? 0 : 1);
        }
    },
    prefix: "end: ",
    finish: "End!",
    redirect: '',
    dateparse: "2050-01-01 00:00:00" 
}, options);

var timestamp       = Date.parse(options.dateparse);

var timeDifference  = function(begin, end) {
    if(end < begin){
        return false;
    }
    var diff = {
        seconds: [end.getSeconds() - begin.getSeconds(), 60],
        minutes: [end.getMinutes() - begin.getMinutes(), 60],
        hours: [end.getHours() - begin.getHours(), 24],
        days: [end.getDate()  - begin.getDate(), new Date(begin.getYear(), begin.getMonth(), 0).getDate()],
        months: [end.getMonth() - begin.getMonth()-1, 12],
        years: [end.getYear()  - begin.getYear(), 0]
    };

    var result = new Array();
    var flag = false;
    for(i in diff){
        if((i=='seconds' || i=='minutes') && diff[i][0]==0){
            result.push('00' + options.lang[i][options.lang.plurar(diff[i][0])]);
        }else{
            if(flag){
                diff[i][0]--;
                flag = false;
            }       
            if(diff[i][0] < 0){
                flag = true;
                diff[i][0] += diff[i][1];
            }
            if(!diff[i][0]) continue;
            if(i=='days' && diff[i][0]<0){
                diff['days'][0]=Math.abs(1+diff['days'][0]);
                diff['months'][0]++;
            }
            if(i=='years' && diff[i][0]<0)
                return '';
            if((i=='seconds' || i=='minutes') && diff[i][0]<10)
                diff[i][0]  = '0' + diff[i][0];

            if(diff[i][0]!=0)
                result.push(diff[i][0] + '' + options.lang[i][options.lang.plurar(diff[i][0])]);
        }
    }
    return result.reverse().join('');
};
var timeCurrent = function(date){
    var hou     = date.getHours().toString();
    var min     = date.getMinutes().toString();
    var sec     = date.getSeconds().toString();
    hou         = (hou<10)?0+hou:hou;
    min         = (min<10)?0+min:min;
    sec         = (sec<10)?0+sec:sec;
    return hou+':'+min+':'+sec;
};

var elem        = $(this);
var timeUpdate  = function(){
    dateJS      = new Date();

    timestamp   = parseInt(timestamp) + 1000;
    dateJS.setTime(timestamp);

    /*if(elem.parents('.timedependent-form-content').find('#currentTime').length)
        elem.parents('.timedependent-form-content').find('#currentTime').html(timeCurrent(dateJS));*/
    var s       = timeDifference(dateJS, date);
    if(s.length){
        elem.html(options.prefix + s);
    }else{
        clearInterval(timer);
        elem.html(options.finish);
        if(options.redirect != '')
            window.location.href    = options.redirect;
    }       
};
timeUpdate();
var timer = setInterval(timeUpdate, 1000);      
};
</script>
<?php } ?>

2)添加倒计时器并拉出值。

更改

<?php foreach ($products as $product) { ?>

<?php $now = time();
$count = 0;
foreach ($products as $product) {
$count++; ?>

在您喜欢的地方添加:

 <?php $time_remaining = $product['date_ends'];
$countdown = strtotime("$time_remaining"); ?>
 <div class="timerbar">
    <h2 id="product<?php echo $count; ?>"></h2>
</div><br/>
<script>
    jQuery("#product<?php echo $count; ?>").countdown(new Date(<?php echo date('Y, m, d, H, i, s',$countdown); ?>), {
                                                            prefix:"",
                                                            finish:"Expired",
                                                            redirect:"",
                                                            dateparse:"<?php echo date('d F Y H:i:s',$now); ?>",
                                                            lang:{
        years:   [' year, ', ' years, '],
        months:  [' month, ', ' months, '],
        days:    [' day, ', ' days, '],
        hours:   [':', ':'],
        minutes: [':', ':'],
        seconds: ['', ''],
        plurar:  function(n) {
            return (n == 1 ? 0 : 1);
        }
    }});
</script>

要自定义输出:

  • finish =过期文字
  • redirect =如果您希望它在到期时重定向,请输入网址
  • lang =更改倒计时输出

所有这些代码都适用于我,希望能与您合作

我用opencart v.1.5.6.4尝试了它,这是工作