我正在尝试在 opencart 中以特价放置 jquery 倒数计时器。
因为我们在打开的购物车管理面板中有特价的开始日期和结束日期,
我想要 jquery 计数计时器来显示剩余
(天:小时:分钟:秒)
特价。
我得到了 jquery 倒计时的代码并放入了产品的模板文件,但它不起作用,互联网上没有任何帮助或代码。
谢谢
最佳答案
好问题。如您所述,您希望显示的数据已经是 OpenCart 管理/后端的一部分,但在前端不可用。我将向您展示如何添加它。
由于 MVC OpenCart 的体系结构,您必须在 3 个地方进行更改。模型、 View 和 Controller 。首先,您必须从数据库中获取数据。因为我们希望对前端进行更改,所有内容都将包含在 catalog 目录中。如果您查看代码,您会发现 catalog/model/catalog/product.php。这是我们要进行第一个更改的地方。 ModelCatalogProduct 中有特价,但没有特价结束日期。您可以修改现有的 getProduct() 方法,也可以创建自己的方法。我将向您展示后者,而前者留给用户作为练习。
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(),您可以调用它来了解产品特价何时结束。让我们将此数据提供给 View 。为此,我们必须将它添加到 Controller 中。在 ControllerProductProduct 中查找“特殊”变量的设置位置。
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;
}
...
最后一个任务是在产品 View 中实现您的计时器。这将位于类似 catalog/view/theme/default/template/product/product.tpl 的地方(如果您有自己的主题,请将 default 替换为 {你的主题)。有很多不同的 jQuery 倒数计时器解决方案,选择你的 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 } ?>
关于php - 试图在 opencart 中以特价添加 jquery 倒数计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7759607/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
当谈到运行时自省(introspection)和动态代码生成时,我认为ruby没有任何竞争对手,可能除了一些lisp方言。前几天,我正在做一些代码练习来探索ruby的动态功能,我开始想知道如何向现有对象添加方法。以下是我能想到的3种方法:obj=Object.new#addamethoddirectlydefobj.new_method...end#addamethodindirectlywiththesingletonclassclass这只是冰山一角,因为我还没有探索instance_eval、module_eval和define_method的各种组合。是否有在线/离线资
我注意到类定义,如果我打开classMyClass,并在不覆盖的情况下添加一些东西我仍然得到了之前定义的原始方法。添加的新语句扩充了现有语句。但是对于方法定义,我仍然想要与类定义相同的行为,但是当我打开defmy_method时似乎,def中的现有语句和end被覆盖了,我需要重写一遍。那么有什么方法可以使方法定义的行为与定义相同,类似于super,但不一定是子类? 最佳答案 我想您正在寻找alias_method:classAalias_method:old_func,:funcdeffuncold_func#similartoca
我有带有Logo图像的公司模型has_attached_file:logo我用他们的Logo创建了许多公司。现在,我需要添加新样式has_attached_file:logo,:styles=>{:small=>"30x15>",:medium=>"155x85>"}我是否应该重新上传所有旧数据以重新生成新样式?我不这么认为……或者有什么rake任务可以重新生成样式吗? 最佳答案 参见Thumbnail-Generation.如果rake任务不适合你,你应该能够在控制台中使用一个片段来调用重新处理!关于相关公司
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
我正在开发一个创建网络博客的RubyonRails项目。我希望将一个名为featured的boolean数据库字段添加到Post模型中。该字段应该可以通过我添加的事件管理界面进行编辑。我使用了以下代码,但我什至没有在网站上显示另一列。$railsgeneratemigrationaddFeaturedfeatured:boolean$rakedb:migrate我是RubyonRails的新手,非常感谢任何帮助。我的index.html.erb文件中的相关代码(views):FeaturedPost架构.rb:ActiveRecord::Schema.define(:version=>
假设我有一个这样的单例类:classSettingsincludeSingletondeftimeout#lazy-loadtimeoutfromconfigfile,orwhateverendend现在,如果我想知道使用什么超时,我需要编写如下内容:Settings.instance.timeout但我宁愿将其缩短为Settings.timeout使这项工作有效的一个明显方法是将设置的实现修改为:classSettingsincludeSingletondefself.timeoutinstance.timeoutenddeftimeout#lazy-loadtimeoutfromc