[英]How to add quantity box in category pages opencart 2.2
Im working on a 2.2 version of OpenChart (OC), and I'm new to OC, and I want to add quantity box in category pages and at featured products parts.我正在开发 2.2 版本的 OpenChart (OC),我是 OC 的新手,我想在类别页面和特色产品部分添加数量框。
So I was trying to copy this code from theme/default/template/product/product.tpl
, because I want the same result which OC have applied in product page.所以我试图从theme/default/template/product/product.tpl
复制这段代码,因为我想要 OC 在产品页面中应用的相同结果。
<label class="control-label" for="input-quantity"><?php echo $entry_qty; ?></label>
<input type="text" name="quantity" value="<?php echo $minimum; ?>" size="2" id="input-quantity" class="form-control" />
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />
and was trying to paste it in theme/default/template/product/category.tpl
page below price but got an error Undefined variable
.并试图将其粘贴到低于价格的theme/default/template/product/category.tpl
页面中,但出现错误Undefined variable
。
From R&D I got to know that I have to update it in catalog/controller/category.tpl
page as well.从 R&D 我知道我也必须在catalog/controller/category.tpl
页面中更新它。 I don't know what to do.我不知道该怎么办。
Please help me.请帮帮我。 Thanks alot in advance.非常感谢提前。
You will replace the following changes in您将替换以下更改
category.tpl类别.tpl
Replace code with following用以下代码替换代码
<div class="image"><a href="<?php echo $product['href']; ?>" id="location-<?php echo $product['product_id']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></a></div>
add following code before 'div class="button-group">'在 'div class="button-group">' 之前添加以下代码
<div class="form-group">
<label class="control-label" for="input-quantity">Qty</label>
<input type="text" name="quantity" value="<?php echo $product['minimum']; ?>" size="2" id="input-quantity-<?php echo $product['product_id']; ?>" class="form-control" />
</div>
change following code更改以下代码
<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>
to following跟随
<button type="button" onclick="addTocart('<?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>
Add Javascript before之前添加Javascript
<script type="text/javascript">
function addTocart(product_id){
var product_id = product_id;
var qty = $('#input-quantity-'+product_id).val();
var location = $('#location-'+product_id).attr('href');
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: 'product_id='+product_id+'&quantity='+qty,
dataType: 'json',
beforeSend: function() {
$('#button-cart').button('loading');
},
complete: function() {
$('#button-cart').button('reset');
},
success: function(json) {
$('.alert, .text-danger').remove();
$('.form-group').removeClass('has-error');
if (json['error']) {
if (json['error']['option']) {
window.location = location;
}
if (json['error']['recurring']) {
window.location = location;
}
// Highlight any found errors
$('.text-danger').parent().addClass('has-error');
}
if (json['success']) {
$('.breadcrumb').after('<div class="alert alert-success">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">×</button></div>');
$('#cart > button').html('<i class="fa fa-shopping-cart"></i> ' + json['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
</script>
Cheers干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.