Jump to content

Shopping cart: restrict order qty / grey out minus sign


Recommended Posts

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

post-1226744-0-93094000-1463471181_thumb.jpg

Edited by redmar (see edit history)
Link to comment
Share on other sites

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

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

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 by RiesjardVV (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

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 by premiumpresta (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...