redmar Posted May 17, 2016 Share Posted May 17, 2016 (edited) Goodmorning everybody, Thanks for reading my post. We sell some of our products with an Minimal Order Quantity (MOQ). For example, item X has a MOQ of 12. So when somebody wants to buy item X, we 1) need Prestashop to show at default the MOQ quantity (i.e. 12 in this example) and have the minus sign greyed out (because quantities < 12 cannot be ordered). and we also 2) need Prestashop to restrict the quantity that can be ordered to 12 or quantities that follow the formula: quantity = 12 + n*12 (n being integers of 0 or higher)...OR put in a different way: higher amounts that are only within the mathematic table of 12 (...24, 36, 48...etc.). Does anyone here know of such a functionality / add-on or have pointers that would get us nearer to a solution for our problem? Many thanks in advance for any help, Best regards, Redmar Edited May 17, 2016 by redmar (see edit history) Link to comment Share on other sites More sharing options...
premiumpresta Posted May 17, 2016 Share Posted May 17, 2016 I will assume that you use the version 1.6.1.5 with the default theme. If I understand correctly, you want to always calculate the quantity as n*MOQ (where n is altered by - and + buttons). Start by showing the MOQ under product attributes, edit file shopping-cart-product-line.tpl and under line 34 add: <strong class="minimal-quantity" data-value="{$product.minimal_quantity}">{l s='MOQ'}: {$product.minimal_quantity} {l s='pcs'}</strong> You may also want to make the quantity input so the user can't type any value. At line 96 add attribute readonly. To change the quantity adjustment behavior, edit the file cart-summary.js. Change line 581 into: qty = parseInt($('#product_' + id + ' .minimal-quantity').data('value')); Change lines 684, 685 into: qty = parseInt($('#product_' + id + ' .minimal-quantity').data('value')); newVal -= qty; To disable the - button when the quantity equals MOQ, under line 877 add: if ($('input[name=quantity_' + key_for_blockcart_nocustom + ']').val() <= $('#product_' + key_for_blockcart_nocustom + ' .minimal-quantity').data('value')) { $('#cart_quantity_down_' + key_for_blockcart_nocustom).addClass('disabled'); } else { $('#cart_quantity_down_' + key_for_blockcart_nocustom).removeClass('disabled'); } Link to comment Share on other sites More sharing options...
RiesjardVV Posted May 18, 2016 Share Posted May 18, 2016 Dear PremiumPresta. we implemented the code provided by you, after saving cart-summary.js and refreshing testing starts ;-) After adding product to cart from product page, the quantity is 6 pieces as defined on product level. I added console trace to both up-and downQuantity. When i press +, i get error message popup telling me there is no quantity and in the console i see the log value NaN. console.log(parseInt($('#product_' + id + ' .minimal-quantity').data('value'))); Best regards, Richard Link to comment Share on other sites More sharing options...
premiumpresta Posted May 18, 2016 Share Posted May 18, 2016 The first edit in shopping-cart-product-line.tpl is essential for the code in cart-summary.js because it adds data-value of minimal quantity. So make sure you haven't missed that. Also make sure you clear the smarty cache after editing the files. Link to comment Share on other sites More sharing options...
RiesjardVV Posted May 18, 2016 Share Posted May 18, 2016 (edited) Okay, works now ;-) Only sometimes i can not find out in which specific situation, i get error message popup only in case of pressing + button. ->> TECHNICAL ERROR: unable to save update quantity Details: Error thrown: [object Object] Text status: error Can this same code change be applied to to + and - sign on the product detail page? Edited May 18, 2016 by RiesjardVV (see edit history) Link to comment Share on other sites More sharing options...
premiumpresta Posted May 27, 2016 Share Posted May 27, 2016 For the product page is a little bit trickier, but it can be adapted on the same principles. If you provide your link I can look into why you get that error when pressing + button. Link to comment Share on other sites More sharing options...
RiesjardVV Posted June 1, 2016 Share Posted June 1, 2016 Dear PremiumPresta, error does not occur anymore, i think it was a cache related issue. Can u giver me an ocerview of code changes in order to makes +/- sign also work on product page? Link to comment Share on other sites More sharing options...
premiumpresta Posted June 2, 2016 Share Posted June 2, 2016 (edited) Here's how you can get the same behavior on the product page. Edit file product.js from your theme. Under line 215 add: if (typeof minimalQuantity !== 'number' || minimalQuantity < 1) { minimalQuantity = 1; } checkMinimalQuantity(minimalQuantity); Replace line 358 with: $('input[name='+fieldName+']').val(currentVal + minimalQuantity).trigger('keyup'); Replace line 370 with: $('input[name='+fieldName+']').val(currentVal - minimalQuantity).trigger('keyup'); At the end of function checkMinimalQuantity() add: if ($('#quantity_wanted').val() <= minimal_quantity) { $('#quantity_wanted_p .product_quantity_down').addClass('disabled'); } else { $('#quantity_wanted_p .product_quantity_down').removeClass('disabled'); } Edited June 2, 2016 by premiumpresta (see edit history) Link to comment Share on other sites More sharing options...
RiesjardVV Posted June 3, 2016 Share Posted June 3, 2016 Thks works like a charm, Only open point is disabling the qnty field so customer can only use + and -. Grtz RIchard Link to comment Share on other sites More sharing options...
premiumpresta Posted June 4, 2016 Share Posted June 4, 2016 You can make the quantity field readonly like you did on shopping-cart-product-line.tpl. This thread can be marked as solved now Link to comment Share on other sites More sharing options...
RiesjardVV Posted June 4, 2016 Share Posted June 4, 2016 Thks for support, i will ask Redmar to close the thread ;-) Link to comment Share on other sites More sharing options...
redmar Posted June 6, 2016 Author Share Posted June 6, 2016 Dear PremiumPresta, On behalf of Richard and me a big thank you for your detailed help!!! Have a great day, with very kind regards, redmar 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