Jump to content

how to pass minimal quantity to product list


ruisonika
 Share

Recommended Posts

hello guys,

I'm using prestashop 1.6, and i'm trying to goal this:
- in product list i created a add quantities buttons

<!------------------------ quantity wanted ---------------------------------------------->
            {if !$PS_CATALOG_MODE}
            <p class="quantity_wanted_p_"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: block;"{/if}>
            <!-- <label>{l s='Quantity'}</label> -->
                <a class="btn button-minus product_quantity_down decrement_qty" data-field-qty="{$product.minimal_quantity}">
                    <span><i class="icon-minus"></i></span>
                </a>
                <input type="number" min="1" name="qty" id="quantity_wanted_{$product.id_product|intval}" class="text inputqtyfield" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product.minimal_quantity > 1}{$product.minimal_quantity}{else}1{/if}{/if}" />
                <span class="minQty" style="display:none;">{$product.minimal_quantity}</span>
                <a class="btn button-plus product_quantity_up increment_qty">
                    <span><i class="icon-plus"></i></span>
                </a>
                <span class="clearfix"></span>
            </p>
            {/if}

- in global js file i created this to the + and - work

/////quantities in  default product list
jQuery(document).ready(function(){
    jQuery('.increment_qty').click(function() {
      var oldVal = jQuery(this).parent().find("input").val();
        if ( parseFloat(oldVal) >= 0 ) {
        var newVal = parseFloat(oldVal) + 1;
        jQuery(this).parent().find("input").val(newVal);
      }
      console.log(oldVal);
      console.log(newVal);
      console.log(minQty);
        
    });

    jQuery('.decrement_qty').click(function() {
      var oldVal = jQuery(this).parent().find("input").val();
      if ( parseFloat(oldVal) >= 1 ) {
        var newVal = parseFloat(oldVal) - 1;
        jQuery(this).parent().find("input").val(newVal);
      }
    });
  });

and all works well, but now i wanna increase or decrease with minimal quantity instead of 1, so if the product has 10 of minimal buy when the customer click on + button the result is 20, another click 30 and so on...but i cant get the minimal quantity in this file global.js, any ideias how to achive this?

Share this post


Link to post
Share on other sites

<!------------------------ quantity wanted ---------------------------------------------->
            {if !$PS_CATALOG_MODE}
            <p class="quantity_wanted_p_"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: block;"{/if}>
            <!-- <label>{l s='Quantity'}</label> -->
                <a class="btn button-minus product_quantity_down decrement_qty" data-field-qty="{$product.minimal_quantity}">
                    <span><i class="icon-minus"></i></span>
                </a>
              <!-- change the min  -->
                <input type="number" min="{$product.minimal_quantity}" name="qty" id="quantity_wanted_{$product.id_product|intval}" class="text inputqtyfield" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product.minimal_quantity > 1}{$product.minimal_quantity}{else}1{/if}{/if}" />
                <span class="minQty" style="display:none;">{$product.minimal_quantity}</span>
                <a class="btn button-plus product_quantity_up increment_qty">
                    <span><i class="icon-plus"></i></span>
                </a>
                <span class="clearfix"></span>
            </p>
            {/if}
////quantities in  default product list
jQuery(document).ready(function(){
    jQuery('.increment_qty').click(function() {

      var oldVal = jQuery(this).parent().find("input").val();
      var minQty = jQuery(this).parent().find("input").attr('min'); 
      minQty = (typeod minQty !== 'undefined' ) ? parseFloat(minQty) : 1;
        if ( parseFloat(oldVal) >= 0 ) {
        var newVal = parseFloat(oldVal) + minQty;
        jQuery(this).parent().find("input").val(newVal);
      }
      console.log(oldVal);
      console.log(newVal);
      console.log(minQty);
        
    });

    jQuery('.decrement_qty').click(function() {
      var minQty = jQuery(this).parent().find("input").attr('min'); 
      minQty = (typeod minQty !== 'undefined' ) ? parseFloat(minQty) : 1;
      var oldVal = jQuery(this).parent().find("input").val();
      if ( parseFloat(oldVal) >=  minQty ) {
        var newVal = parseFloat(oldVal) - minQty >= minQty ? parseFloat(oldVal) - minQty : minQty;
        jQuery(this).parent().find("input").val(newVal);
      }
    });
  });

something like that

  • Thanks 1

Share this post


Link to post
Share on other sites

2 hours ago, EvaF said:
<!------------------------ quantity wanted ---------------------------------------------->
            {if !$PS_CATALOG_MODE}
            <p class="quantity_wanted_p_"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: block;"{/if}>
            <!-- <label>{l s='Quantity'}</label> -->
                <a class="btn button-minus product_quantity_down decrement_qty" data-field-qty="{$product.minimal_quantity}">
                    <span><i class="icon-minus"></i></span>
                </a>
              <!-- change the min  -->
                <input type="number" min="{$product.minimal_quantity}" name="qty" id="quantity_wanted_{$product.id_product|intval}" class="text inputqtyfield" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product.minimal_quantity > 1}{$product.minimal_quantity}{else}1{/if}{/if}" />
                <span class="minQty" style="display:none;">{$product.minimal_quantity}</span>
                <a class="btn button-plus product_quantity_up increment_qty">
                    <span><i class="icon-plus"></i></span>
                </a>
                <span class="clearfix"></span>
            </p>
            {/if}
////quantities in  default product list
jQuery(document).ready(function(){
    jQuery('.increment_qty').click(function() {

      var oldVal = jQuery(this).parent().find("input").val();
      var minQty = jQuery(this).parent().find("input").attr('min'); 
      minQty = (typeod minQty !== 'undefined' ) ? parseFloat(minQty) : 1;
        if ( parseFloat(oldVal) >= 0 ) {
        var newVal = parseFloat(oldVal) + minQty;
        jQuery(this).parent().find("input").val(newVal);
      }
      console.log(oldVal);
      console.log(newVal);
      console.log(minQty);
        
    });

    jQuery('.decrement_qty').click(function() {
      var minQty = jQuery(this).parent().find("input").attr('min'); 
      minQty = (typeod minQty !== 'undefined' ) ? parseFloat(minQty) : 1;
      var oldVal = jQuery(this).parent().find("input").val();
      if ( parseFloat(oldVal) >=  minQty ) {
        var newVal = parseFloat(oldVal) - minQty >= minQty ? parseFloat(oldVal) - minQty : minQty;
        jQuery(this).parent().find("input").val(newVal);
      }
    });
  });

something like that

Thanks @EvaF with a small difference it works like i want, i will mark solved.
Thanks again.

By the way this were my changes.
product-list.tpl
<!------------------------ quantity wanted ---------------------------------------------->
            {if !$PS_CATALOG_MODE}
            <p class="quantity_wanted_p_"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: block;"{/if}>
            <!-- <label>{l s='Quantity'}</label> -->
                <a class="btn button-minus product_quantity_down decrement_qty" data-field-qty="{$product.minimal_quantity}">
                    <span><i class="icon-minus"></i></span>
                </a>
                <input type="number" min="{if $product.minimal_quantity > 0}{$product.minimal_quantity}{else}1{/if}" name="qty" id="quantity_wanted_{$product.id_product|intval}" class="text inputqtyfield" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product.minimal_quantity > 1}{$product.minimal_quantity}{else}1{/if}{/if}" />
      
                <a class="btn button-plus product_quantity_up increment_qty">
                    <span><i class="icon-plus"></i></span>
                </a>
                <span class="clearfix"></span>
            </p>
            {/if}

<!------------------------------------------------------------------------------------->

global.js
 

/////quantities in  default product list
jQuery(document).ready(function(){
    jQuery('.increment_qty').click(function() {
      var oldVal = jQuery(this).parent().find("input").val();
      var minQty = jQuery(this).parent().find("input").attr('min'); 
      
        if ( parseFloat(oldVal) > 0 ) {
        var newVal = parseFloat(oldVal) + parseFloat(minQty);
        jQuery(this).parent().find("input").val(newVal);
      }
      
    });

    jQuery('.decrement_qty').click(function() {
      var oldVal = jQuery(this).parent().find("input").val();
      var minQty = jQuery(this).parent().find("input").attr('min'); 
      if ( parseFloat(oldVal) >= 1 ) {
        var newVal = parseFloat(oldVal) - parseFloat(minQty);
        jQuery(this).parent().find("input").val(newVal);
      }
    });
  });

 

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More