Jump to content

Edit History

lvlehdi

lvlehdi

On 1/18/2017 at 2:36 PM, Embalim said:

You already have the script for 1 quantity and then you duplicate for 10, 20, 25, 50 (as you want)

thx man, that was awesome

how can i do it for 0.5

i'm using prestashop 1.6.1.18

i tried this but it didn't work

 

product.tpl

<div class="product_attributes clearfix">
						<!-- quantity wanted -->
						{if !$PS_CATALOG_MODE}

						{assign cat16 [['id_category' => 16]]}
						{assign cat17 [['id_category' => 17]]}
						
						{if Product::idIsOnCategoryId($smarty.get.id_product, $cat16)}
						<p id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
						<label for="quantity_wanted">{l s='Quantity'}</label>
						<input type="text" min="1" name="qty" id="quantity_wanted" class="text" disabled="disabled" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}{/if}" />
                        <a href="#" data-field-qty="qty" class="btn btn-default button-minus product_quantity_down_1">
                        	<span><i class="icon-minus"></i></span>
                        </a>
                        <a href="#" data-field-qty="qty" class="btn btn-default button-minus product_quantity_up_1">
                         	<span><i class="icon-plus"></i></span>
							</a>
						</p>
											
						{elseif Product::idIsOnCategoryId($smarty.get.id_product, $cat17)}
						<p id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
						<label for="quantity_wanted">{l s='Quantity'}</label>
						<input type="text" min="2" name="qty" id="quantity_wanted" class="text" disabled="disabled" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product->minimal_quantity > 2}{$product->minimal_quantity}{else}2{/if}{/if}"  />
                        <a href="#" data-field-qty="qty" class="btn btn-default button-minus product_quantity_down_2">
                        	<span><i class="icon-minus"></i></span>
                        </a>
                        <a href="#" data-field-qty="qty" class="btn btn-default button-minus product_quantity_up_2">
                         	<span><i class="icon-plus"></i></span>
							</a>
						</p>

						{else}
						<p id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
							<label for="quantity_wanted">{l s='Quantity'}</label>
							<input type="number" min="1" name="qty" id="quantity_wanted" disabled="disabled" class="text" value="{if isset($quantityBackup)}{$quantityBackup|floatval}{else}{if $product->minimal_quantity > 0.5}{$product->minimal_quantity}{else}0.5{/if}{/if}" />
							<a href="#" data-field-qty="qty" class="btn btn-default button-minus product_quantity_down_0.5">
								<span><i class="icon-minus"></i></span>
							</a>
							<a href="#" data-field-qty="qty" class="btn btn-default button-plus product_quantity_up_0.5">
								<span><i class="icon-plus"></i></span>
							</a>
							<span class="clearfix"></span>
						</p>	

						{/if}
						{/if}
						<!-- minimal quantity wanted -->
						<p id="minimal_quantity_wanted_p"{if $product->minimal_quantity <= 1 || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
							{l s='The minimum purchase order quantity for the product is'} <b id="minimal_quantity_label">{$product->minimal_quantity}</b>
						</p>

1 and 2 work fine but 0.5 nope (i tried it with min="0.5" too)

 

product.js

// The button to increment the product value
$(document).on('click', '.product_quantity_up_1', 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();
});
 // The button to decrement the product value
$(document).on('click', '.product_quantity_down_1', function(e){
        e.preventDefault();
        fieldName = $(this).data('field-qty');
        var currentVal = parseInt($('input[name='+fieldName+']').val());
        if (!isNaN(currentVal) && currentVal > 1 && currentVal > 1)
                $('input[name='+fieldName+']').val(currentVal - 1).trigger('keyup');
        else
                $('input[name='+fieldName+']').val(1);

        $('#quantity_wanted').change();    
});

// The button to increment the product value
$(document).on('click', '.product_quantity_up_2', 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');
        else
                $('input[name='+fieldName+']').val(quantityAvailableT);

        $('#quantity_wanted').change();
});
 // The button to decrement the product value
$(document).on('click', '.product_quantity_down_2', function(e){
        e.preventDefault();
        fieldName = $(this).data('field-qty');
        var currentVal = parseInt($('input[name='+fieldName+']').val());
        if (!isNaN(currentVal) && currentVal > 1 && currentVal > 2)
                $('input[name='+fieldName+']').val(currentVal - 2).trigger('keyup');
        else
                $('input[name='+fieldName+']').val(2);

        $('#quantity_wanted').change();    
});

// The button to increment the product value
$(document).on('click', '.product_quantity_up_0.5', function(e){
        e.preventDefault();
        fieldName = $(this).data('field-qty');
        var currentVal = parseFloat($('input[name='+fieldName+']').val());
        if (!allowBuyWhenOutOfStock && quantityAvailable > 0)
                quantityAvailableT = quantityAvailable;
        else
                quantityAvailableT = 100000000;
        if (!isNaN(currentVal) && currentVal < quantityAvailableT)
                $('input[name='+fieldName+']').val(currentVal + 0.5).trigger('keyup');
        else
                $('input[name='+fieldName+']').val(quantityAvailableT);

        $('#quantity_wanted').change();
});
 // The button to decrement the product value
$(document).on('click', '.product_quantity_down_0.5', function(e){
        e.preventDefault();
        fieldName = $(this).data('field-qty');
        var currentVal = parseFloat($('input[name='+fieldName+']').val());
        if (!isNaN(currentVal) && currentVal > 1 && currentVal > 0.5)
                $('input[name='+fieldName+']').val(currentVal - 0.5).trigger('keyup');
        else
                $('input[name='+fieldName+']').val(0.5);

        $('#quantity_wanted').change();    
});


if (typeof minimalQuantity !== 'undefined' && minimalQuantity)
{
	checkMinimalQuantity();
	$(document).on('keyup', 'input[name=qty]', function(e){
		checkMinimalQuantity(minimalQuantity);
	});
}

 

I appreciate any help

lvlehdi

lvlehdi

On 1/18/2017 at 2:36 PM, Embalim said:

You already have the script for 1 quantity and then you duplicate for 10, 20, 25, 50 (as you want)

thx man, that was awesome

how can i do it for 0.5

i'm using prestashop 1.6.1.18

i tried this but it didn't work

 

product.tpl

<div class="product_attributes clearfix">
						<!-- quantity wanted -->
						{if !$PS_CATALOG_MODE}

						{assign cat16 [['id_category' => 16]]}
						{assign cat17 [['id_category' => 17]]}
						
						{if Product::idIsOnCategoryId($smarty.get.id_product, $cat16)}
						<p id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
						<label for="quantity_wanted">{l s='Quantity'}</label>
						<input type="text" min="1" name="qty" id="quantity_wanted" class="text" disabled="disabled" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}{/if}" />
                        <a href="#" data-field-qty="qty" class="btn btn-default button-minus product_quantity_down_1">
                        	<span><i class="icon-minus"></i></span>
                        </a>
                        <a href="#" data-field-qty="qty" class="btn btn-default button-minus product_quantity_up_1">
                         	<span><i class="icon-plus"></i></span>
							</a>
						</p>
											
						{elseif Product::idIsOnCategoryId($smarty.get.id_product, $cat17)}
						<p id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
						<label for="quantity_wanted">{l s='Quantity'}</label>
						<input type="text" min="2" name="qty" id="quantity_wanted" class="text" disabled="disabled" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product->minimal_quantity > 2}{$product->minimal_quantity}{else}2{/if}{/if}"  />
                        <a href="#" data-field-qty="qty" class="btn btn-default button-minus product_quantity_down_2">
                        	<span><i class="icon-minus"></i></span>
                        </a>
                        <a href="#" data-field-qty="qty" class="btn btn-default button-minus product_quantity_up_2">
                         	<span><i class="icon-plus"></i></span>
							</a>
						</p>

						{else}
						<p id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity <= 0) || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
							<label for="quantity_wanted">{l s='Quantity'}</label>
							<input type="number" min="1" name="qty" id="quantity_wanted" disabled="disabled" class="text" value="{if isset($quantityBackup)}{$quantityBackup|floatval}{else}{if $product->minimal_quantity > 0.5}{$product->minimal_quantity}{else}0.5{/if}{/if}" />
							<a href="#" data-field-qty="qty" class="btn btn-default button-minus product_quantity_down_0.5">
								<span><i class="icon-minus"></i></span>
							</a>
							<a href="#" data-field-qty="qty" class="btn btn-default button-plus product_quantity_up_0.5">
								<span><i class="icon-plus"></i></span>
							</a>
							<span class="clearfix"></span>
						</p>	

						{/if}
						{/if}
						<!-- minimal quantity wanted -->
						<p id="minimal_quantity_wanted_p"{if $product->minimal_quantity <= 1 || !$product->available_for_order || $PS_CATALOG_MODE} style="display: none;"{/if}>
							{l s='The minimum purchase order quantity for the product is'} <b id="minimal_quantity_label">{$product->minimal_quantity}</b>
						</p>

1 and 2 work fine but 0.5 nope

 

product.js

// The button to increment the product value
$(document).on('click', '.product_quantity_up_1', 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();
});
 // The button to decrement the product value
$(document).on('click', '.product_quantity_down_1', function(e){
        e.preventDefault();
        fieldName = $(this).data('field-qty');
        var currentVal = parseInt($('input[name='+fieldName+']').val());
        if (!isNaN(currentVal) && currentVal > 1 && currentVal > 1)
                $('input[name='+fieldName+']').val(currentVal - 1).trigger('keyup');
        else
                $('input[name='+fieldName+']').val(1);

        $('#quantity_wanted').change();    
});

// The button to increment the product value
$(document).on('click', '.product_quantity_up_2', 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');
        else
                $('input[name='+fieldName+']').val(quantityAvailableT);

        $('#quantity_wanted').change();
});
 // The button to decrement the product value
$(document).on('click', '.product_quantity_down_2', function(e){
        e.preventDefault();
        fieldName = $(this).data('field-qty');
        var currentVal = parseInt($('input[name='+fieldName+']').val());
        if (!isNaN(currentVal) && currentVal > 1 && currentVal > 2)
                $('input[name='+fieldName+']').val(currentVal - 2).trigger('keyup');
        else
                $('input[name='+fieldName+']').val(2);

        $('#quantity_wanted').change();    
});

// The button to increment the product value
$(document).on('click', '.product_quantity_up_0.5', function(e){
        e.preventDefault();
        fieldName = $(this).data('field-qty');
        var currentVal = parseFloat($('input[name='+fieldName+']').val());
        if (!allowBuyWhenOutOfStock && quantityAvailable > 0)
                quantityAvailableT = quantityAvailable;
        else
                quantityAvailableT = 100000000;
        if (!isNaN(currentVal) && currentVal < quantityAvailableT)
                $('input[name='+fieldName+']').val(currentVal + 0.5).trigger('keyup');
        else
                $('input[name='+fieldName+']').val(quantityAvailableT);

        $('#quantity_wanted').change();
});
 // The button to decrement the product value
$(document).on('click', '.product_quantity_down_0.5', function(e){
        e.preventDefault();
        fieldName = $(this).data('field-qty');
        var currentVal = parseFloat($('input[name='+fieldName+']').val());
        if (!isNaN(currentVal) && currentVal > 1 && currentVal > 0.5)
                $('input[name='+fieldName+']').val(currentVal - 0.5).trigger('keyup');
        else
                $('input[name='+fieldName+']').val(0.5);

        $('#quantity_wanted').change();    
});


if (typeof minimalQuantity !== 'undefined' && minimalQuantity)
{
	checkMinimalQuantity();
	$(document).on('keyup', 'input[name=qty]', function(e){
		checkMinimalQuantity(minimalQuantity);
	});
}

 

I appreciate any help

×
×
  • Create New...