Jump to content

Problème bouton radio fiche produit


SK3uD

Recommended Posts

Bonjour,

je suis sous Prestashop 1.6 et j'ai le template Warehouse. 

Je souhaite personnaliser mes boutons radio pour le choix des tailles. Seulement, je crois que je me suis mélangé les pinceaux quelque part. Les boutons fonctionnent super sauf que je n'arrive pas à mettre une bordure différente lorsque le bouton est "checked". Il devrait y avoir une classe supplémentaire "selected_radio_label" mais je ne la vois pas se mettre. Du coup, mon css correspondant ne s'affiche pas. 

Screenshot_3.jpg.e262a3ad2ca5fed69334c9c145a9a624.jpg

Est-ce que vous pouvez juste m'aiguiller ?

Merci d'avance.

Link to comment
Share on other sites

function getProductAttribute()
{
	// get every attributes values
	request = '';
	//create a temporary 'tab_attributes' array containing the choices of the customer
	var tab_attributes = [];
	var radio_inputs = parseInt($('#attributes .checked > input[type=radio]').length);
	if (radio_inputs)
		radio_inputs = '#attributes .checked > input[type=radio]';
	else
		radio_inputs = '#attributes input[type=radio]:checked';

	$('#attributes select, #attributes input[type=hidden], ' + radio_inputs).each(function(){
		tab_attributes.push($(this).val());
	});

	// build new request
	for (var i in attributesCombinations)
		for (var a in tab_attributes)
			if (attributesCombinations[i]['id_attribute'] === tab_attributes[a])
				request += '/' + attributesCombinations[i]['id_attribute'] + '-' + attributesCombinations[i]['group'] + attribute_anchor_separator + attributesCombinations[i]['attribute'];
	request = request.replace(request.substring(0, 1), '#/');
	var url = window.location + '';

	$('span').closest('li').find('label.selected_radio_label').removeClass('selected_radio_label');
	$('span.checked').closest('li').find('label').addClass('selected_radio_label');
	$('input[type=radio]').prev('label.selected_radio_label').removeClass('selected_radio_label');
	$('input[type=radio]:checked').prev('label').addClass('selected_radio_label');
	// redirection
	if (url.indexOf('#') != -1)
		url = url.substring(0, url.indexOf('#'));

	if ($('#customizationForm').length)
	{
		// set ipa to the customization form
		customAction = $('#customizationForm').attr('action');
		if (customAction.indexOf('#') != -1)
			customAction = customAction.substring(0, customAction.indexOf('#'));
		$('#customizationForm').attr('action', customAction + request);
	}

	window.location.replace(url + request);
}

J'ai ajouté ce bout de code là et maintenant, ça charge bien ma classe pour que la bordure ait l'aspect voulu quand on choisit une taille (mon attribut). Je sèche encore sur l'aspect de la bordure sur l'attribut par défaut. 

Link to comment
Share on other sites

function checkUrl()
{
	$('span').closest('li').find('label.selected_radio_label').removeClass('selected_radio_label');
	$('span.checked').closest('li').find('label').addClass('selected_radio_label');
	$('input[type=radio]').prev('label.selected_radio_label').removeClass('selected_radio_label');
	$('input[type=radio]:checked').prev('label').addClass('selected_radio_label');
	if (original_url != window.location || first_url_check)
	{
		first_url_check = false;
		var url = window.location + '';
		// if we need to load a specific combination
		if (url.indexOf('#/') != -1)
		{
			// get the params to fill from a "normal" url
			params = url.substring(url.indexOf('#') + 1, url.length);
			tabParams = params.split('/');
			tabValues = [];
			if (tabParams[0] == '')
				tabParams.shift();

			var len = tabParams.length;
			for (var i=0; i<len; i++)
			{
				tabParams[i] = tabParams[i].replace(attribute_anchor_separator, '-');
				tabValues.push(tabParams[i].split('-'));
			}

			// fill html with values
			$('.color_pick').removeClass('selected').parent().parent().children().removeClass('selected');

			count = 0;
			for (var z in tabValues)
				for (var a in attributesCombinations)
					if (attributesCombinations[a]['group'] === decodeURIComponent(tabValues[z][1])
						&& attributesCombinations[a]['id_attribute'] === decodeURIComponent(tabValues[z][0]))
					{
						count++;

						// add class 'selected' to the selected color
						$('#color_' + attributesCombinations[a]['id_attribute']).addClass('selected').parent().addClass('selected');
						$('input:radio[value=' + attributesCombinations[a]['id_attribute'] + ']').prop('checked', true);
						$('input[type=hidden][name=group_' + attributesCombinations[a]['id_attribute_group'] + ']').val(attributesCombinations[a]['id_attribute']);
						$('select[name=group_' + attributesCombinations[a]['id_attribute_group'] + ']').val(attributesCombinations[a]['id_attribute']);
						if (!!$.prototype.uniform)
							$.uniform.update('input[name=group_' + attributesCombinations[a]['id_attribute_group'] + '], select[name=group_' + attributesCombinations[a]['id_attribute_group'] + ']');

					}
			$('span').closest('li').find('label.selected_radio_label').removeClass('selected_radio_label');
			$('span.checked').closest('li').find('label').addClass('selected_radio_label');
			$('input[type=radio]').prev('label.selected_radio_label').removeClass('selected_radio_label');
			$('input[type=radio]:checked').prev('label').addClass('selected_radio_label');
			// find combination and select corresponding thumbs
			if (count)
			{
				if (firstTime)
				{
					firstTime = false;
					findCombination();
				}
				original_url = url;
				return true;
			}
			// no combination found = removing attributes from url
			else
				window.location.replace(url.substring(0, url.indexOf('#')));
		}
	}
	return false;
}

Il manquait donc ce bout de code dans le "product.js" du template.

Je pense que vous pouvez supprimer ce post. 

Merci pour votre aide spirituelle. 

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...