Jump to content

Select combination on product page by id combination in JS 1.6


hakeryk2

Recommended Posts

Hello,

Is there any possibility to change selected combination to a different one by passing only id of this combination?
There is a variable combinationsFromController which contains basically all informations needed to change selected value (attributes, attributes group) but this is just to overwhelming to determine if product has only color change, input radios, selects and what if there is more than 1 groups of attributes.

This should be in Presta but maybe I can't find it.

Otherwise - maybe someone will create this function :)

Edit: Ok, I made it by myself. Now changing this will be much easier :) 
If I helped please submit Thanks!


 

function selectAttributeByCombinationId(combination_id)
{
	if (typeof combinationsFromController[combination_id] == 'undefined')
		return false;

	var c = combinationsFromController[combination_id];
	var i = 0;
	c.attribute_select = [];

	// prepare easier in use temp array for each selector with group assigned
	$.each(c.attributes_values, function(k){
		c.attribute_select[k] = c.attributes[i];
		i++;
	});

	$.each(c.attribute_select, function(k,v){
		$('#color_' + v).addClass('selected').parent().addClass('selected');
		$('input:radio[value=' + v + ']').prop('checked', true);
		$('input[type=hidden][name=group_' + k + ']').val(v);
		$('select[name=group_' + k + ']').val(v);
	});
	findCombination();
	getProductAttribute();
}



 

Edited by hakeryk2
found a solution (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...