Jump to content

Cart-summary.js : id


Serial

Recommended Posts

Hi,

 

In cart-summary.js, in function downQuantity(id, qty) for example, there is :

$('input[name=quantity_' + id + ']')

I'm creating a new function in this .js file : function CalculCoupe()

 

I want this "id". When I do something in my function with "id" for example :

document.getElementsByName("pieces_"+id)[0].value = 9;

OR

document.getElementsByName('input[name=pieces_' + id + ']')[0].value = 9;

That's not work.

 

But when i type my id in hard-coded :

document.getElementsByName("pieces_22_2_0_5")[0].value = 9;

That's work. How can I have this value in "id" ?

Link to comment
Share on other sites

hi, havo you tried to check what value exporting "id"? also "pieces_..." is input? if yes, try  $('input[name=pieces_' + id + ]').val(9);

 

$('input[name=pieces_' + id + ]').val(9); not work

Yes, its an input.

 

I think the problem is in "id". I'm sure it's the value that I want but I found this variable in an other function of this file. See this function (I comment to show you what I want) :

function downQuantity(o, id, qty)
{
	var val = $('input[name=quantity_' + id + ']').val(); /* The id variable that I need */
	var newVal = val;
	if(typeof(qty) == 'undefined' || !qty)
	{
		qty = 1;
		newVal = val - 1;
	}
	else if (qty < 0)
		qty = -qty;

	var icp = ppCart.getIcp(o);
	var icpSelector = ppCart.getIcpSelector(icp);
	var customizationId = 0;
	var productId = 0;
	var productAttributeId = 0;
	var id_address_delivery = 0;
	var ids = 0;

	ids = id.split('_');
	productId = parseInt(ids[0]);
	if (typeof(ids[1]) !== 'undefined')
		productAttributeId = parseInt(ids[1]);
	if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom')
		customizationId = parseInt(ids[2]);
	if (typeof(ids[3]) !== 'undefined')
		id_address_delivery = parseInt(ids[3]);

	if (newVal > 0 || $('#product_' + id + '_gift').length) /* The id variable that I need */
	{
		$.ajax({
			type: 'POST',
			headers: { "cache-control": "no-cache" },
			url: baseUri + '?rand=' + new Date().getTime(),
			async: true,
			cache: false,
			dataType: 'json',
			data: 'controller=cart'
				+ '&ajax=true'
				+ '&add=true'
				+ '&getproductprice=true'
				+ '&summary=true'
				+ '&id_product='+productId
				+ '&ipa='+productAttributeId
				+ '&id_address_delivery='+id_address_delivery
				+ '&op=down'
				+ ((customizationId !== 0) ? '&id_customization='+customizationId : '')
				+ '&qty='+qty
				+ '&icp='+icp
				+ '&token='+static_token
				+ '&allow_refresh=1',
			success: function(jsonData)
			{
				if (jsonData.hasError)
				{
					var errors = '';
					for(var error in jsonData.errors)
						//IE6 bug fix
						if(error !== 'indexOf')
							errors += $('<div />').html(jsonData.errors[error]).text() + "\n";
					if (!!$.prototype.fancybox)
						$.fancybox.open([
							{
								type: 'inline',
								autoScale: true,
								minHeight: 30,
								content: '<p class="fancybox-error">' + errors + '</p>'
							}],
							{
								padding: 0
							});
					else
						alert(errors);
					$('input'+ icpSelector +'[name=quantity_'+ id +']').val($('input'+ icpSelector +'[name=quantity_'+ id +'_hidden]').val()); /* The id variable that I need */
				}
				else
				{
					if (jsonData.refresh)
						window.location.href = window.location.href;
					updateCartSummary(jsonData.summary);

					if (window.ajaxCart !== undefined)
						ajaxCart.updateCart(jsonData);
					if (customizationId !== 0)
						updateCustomizedDatas(jsonData.customizedDatas);
					updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART);
					updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA);

					if (newVal == 0)
						$('#product_' + id).hide(); /* The id variable that I need */

					if (typeof(getCarrierListAndUpdate) !== 'undefined')
						getCarrierListAndUpdate();
					if (typeof(updatePaymentMethodsDisplay) !== 'undefined')
						updatePaymentMethodsDisplay();
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				if (textStatus !== 'abort')
					alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
			}
		});

	}
	else
	{
		deleteProductFromSummary(o, id);
	}
}
Edited by Serial (see edit history)
Link to comment
Share on other sites

In shopping-cart-product-line.tpl (my input "pieces_ + id") :

{if $product.id_category_default != 99}
	<td class="coupe_tissus" data-title="{l s='Coupe'}">
		<input id="coupe_select" type="checkbox" value="no" name="checkbox_coupe">Coupe</input>
		<div id="param_coupe" style="display:none">
			<div class="coupe-content"><input id="nb_pieces" type="text" value="{$product.cart_quantity}" name="pieces_{$product.id_product}_{$product.id_product_attribute}_{if $quantityDisplayed > 0}nocustom{else}0{/if}_{$product.id_address_delivery|intval}" style="width:40px;"/> pièce(s) x <input id="nb_metres" type="text" name="metres_{$product.id_product}_{$product.id_product_attribute}_{if $quantityDisplayed > 0}nocustom{else}0{/if}_{$product.id_address_delivery|intval}" style="width:40px;" disabled /> m</div>
			<input id="bouton_calculer" type="button" value="Calculer" />
		</div>
	</td>
{else}
	<td class="coupe_tissus" data-title="{l s='Coupe'}">
		<div class="nocoupe"></div>
	</td>
{/if}

In my cart.summary.js (I test to do this to get "id") :

$('#bouton_calculer').on('click', function(){
		CalculCoupe($(this).attr('id')); /* I found this in other examples in the file */
});

And my function CalculCoupe in the .js :

function CalculCoupe(id)
{
	var nb_metres;
	var nb_pieces;
	var quantite;
	document.getElementsByName("pieces_" + id)[0].value = 9; /* Not work too with : $('input[name=pieces_' + id + ']').val(9); */
}

Not work :(

Edited by Serial (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...