theDoris Posted April 27, 2017 Share Posted April 27, 2017 Prestashop v1.6.1.13 default-bootstrap theme. When I change in 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(); }); to this: // 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(); }); I'm able to change value in input for 2 qauntity up on every time when I push increment button, but when I put in code minimalQuantity and code in changed line looks like: $('input[name=+fieldName+]').val(currentVal + minimalQuantity).trigger('keyup'); this is work only for product witout attributes. If product have attributes this is didnt work, it seems like minimalQuantity for product without attributes give correct value but for product with attributes value is always 1. How I can fix it? Link to comment Share on other sites More sharing options...
theDoris Posted April 27, 2017 Author Share Posted April 27, 2017 When I use in product.js: console.log(combination) in source code I see correct value for minimal_quantity for this combination of attributes but still I dont know how I can use it for this product and regular product in product.js? So regular product use: minimalQuantity and product with attributes use minimal_quantity how I can use them in this code for correct display? Link to comment Share on other sites More sharing options...
DataKick Posted April 28, 2017 Share Posted April 28, 2017 (edited) When I use in product.js: console.log(combination) in source code I see correct value for minimal_quantity for this combination of attributes but still I dont know how I can use it for this product and regular product in product.js? So regular product use: minimalQuantity and product with attributes use minimal_quantity how I can use them in this code for correct display? Well, you first need to determine what combination is selected (if any) and then get its minimal_quantity value. Example code: function getCurrentCombination() { if (window.combinationsHashSet) { var choice = []; var radioInputs = parseInt($('#attributes .checked > input[type=radio]').length); if (radioInputs) radioInputs = '#attributes .checked > input[type=radio]'; else radioInputs = '#attributes input[type=radio]:checked'; $('#attributes select, #attributes input[type=hidden], ' + radioInputs).each(function() { choice.push(parseInt($(this).val())); }); var id = choice.join('-'); return window.combinationsHashSet[id]; } } function getMinimalQuantity() { var combination = getCurrentCombination(); return combination ? combination['minimal_quantity'] : window.minimalQuantity; } // ... $('input[name='+fieldName+']').val(currentVal + getMinimalQuantity()).trigger('keyup'); //this line changed Edited April 28, 2017 by DataKick (see edit history) 1 Link to comment Share on other sites More sharing options...
theDoris Posted April 28, 2017 Author Share Posted April 28, 2017 Thank you it is awesome! You are awesome! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now