在OpenCart中,我们如何实时更新数据
In OpenCart, how can we update the data in real time
好吧,我是OpenCart的新手。最近开始在Opencart文件系统中处理代码。我的目标是在页眉上显示cart-div,以显示在其他部分,如公共右侧或页脚。因此,在看了header.php和header.tpl之后,我做了一些更改。我在页脚.php上写了-
$data['cart'] = $this->load->controller('common/cart');
在footer.tpl上,我只是简单地回应了$cart。
但结果并不是我想要的。看看一些屏幕截图-
http://postimg.org/image/7v77iswgz/
http://postimg.org/image/thi05wgfj/
所以我的问题是,我必须做什么才能在不刷新页面的情况下更新总价。如果你能额外提供任何链接,我就可以从中学习用代码自定义opencart,那就太好了。
请检查common.js文件并修改var cart
以在页脚中添加数据。
var cart = {
'add': function(product_id, quantity) {
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
success: function(json) {
$('.alert, .text-danger').remove();
$('#cart > button').button('reset');
if (json['redirect']) {
location = json['redirect'];
}
if (json['success']) {
$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '<button type="button" class="close" data-dismiss="alert">×</button></div>');
$('#cart-total').html(json['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
}
});
},
'update': function(key, quantity) {
$.ajax({
url: 'index.php?route=checkout/cart/edit',
type: 'post',
data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
success: function(json) {
$('#cart > button').button('reset');
$('#cart-total').html(json['total']);
//add your footer button here
if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
location = 'index.php?route=checkout/cart';
} else {
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
}
});
},
'remove': function(key) {
$.ajax({
url: 'index.php?route=checkout/cart/remove',
type: 'post',
data: 'key=' + key,
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
success: function(json) {
$('#cart > button').button('reset');
$('#cart-total').html(json['total']);
//Add your footer button here
if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
location = 'index.php?route=checkout/cart';
} else {
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
}
});
}
}
相关文章:
- 标记的实时更新,无需加载页面谷歌地图API V3
- 更新数据,而不是用javascript和jquery将其添加到我的表中
- JQGrid使用服务器编辑后的更新数据刷新数据
- 使用Ajax调用在服务器上实时更新页面
- 实时更新,无需刷新页面
- 使用odata 4的jaydata 1.5和保存/更新数据时的错误
- Dojo dGrid/dStore实时更新
- 使用引导时间选取器时,没有更新数据ng模型值
- AngularJS中超时后没有更新数据
- jQuery动态更新数据键和值
- 使用 AJAX 从数据库中实时获取数据
- 在简单的可重用 D3 图表中更新数据
- Node/Express 无法正确更新数据模型
- 如何在页面上进行实时更新
- 从JSON实时更新
- 在OpenCart中,我们如何实时更新数据
- 在react组件中使用ajax获取实时更新的数据
- 在本地主机上实时更新数据,但不在实时服务器上更新(Node js + MongoDB)
- 如何使用实时(SignalR)更新数据
- 我可以'无法实时更新数据