Jump to content

Minimum quantity


zhihsam

Recommended Posts

Hello!

 

I need to add to products minimum quantity BUT for example if minimum quantity is equal to 50, users shouldn't be allowed to buy 51 product, they should be able to buy only 50, 100, 150 etc.

 

And it's should be made without using product pack.

 

Thank you.

Link to comment
Share on other sites

  • 1 month later...

In the root_folder/themes/mytheme/product.tpl i added data attribute to quantity input:

 

<input type="text" data-quantity="{$product->minimal_quantity}" name="qty" id="quantity_wanted" class="text" value="1" size="2" maxlength="4">

 

data-quantity="{$product.minimal_quantity}" is what you actualy need.

 

When users click on "add to cart" button they invoke function in root_folder/themes/mytheme/js/modules/blockcart/ajax-cart.js file (if not exists you should copy original file from root_folder/modules/blockcart/ajax-cart.js to path given above).

Function is called overrideButtonsInThePage. I made some changes to parse data-quantity from input for multiplying it to minimal quantity

i.e.

....

overrideButtonsInThePage : function(){
    ...
    //for product page 'add' button...
    $('#add_to_cart input').unbind('click').click(function(){
      var input = $('#quantity_wanted'),                                                  // input
          quantity = input.val() * input.data('quantity');                              // parsing our quantity from data-attribute and multiplying by it
      ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, quantity, null);
      return false;
    })
    ...

 

Also you shoudn't forget to add similar code changes (i mean to add data-quantity attribute) to other parts of your shop (shopping-cart page, order page e.t.c)

 

After all changes done, when you set minimal quantity to your product (e.g. 50) users will be able to buy only 50 or 100 or 150 as it was needed.

  • Like 2
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...