开发者

trying to add jquery countdown timer for special price in opencart

i am tr开发者_如何学运维ying 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,

I want to have jquery count timer to show remaining

(days:Hours:Min:SEC)

for that special price.

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.

thanks


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.

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;
        }
    }

    ...
}

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;
}

...

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.

catalog/view/theme/default/template/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 } ?>


Check what I got for you

Also check this

More Option over here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜