[+] FO : you can access to a product combination with its own url (e.g: http://www.myshop.com/index.php?controller=product&id_product=1#disk-space=16go&color=yellow)
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9425 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
1 parent
730e5e4d96
commit
6517b06539
5 files changed
+405
-224
No files matched your search
@@ -553,3 +553,68 @@ function colorPickerClick(elt)
|
||||
$('#color_pick_hidden').val(id_attribute);
|
||||
findCombination();
|
||||
}
|
||||
|
||||
|
||||
function getProductAttribute()
|
||||
{
|
||||
// get product attribute id
|
||||
product_attribute_id = $('#idCombination').val();
|
||||
product_id = $('#product_page_product_id').val();
|
||||
|
||||
// get every attributes values
|
||||
request = '';
|
||||
//create a temporary 'tab_attributes' array containing the choices of the customer
|
||||
var tab_attributes = new Array();
|
||||
$('div#attributes select, div#attributes input[type=hidden], div#attributes input[type=radio]:checked').each(function(){
|
||||
tab_attributes.push($(this).val());
|
||||
});
|
||||
|
||||
// build new request
|
||||
for (i in attributesCombinations)
|
||||
for (a in tab_attributes)
|
||||
if (attributesCombinations[i]['id_attribute'] == tab_attributes[a])
|
||||
request += '&'+attributesCombinations[i]['group']+'='+attributesCombinations[i]['attribute'];
|
||||
request = request.replace(request.substring(0, 1), '#');
|
||||
url = window.location+'';
|
||||
|
||||
// redirection
|
||||
if (url.indexOf('#') != -1)
|
||||
url = url.substring(0, url.indexOf('#'));
|
||||
window.location = url+request;
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
url = window.location+'';
|
||||
// if we need to load a specific combination
|
||||
if (url.indexOf('#') != -1)
|
||||
{
|
||||
// get the params to fill
|
||||
params = url.substring(url.indexOf('#') + 1, url.length);
|
||||
tabParams = params.split('&');
|
||||
tabValues = new Array();
|
||||
for (i in tabParams)
|
||||
tabValues.push(tabParams[i].split('='));
|
||||
product_id = $('#product_page_product_id').val();
|
||||
// fill html with values
|
||||
$('.color_pick').removeClass('selected');
|
||||
count = 0;
|
||||
for (z in tabValues)
|
||||
for (a in attributesCombinations)
|
||||
if (attributesCombinations[a]['group'] == tabValues[z][0]
|
||||
&& attributesCombinations[a]['attribute'] == tabValues[z][1])
|
||||
{
|
||||
count++;
|
||||
// add class 'selected' to the selected color
|
||||
$('#color_'+attributesCombinations[a]['id_attribute']).addClass('selected');
|
||||
$('input:radio[value='+attributesCombinations[a]['id_attribute']+']').attr('checked', 'checked');
|
||||
$('input: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']);
|
||||
}
|
||||
// find combination
|
||||
if (count == tabValues.length)
|
||||
findCombination();
|
||||
// no combination found = removing attributes from url
|
||||
else
|
||||
window.location = url.substring(0, url.indexOf('#'));
|
||||
}
|
||||
});
|
||||
@@ -111,6 +111,19 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
|
||||
addCombination({$idCombination|intval}, new Array({$combination.list}), {$combination.quantity}, {$combination.price}, {$combination.ecotax}, {$combination.id_image}, '{$combination.reference|addslashes}', {$combination.unit_impact}, {$combination.minimal_quantity}, '{$combination.available_date}');
|
||||
{/foreach}
|
||||
{/if}
|
||||
|
||||
{if isset($attributesCombinations)}
|
||||
// Combinations attributes informations
|
||||
var attributesCombinations = new Array();
|
||||
{foreach from=$attributesCombinations key=id item=aC}
|
||||
tabInfos = new Array();
|
||||
tabInfos['id_attribute'] = '{$aC.id_attribute|intval}';
|
||||
tabInfos['attribute'] = '{$aC.attribute}';
|
||||
tabInfos['group'] = '{$aC.group}';
|
||||
tabInfos['id_attribute_group'] = '{$aC.id_attribute_group|intval}';
|
||||
attributesCombinations.push(tabInfos);
|
||||
{/foreach}
|
||||
{/if}
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
@@ -290,7 +303,7 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
|
||||
{assign var="groupName" value="group_$id_attribute_group"}
|
||||
<div class="attribute_list">
|
||||
{if ($group.group_type == 'select')}
|
||||
<select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="attribute_select" onchange="findCombination();{if $colors|@count > 0}$('#wrapResetImages').show('slow');{/if};">
|
||||
<select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="attribute_select" onchange="findCombination();getProductAttribute();{if $colors|@count > 0}$('#wrapResetImages').show('slow');{/if};">
|
||||
{foreach from=$group.attributes key=id_attribute item=group_attribute}
|
||||
<option value="{$id_attribute|intval}"{if (isset($smarty.get.$groupName) && $smarty.get.$groupName|intval == $id_attribute) || $group.default == $id_attribute} selected="selected"{/if} title="{$group_attribute|escape:'htmlall':'UTF-8'}">{$group_attribute|escape:'htmlall':'UTF-8'}</option>
|
||||
{/foreach}
|
||||
@@ -300,7 +313,7 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
|
||||
{assign var="default_colorpicker" value=""}
|
||||
{foreach from=$group.attributes key=id_attribute item=group_attribute}
|
||||
<li>
|
||||
<a id="color_{$id_attribute|intval}" class="color_pick{if ($group.default == $id_attribute)} selected{/if}" style="background: {$colors.$id_attribute.value};" title="{$colors.$id_attribute.name}" onclick="colorPickerClick(this);{if $colors|@count > 0}$('#wrapResetImages').show('slow');{/if}">
|
||||
<a id="color_{$id_attribute|intval}" class="color_pick{if ($group.default == $id_attribute)} selected{/if}" style="background: {$colors.$id_attribute.value};" title="{$colors.$id_attribute.name}" onclick="colorPickerClick(this);getProductAttribute();{if $colors|@count > 0}$('#wrapResetImages').show('slow');{/if}">
|
||||
{if file_exists($col_img_dir|cat:$id_attribute|cat:'.jpg')}
|
||||
<img src="{$img_col_dir}{$id_attribute}.jpg" alt="{$colors.$id_attribute.name}" width="20" height="20" /><br>
|
||||
{/if}
|
||||
@@ -314,7 +327,7 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
|
||||
<input type="hidden" id="color_pick_hidden" name="{$groupName}" value="{$default_colorpicker}" >
|
||||
{elseif ($group.group_type == 'radio')}
|
||||
{foreach from=$group.attributes key=id_attribute item=group_attribute}
|
||||
<input type="radio" class="attribute_radio" name="{$groupName}" value="{$id_attribute}" {if ($group.default == $id_attribute)} checked="checked"{/if} onclick="findCombination();{if $colors|@count > 0}$('#wrapResetImages').show('slow');{/if}">
|
||||
<input type="radio" class="attribute_radio" name="{$groupName}" value="{$id_attribute}" {if ($group.default == $id_attribute)} checked="checked"{/if} onclick="findCombination();getProductAttribute();{if $colors|@count > 0}$('#wrapResetImages').show('slow');{/if}">
|
||||
{$group_attribute|escape:'htmlall':'UTF-8'}<br/>
|
||||
{/foreach}
|
||||
{/if}
|
||||
|
||||
Reference in new issue
Block a user