Prestashop v1.6.1.13 default-bootstrap主题。
当我更改product.js
时// The button to increment the product value
$(document).on('click', '.product_quantity_up', function(e){
e.preventDefault();
fieldName = $(this).data('field-qty');
var currentVal = parseInt($('input[name='+fieldName+']').val());
if (!allowBuyWhenOutOfStock && quantityAvailable > 0)
quantityAvailableT = quantityAvailable;
else
quantityAvailableT = 100000000;
if (!isNaN(currentVal) && currentVal < quantityAvailableT)
$('input[name='+fieldName+']').val(currentVal + 1).trigger('keyup');
else
$('input[name='+fieldName+']').val(quantityAvailableT);
$('#quantity_wanted').change();
});
到此:
// The button to increment the product value
$(document).on('click', '.product_quantity_up', function(e){
e.preventDefault();
fieldName = $(this).data('field-qty');
var currentVal = parseInt($('input[name='+fieldName+']').val());
if (!allowBuyWhenOutOfStock && quantityAvailable > 0)
quantityAvailableT = quantityAvailable;
else
quantityAvailableT = 100000000;
if (!isNaN(currentVal) && currentVal < quantityAvailableT)
$('input[name='+fieldName+']').val(currentVal + 2).trigger('keyup'); //this line changed
else
$('input[name='+fieldName+']').val(quantityAvailableT);
$('#quantity_wanted').change();
});
每次按下增量按钮时,我都可以在输入中更改2个qauntity的值,但是当我输入代码minimalQuantity
并且代码看起来像:$('input[name='+fieldName+']').val(currentVal + minimalQuantity).trigger('keyup');
时这只是工作对于产品没有属性。如果产品具有属性,则这不起作用,对于没有属性的产品,似乎minimalQuantity
给出了正确的值,但对于具有属性值的产品,总是1.我如何修复它?
答案 0 :(得分:0)
在产品页面上,您有一个全局JS变量combinations
,它存储有关组合的所有信息。它被包含在DOM中,因此您可以在那里搜索它。
变量示例:
var combinations =
{
"31": {
"attributes_values": {
"1": "S",
"3": "Yellow"
},
"attributes": [
1,
16
],
"price": 0,
"specific_price": false,
"ecotax": 0,
"weight": 0,
"quantity": 300,
"reference": "",
"unit_impact": 0,
"minimal_quantity": "1",
"date_formatted": "",
"available_date": "",
"id_image": 16,
"list": "'1','16'"
},
...
}
因此,您需要在上面列表中的所选组合ID的对象中获取minimal_quantity
变量。
// The button to increment the product value
$(document).on('click', '.product_quantity_up', function(e){
e.preventDefault();
fieldName = $(this).data('field-qty');
var curCombinationId = $('#idCombination').val();
var minCombinationQty = minimalQuantity; // set default product minimal quantity
if (combinations != 'undefined') { // check if product has combinations
for (var combData in combinations) {
if (combData.idCombination == curCombinationId) {
minCombinationQty = parseInt(combData.minimal_quantity);
break;
}
}
}
var currentVal = parseInt($('input[name='+fieldName+']').val());
if (!allowBuyWhenOutOfStock && quantityAvailable > 0)
quantityAvailableT = quantityAvailable;
else
quantityAvailableT = 100000000;
if (!isNaN(currentVal) && currentVal < quantityAvailableT)
$('input[name='+fieldName+']').val(currentVal + minCombinationQty).trigger('keyup');
else
$('input[name='+fieldName+']').val(quantityAvailableT);
$('#quantity_wanted').change();
});