我正在使用 Opencart 2.0,我正在尝试让数量字段从类别页面和产品页面中工作。我之前在 1.5 版中设法做到了这一点,但此后代码发生了很大变化。对于 Opencart V 1.5,我使用了 Siven Sadiyan 提供的解决方案(http://siven76.com/2013/04/29/opencart-add-a-quantity-box-on-product-list-pages/) 谁的解决方案效果很好,只需要对 common.js 和 category.tpl 进行调整,我也能够将其应用于各种其他页面,例如搜索结果和模块。由于代码和条款发生了变化,我至今无法修改它以适应 Opencart 版本 2.0+。我已经尝试了几个扩展,但目前似乎没有什么可行的解决方案,除了硬编码和手动,到目前为止它对我来说并不顺利!我所寻找的只是功能,我不担心布局。
自从解决之前版本的 Opencart 以来,common.js 文件发生了变化,我知道它涉及以下代码(ps,从下面的代码中删除了滚动到顶部,但仅与原始代码更改了一行):
// Cart add remove functions
var cart = {
'add': function(product_id, quantity) {
jQuery.ajax({
url: 'index.php?option=com_mijoshop&route=checkout/cart/add&format=raw&tmpl=component',
type: 'post',
data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
dataType: 'json',
beforeSend: function() {
jQuery('#cart > button').button('loading');
},
success: function(json) {
jQuery('.alert, .text-danger').remove();
jQuery('#cart > button').button('reset');
if (json['redirect']) {
location = json['redirect'];
}
if (json['success']) {
jQuery('#content_oc').parent().before('<div class="shopnotification"><i class="fa fa-check-circle"></i> ' + json['success'] + '<button type="button" class="close" data-dismiss="alert">×</button></div>');
jQuery('#cart-total,#cart > a > span').html(json['total']);
jQuery('.shopnotification').fadeIn(1000).delay(3000).fadeOut(1500);
jQuery('#cart > ul,#module_cart > ul').load('index.php?option=com_mijoshop&route=common/cart/info&format=raw&tmpl=component ul li');
}
}
});
},
第二个文件是 category.tpl 代码(我假设成功更改后可以在其他区域进行更改):
<div class="button-group">
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>
<button type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-heart"></i></button>
<button type="button" data-toggle="tooltip" title="<?php echo $button_compare; ?>" onclick="compare.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-exchange"></i></button>
</div>
任何对此有解决方案的人将不胜感激!如果我自己运气好的话,我会回帖,但是在长时间的头抓伤之后,我的咖啡量很低!