· 9 years ago · Oct 12, 2016, 10:12 PM
1/*
2* 2007-2015 PrestaShop
3*
4* NOTICE OF LICENSE
5*
6* This source file is subject to the Academic Free License (AFL 3.0)
7* that is bundled with this package in the file LICENSE.txt.
8* It is also available through the world-wide-web at this URL:
9* http://opensource.org/licenses/afl-3.0.php
10* If you did not receive a copy of the license and are unable to
11* obtain it through the world-wide-web, please send an email
12* to license@prestashop.com so we can send you a copy immediately.
13*
14* DISCLAIMER
15*
16* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
17* versions in the future. If you wish to customize PrestaShop for your
18* needs please refer to http://www.prestashop.com for more information.
19*
20* @author PrestaShop SA <contact@prestashop.com>
21* @copyright 2007-2015 PrestaShop SA
22* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
23* International Registered Trademark & Property of PrestaShop SA
24*/
25//global variables
26var serialScrollNbImagesDisplayed;
27var selectedCombination = [];
28var globalQuantity = 0;
29var colors = [];
30var original_url = window.location + '';
31var first_url_check = true;
32var firstTime = true;
33/* Retro compat from product.tpl */
34if (typeof customizationFields !== 'undefined' && customizationFields)
35{
36 var customizationFieldsBk = customizationFields;
37 customizationFields = [];
38 var j = 0;
39 for (var i = 0; i < customizationFieldsBk.length; ++i)
40 {
41 var key = 'pictures_' + parseInt(id_product) + '_' + parseInt(customizationFieldsBk[i]['id_customization_field']);
42 customizationFields[i] = [];
43 customizationFields[i][0] = (parseInt(customizationFieldsBk[i]['type']) == 0) ? 'img' + i : 'textField' + j++;
44 customizationFields[i][1] = (parseInt(customizationFieldsBk[i]['type']) == 0 && customizationFieldsBk[i][key]) ? 2 : parseInt(customizationFieldsBk[i]['required']);
45 }
46}
47
48if (typeof combinationImages !== 'undefined' && combinationImages)
49{
50 combinationImagesJS = [];
51 combinationImagesJS[0] = [];
52 var k = 0;
53 for (var i in combinationImages)
54 {
55 combinationImagesJS[i] = [];
56 for (var j in combinationImages[i])
57 {
58 var id_image = parseInt(combinationImages[i][j]['id_image']);
59 if (id_image)
60 {
61 combinationImagesJS[0][k++] = id_image;
62 combinationImagesJS[i][j] = [];
63 combinationImagesJS[i][j] = id_image;
64 }
65 }
66 }
67
68 if (typeof combinationImagesJS[0] !== 'undefined' && combinationImagesJS[0])
69 {
70 var array_values = [];
71 for (var key in arrayUnique(combinationImagesJS[0]))
72 array_values.push(combinationImagesJS[0][key]);
73 combinationImagesJS[0] = array_values;
74 }
75 combinationImages = combinationImagesJS;
76}
77
78if (typeof combinations !== 'undefined' && combinations)
79{
80 combinationsJS = [];
81 combinationsHashSet = {};
82 var k = 0;
83 for (var i in combinations)
84 {
85 globalQuantity += combinations[i]['quantity'];
86 combinationsJS[k] = [];
87 combinationsJS[k]['idCombination'] = parseInt(i);
88 combinationsJS[k]['idsAttributes'] = combinations[i]['attributes'];
89 combinationsJS[k]['quantity'] = combinations[i]['quantity'];
90 combinationsJS[k]['price'] = combinations[i]['price'];
91 combinationsJS[k]['ecotax'] = combinations[i]['ecotax'];
92 combinationsJS[k]['image'] = parseInt(combinations[i]['id_image']);
93 combinationsJS[k]['reference'] = combinations[i]['reference'];
94 combinationsJS[k]['unit_price'] = combinations[i]['unit_impact'];
95 combinationsJS[k]['minimal_quantity'] = parseInt(combinations[i]['minimal_quantity']);
96
97 combinationsJS[k]['available_date'] = [];
98 combinationsJS[k]['available_date']['date'] = combinations[i]['available_date'];
99 combinationsJS[k]['available_date']['date_formatted'] = combinations[i]['date_formatted'];
100
101 combinationsJS[k]['specific_price'] = [];
102 combinationsJS[k]['specific_price']['reduction_percent'] = (combinations[i]['specific_price'] && combinations[i]['specific_price']['reduction'] && combinations[i]['specific_price']['reduction_type'] == 'percentage') ? combinations[i]['specific_price']['reduction'] * 100 : 0;
103 combinationsJS[k]['specific_price']['reduction_price'] = (combinations[i]['specific_price'] && combinations[i]['specific_price']['reduction'] && combinations[i]['specific_price']['reduction_type'] == 'amount') ? combinations[i]['specific_price']['reduction'] : 0;
104 combinationsJS[k]['price'] = (combinations[i]['specific_price'] && combinations[i]['specific_price']['price'] && parseInt(combinations[i]['specific_price']['price']) != -1) ? combinations[i]['specific_price']['price'] : combinations[i]['price'];
105
106 combinationsJS[k]['reduction_type'] = (combinations[i]['specific_price'] && combinations[i]['specific_price']['reduction_type']) ? combinations[i]['specific_price']['reduction_type'] : '';
107 combinationsJS[k]['id_product_attribute'] = (combinations[i]['specific_price'] && combinations[i]['specific_price']['id_product_attribute']) ? combinations[i]['specific_price']['id_product_attribute'] : 0;
108
109 var key = combinationsJS[k]['idsAttributes'].sort().join('-');
110 combinationsHashSet[key] = combinationsJS[k];
111
112 k++;
113 }
114 combinations = combinationsJS;
115}
116/* */
117$(document).ready(function()
118{
119
120 //Added per tutorial
121 var files = new Array();
122 $('.customizationUploadLine').find('input[type="file"]').on('change', prepareUpload);
123 // Grab the files and set them to our variable
124 function prepareUpload(event)
125 {
126 files.push({'name' : event.target.name, 'file' :event.target.files[0]});
127 }
128
129
130
131 function previewFile(target, file) {
132
133 // $('#uniform-'+target.attr('id')).before($('<img id="preview-'+target.attr('id')+'"/><a href="'+window.location.href+'?deletePicture=1" title="Delete" ><img src="'+baseUri+'themes/default-bootstrap/img/icon/delete.gif" class="customization_delete_icon" width="12" height="12" /></a>'));
134 $('#uniform-'+target.attr('id')).before($('<span id="customImages"><img id="preview-'+target.attr('id')+'"/><a id="deletePictureTrigger" href="javascript:void(0)" title="Delete" ><img src="'+baseUri+'themes/default-bootstrap/img/icon/delete.gif" class="customization_delete_icon" width="12" height="12" /></a><span id="fileNameText">File Uploaded As: </span><span id="fileName"></span></span>'));
135 var preview = $('#preview-'+target.attr('id'));
136 var reader = new FileReader();
137 //hide the description line
138 $('.customizationUploadBrowseDescription').hide();
139 preview.attr('width', 64);
140
141 reader.onloadend = function () {
142 preview.attr('src', reader.result);
143 }
144
145 if (file) {
146 var extension = file.name.substring(file.name.lastIndexOf('.'));
147 switch (extension) {
148 case '.pdf':
149 //set the icon to PDF icon
150 preview.attr('src', ""+baseUri+"themes/trophy-bootstrap/img/pdf-icon.png");
151 break;
152 case '.ai':
153 //set the icon to AI icon
154 preview.attr('src', ""+baseUri+"themes/trophy-bootstrap/img/ai-icon.png");
155 break;
156 case '.eps':
157 //set the icon to the EPS icon
158 preview.attr('src', ""+baseUri+"themes/trophy-bootstrap/img/eps-icon.png");
159 break;
160 default :
161 reader.readAsDataURL(file);
162 }
163
164 } else {
165 preview.attr('src', "");
166 }
167 }
168
169 $('body').on('click', '#deletePictureTrigger', function(event){
170 event.preventDefault();
171 var data = new FormData();
172 // data.append('deletePicture', 1);
173 data.append('ajax', 1);
174 $.ajax({
175 url: window.location.href+"?deletePicture=1",
176 type: 'GET',
177 data: data,
178 cache: false,
179 //dataType: 'json',
180 processData: false,
181 contentType: false,
182 //enable for saving on 'add to cart'
183 //async: true,
184 success: function(data, textStatus, jqXHR)
185 {
186 console.log(data);
187 $('#customImages').remove();
188 $('.uploader .filename').val(null);
189 $('.uploader .filename').html("");
190 },
191 error: function(jqXHR, textStatus, errorThrown)
192 {
193 console.log( jqXHR);
194 alert ("there was an error:"+errorThrown);
195 }
196 });
197
198 });
199
200 $('#uploadTrigger').click(function(e) {
201
202
203 if(files.length > 0)
204 {
205
206 $('<div class="myoverlay"></div>').css({
207
208 'position' : 'fixed',
209 'top' : 0,
210 'left' : 0,
211 'background' : 'black',
212 'background' : 'rgba(0,0,0,.5)',
213 'z-index' : 5999,
214 'width' : '100%',
215 'height' : '100%',
216 'cursor' : 'pointer'
217 }).appendTo('body');
218
219 $('<div class="uploadingfiles">Your files are being uploaded...<img src="'+baseUri+'themes/default-bootstrap/img/ajax-loader.gif"></div>')
220 .css({
221 'position' : 'absolute',
222 'top' : '30%',
223 'left' : '50%',
224 'width' : '300px',
225 'margin-left' : '-150px',
226 'text-align' : 'center',
227 'padding' : '10px',
228 'background' : 'white'
229 })
230 .appendTo('.myoverlay');
231
232
233 var data = new FormData();
234
235 $.each(files, function(key, obj)
236 {
237 data.append(obj.name, obj.file);
238 });
239
240 data.append('submitCustomizedDatas', 1);
241 data.append('ajax', 1);
242 console.log(files);
243 $.ajax({
244 url: $('#customizationForm').attr('action'),
245 type: 'POST',
246 data: data,
247 cache: false,
248 dataType: 'json',
249 processData: false,
250 contentType: false,
251 //enable for saving on 'add to cart'
252 //async: true,
253 success: function(data, textStatus, jqXHR)
254 {
255
256
257
258
259
260 if (data !== null) {
261 if(typeof data.errors === 'undefined')
262 {
263 $.each(files, function(key, obj)
264 {
265 $('input[name="'+obj.name+'"]').addClass('filled');
266 previewFile($('input[name="'+obj.name+'"]'), obj.file);
267
268 });
269 $('.uploadingfiles').text('Upload Complete!');
270
271 }
272 else
273 {
274 console.log(data.errors);
275 $('.uploadingfiles').text('Error while uploading, please ensure your file type is allowed and try again');
276 }
277 }
278 $('.myoverlay').click(function(){$(this).remove()});
279 },
280 error: function(jqXHR, textStatus, errorThrown)
281 {
282 $('.uploadingfiles').text('ERRORS: ' + errorThrown);
283 $('.myoverlay').click(function(){$(this).remove()});
284 }
285 });
286
287 } // end checking files length
288 else alert('Nothing to upload!');
289 });
290
291
292
293 //End addition
294
295 var url_found = checkUrl();
296 //init the price in relation of the selected attributes
297 if (!url_found)
298 {
299 if (typeof productHasAttributes !== 'undefined' && productHasAttributes)
300 findCombination();
301 else
302 refreshProductImages(0);
303 }
304
305 serialScrollSetNbImages();
306
307 //init the serialScroll for thumbs
308 if (!!$.prototype.serialScroll)
309 $('#thumbs_list').serialScroll({
310 items:'li:visible',
311 prev:'#view_scroll_left',
312 next:'#view_scroll_right',
313 axis:'x',
314 offset:0,
315 start:0,
316 stop:true,
317 onBefore:serialScrollFixLock,
318 duration:700,
319 lazy: true,
320 lock: false,
321 force:false,
322 cycle:false
323 });
324
325 $('#thumbs_list').trigger('goto', 0);
326
327 //set jqZoom parameters if needed
328 if (typeof(jqZoomEnabled) !== 'undefined' && jqZoomEnabled)
329 {
330 if ($('#thumbs_list .shown img').length)
331 {
332 var new_src = $('#thumbs_list .shown img').attr('src').replace('cart_', 'large_');
333 if ($('.jqzoom img').attr('src')!= new_src)
334 $('.jqzoom img').attr('src', new_src).parent().attr('href', new_src);
335 }
336
337 $('.jqzoom').jqzoom({
338 zoomType: 'innerzoom', //innerzoom/standard/reverse/drag
339 zoomWidth: 458, //zooming div default width(default width value is 200)
340 zoomHeight: 458, //zooming div default width(default height value is 200)
341 xOffset: 21, //zooming div default offset(default offset value is 10)
342 yOffset: 0,
343 title: false
344 });
345
346 }
347 if (typeof(contentOnly) !== 'undefined')
348 {
349 if (!contentOnly && !!$.prototype.fancybox) {
350 $('li:visible .fancybox, .fancybox.shown').fancybox({
351 'hideOnContentClick': true,
352 'openEffect' : 'elastic',
353 'closeEffect' : 'elastic'
354 });
355 }
356 else if (contentOnly) {
357 $('#buy_block').attr('target', '_top');
358 }
359 }
360
361 if ($('#bxslider li').length && !!$.prototype.bxSlider)
362 $('#bxslider').bxSlider({
363 minSlides: 1,
364 maxSlides: 6,
365 slideWidth: 178,
366 slideMargin: 20,
367 pager: false,
368 nextText: '',
369 prevText: '',
370 moveSlides:1,
371 infiniteLoop:false,
372 hideControlOnEnd: true
373 });
374
375 if (!$('#bxslider li').length)
376 $('.accessories-block').parent().remove();
377
378 if (!!$.prototype.uniform)
379 {
380 if (typeof product_fileDefaultHtml !== 'undefined')
381 $.uniform.defaults.fileDefaultHtml = product_fileDefaultHtml;
382 if (typeof product_fileButtonHtml !== 'undefined')
383 $.uniform.defaults.fileButtonHtml = product_fileButtonHtml;
384 }
385
386 if ($('#customizationForm').length)
387 {
388 var url = window.location + '';
389 if (url.indexOf('#') != -1)
390 getProductAttribute();
391 }
392});
393
394//find a specific price rule, based on pre calculated dom display array
395function findSpecificPrice(){
396 var domData = $("#quantityDiscount table tbody tr").not( ":hidden" );
397 var nbProduct = $('#quantity_wanted').val();
398 var newPrice = false;
399
400 //construct current specific price for current combination
401 domData.each(function(i){
402 var dataDiscountQuantity = parseInt($(this).attr('data-discount-quantity'));
403 var dataDiscountNextQuantity = -1;
404
405 var nextQtDiscount = $(domData[i+1]);
406 if(nextQtDiscount.length){
407 dataDiscountNextQuantity = parseInt(nextQtDiscount.attr('data-discount-quantity'));
408 }
409 if(
410 (dataDiscountNextQuantity != -1 && nbProduct >= dataDiscountQuantity && nbProduct < dataDiscountNextQuantity) ||
411 (dataDiscountNextQuantity == -1 && nbProduct >= dataDiscountQuantity)
412 ){
413 newPrice = $(this).attr('data-real-discount-value');
414 return false;
415 }
416 });
417
418 return newPrice;
419}
420
421$(window).resize(function(){
422 serialScrollSetNbImages();
423 $('#thumbs_list').trigger('goto', 0);
424 serialScrollFixLock('', '', '', '', 0);
425});
426
427$(window).bind('hashchange', function(){
428 checkUrl();
429 findCombination();
430});
431
432//hover 'other views' images management
433$(document).on('mouseover', '#views_block li a', function(){
434 displayImage($(this));
435});
436//add a link on the span 'view full size' and on the big image
437$(document).on('click', '#view_full_size, #image-block', function(e){
438 $('#views_block .shown').click();
439});
440//catch the click on the "more infos" button at the top of the page
441$(document).on('click', '#short_description_block .button', function(e){
442 $('#more_info_tab_more_info').click();
443 $.scrollTo( '#more_info_tabs', 1200 );
444});
445// Hide the customization submit button and display some message
446$(document).on('click', '#customizedDatas input', function(e){
447 $('#customizedDatas input').hide();
448 $('#ajax-loader').fadeIn();
449 $('#customizedDatas').append(uploading_in_progress);
450});
451
452$(document).on('click', 'a[data-id=resetImages]', function(e){
453 e.preventDefault();
454 refreshProductImages(0);
455});
456
457$(document).on('click', '.color_pick', function(e){
458 e.preventDefault();
459 colorPickerClick($(this));
460 getProductAttribute();
461});
462
463$(document).on('change', '#quantity_wanted', function(e){
464 e.preventDefault();
465 var specificPrice = findSpecificPrice();
466
467 if(false !== specificPrice){
468 $('#our_price_display').text(specificPrice);
469 }else{
470 if (typeof productHasAttributes != 'undefined' && productHasAttributes){
471 updateDisplay();
472 }else{
473 $('#our_price_display').text(formatCurrency(parseFloat($('#our_price_display').attr('content')), currencyFormat, currencySign, currencyBlank));
474 }
475 }
476});
477
478$(document).on('change', '.attribute_select', function(e){
479 e.preventDefault();
480 findCombination();
481 getProductAttribute();
482});
483
484$(document).on('click', '.attribute_radio', function(e){
485 e.preventDefault();
486 getProductAttribute();
487});
488
489$(document).on('click', 'button[name=saveCustomization]', function(e){
490 saveCustomization();
491});
492
493if (typeof ad !== 'undefined' && ad && typeof adtoken !== 'undefined' && adtoken)
494{
495 $(document).on('click', 'a#publish_button', function(e){
496 e.preventDefault();
497 submitPublishProduct(ad, 0, adtoken);
498 });
499 $(document).on('click', 'a#lnk_view', function(e){
500 e.preventDefault();
501 submitPublishProduct(ad, 1, adtoken);
502 });
503}
504
505if (typeof(contentOnly) !== 'undefined' && contentOnly)
506{
507 $(document).on('click', '.fancybox', function(e){
508 e.preventDefault();
509 });
510
511 $(document).on('click', '#image-block', function(e){
512 e.preventDefault();
513 var productUrl = window.document.location.href + '';
514 var data = productUrl.replace(/[\?|&]content_only=1/, '');
515
516 if (window.parent.page_name == 'search')
517 data += ((data.indexOf('?') < 0) ? '?' : '&') + 'HTTP_REFERER=' + encodeURIComponent(window.parent.document.location.href);
518
519 window.parent.document.location.href = data;
520 return;
521 });
522}
523
524// The button to increment the product value
525$(document).on('click', '.product_quantity_up', function(e){
526 e.preventDefault();
527 fieldName = $(this).data('field-qty');
528 var currentVal = parseInt($('input[name='+fieldName+']').val());
529 if (!allowBuyWhenOutOfStock && quantityAvailable > 0)
530 quantityAvailableT = quantityAvailable;
531 else
532 quantityAvailableT = 100000000;
533 if (!isNaN(currentVal) && currentVal < quantityAvailableT)
534 $('input[name='+fieldName+']').val(currentVal + 1).trigger('keyup');
535 else
536 $('input[name='+fieldName+']').val(quantityAvailableT);
537
538 $('#quantity_wanted').change();
539});
540 // The button to decrement the product value
541$(document).on('click', '.product_quantity_down', function(e){
542 e.preventDefault();
543 fieldName = $(this).data('field-qty');
544 var currentVal = parseInt($('input[name='+fieldName+']').val());
545 if (!isNaN(currentVal) && currentVal > 1)
546 $('input[name='+fieldName+']').val(currentVal - 1).trigger('keyup');
547 else
548 $('input[name='+fieldName+']').val(1);
549
550 $('#quantity_wanted').change();
551});
552
553if (typeof minimalQuantity !== 'undefined' && minimalQuantity)
554{
555 checkMinimalQuantity();
556 $(document).on('keyup', 'input[name=qty]', function(e){
557 checkMinimalQuantity(minimalQuantity);
558 });
559}
560
561function arrayUnique(a)
562{
563 return a.reduce(function(p, c){
564 if (p.indexOf(c) < 0)
565 p.push(c);
566 return p;
567 }, []);
568};
569
570//check if a function exists
571function function_exists(function_name)
572{
573 if (typeof function_name === 'string')
574 function_name = this.window[function_name];
575 return typeof function_name === 'function';
576}
577
578//execute oosHook js code
579function oosHookJsCode()
580{
581 for (var i = 0; i < oosHookJsCodeFunctions.length; i++)
582 {
583 if (function_exists(oosHookJsCodeFunctions[i]))
584 setTimeout(oosHookJsCodeFunctions[i] + '()', 0);
585 }
586}
587
588//add a combination of attributes in the global JS sytem
589function addCombination(idCombination, arrayOfIdAttributes, quantity, price, ecotax, id_image, reference, unit_price, minimal_quantity, available_date, combination_specific_price)
590{
591 globalQuantity += quantity;
592
593 var combination = [];
594 combination['idCombination'] = idCombination;
595 combination['quantity'] = quantity;
596 combination['idsAttributes'] = arrayOfIdAttributes;
597 combination['price'] = price;
598 combination['ecotax'] = ecotax;
599 combination['image'] = id_image;
600 combination['reference'] = reference;
601 combination['unit_price'] = unit_price;
602 combination['minimal_quantity'] = minimal_quantity;
603 combination['available_date'] = [];
604 combination['available_date'] = available_date;
605 combination['specific_price'] = [];
606 combination['specific_price'] = combination_specific_price;
607 combinations.push(combination);
608}
609
610// search the combinations' case of attributes and update displaying of availability, prices, ecotax, and image
611function findCombination()
612{
613 $('#minimal_quantity_wanted_p').fadeOut();
614 if (typeof $('#minimal_quantity_label').text() === 'undefined' || $('#minimal_quantity_label').html() > 1)
615 $('#quantity_wanted').val(1);
616
617 //create a temporary 'choice' array containing the choices of the customer
618 var choice = [];
619 var radio_inputs = parseInt($('#attributes .checked > input[type=radio]').length);
620 if (radio_inputs)
621 radio_inputs = '#attributes .checked > input[type=radio]';
622 else
623 radio_inputs = '#attributes input[type=radio]:checked';
624
625 $('#attributes select, #attributes input[type=hidden], ' + radio_inputs).each(function(){
626 choice.push(parseInt($(this).val()));
627 });
628
629 //verify if this combinaison is the same that the user's choice
630 if (typeof combinationsHashSet !== 'undefined') {
631 var combination = combinationsHashSet[choice.sort().join('-')];
632
633 if (combination)
634 {
635 if (combination['minimal_quantity'] > 1)
636 {
637 $('#minimal_quantity_label').html(combination['minimal_quantity']);
638 $('#minimal_quantity_wanted_p').fadeIn();
639 $('#quantity_wanted').val(combination['minimal_quantity']);
640 $('#quantity_wanted').bind('keyup', function() {checkMinimalQuantity(combination['minimal_quantity']);});
641 }
642 //combination of the user has been found in our specifications of combinations (created in back office)
643 selectedCombination['unavailable'] = false;
644 selectedCombination['reference'] = combination['reference'];
645 $('#idCombination').val(combination['idCombination']);
646
647 //get the data of product with these attributes
648 quantityAvailable = combination['quantity'];
649 selectedCombination['price'] = combination['price'];
650 selectedCombination['unit_price'] = combination['unit_price'];
651 selectedCombination['specific_price'] = combination['specific_price'];
652 if (combination['ecotax'])
653 selectedCombination['ecotax'] = combination['ecotax'];
654 else
655 selectedCombination['ecotax'] = default_eco_tax;
656
657 //show the large image in relation to the selected combination
658 if (combination['image'] && combination['image'] != -1)
659 displayImage($('#thumb_' + combination['image']).parent());
660
661 //show discounts values according to the selected combination
662 if (combination['idCombination'] && combination['idCombination'] > 0)
663 displayDiscounts(combination['idCombination']);
664
665 //get available_date for combination product
666 selectedCombination['available_date'] = combination['available_date'];
667
668 //update the display
669 updateDisplay();
670
671 if (firstTime)
672 {
673 refreshProductImages(0);
674 firstTime = false;
675 }
676 else
677 refreshProductImages(combination['idCombination']);
678 //leave the function because combination has been found
679 return;
680 }
681 }
682
683 //this combination doesn't exist (not created in back office)
684 selectedCombination['unavailable'] = true;
685 if (typeof(selectedCombination['available_date']) !== 'undefined')
686 delete selectedCombination['available_date'];
687
688 updateDisplay();
689}
690
691//update display of the availability of the product AND the prices of the product
692function updateDisplay()
693{
694 var productPriceDisplay = productPrice;
695 var productPriceWithoutReductionDisplay = productPriceWithoutReduction;
696
697 if (!selectedCombination['unavailable'] && quantityAvailable > 0 && productAvailableForOrder == 1)
698 {
699 //show the choice of quantities
700 $('#quantity_wanted_p:hidden').show('slow');
701
702 //show the "add to cart" button ONLY if it was hidden
703 $('#add_to_cart:hidden').fadeIn(600);
704
705 //hide the hook out of stock
706 $('#oosHook').hide();
707
708 $('#availability_date').fadeOut();
709
710 //availability value management
711 if (stock_management && availableNowValue != '')
712 {
713 $('#availability_value').removeClass('label-warning').addClass('label-success').text(availableNowValue).show();
714 $('#availability_statut:hidden').show('slow');
715 }
716 else
717 $('#availability_statut:visible').hide('slow');
718
719 //'last quantities' message management
720 if (!allowBuyWhenOutOfStock)
721 {
722 if (quantityAvailable <= maxQuantityToAllowDisplayOfLastQuantityMessage)
723 $('#last_quantities').show('slow');
724 else
725 $('#last_quantities').hide('slow');
726 }
727
728 if (quantitiesDisplayAllowed)
729 {
730 $('#pQuantityAvailable:hidden').show('slow');
731 $('#quantityAvailable').text(quantityAvailable);
732
733 if (quantityAvailable < 2) // we have 1 or less product in stock and need to show "item" instead of "items"
734 {
735 $('#quantityAvailableTxt').show();
736 $('#quantityAvailableTxtMultiple').hide();
737 }
738 else
739 {
740 $('#quantityAvailableTxt').hide();
741 $('#quantityAvailableTxtMultiple').show();
742 }
743 }
744 }
745 else
746 {
747 //show the hook out of stock
748 if (productAvailableForOrder == 1)
749 {
750 $('#oosHook').show();
751 if ($('#oosHook').length > 0 && function_exists('oosHookJsCode'))
752 oosHookJsCode();
753 }
754
755 //hide 'last quantities' message if it was previously visible
756 $('#last_quantities:visible').hide('slow');
757
758 //hide the quantity of pieces if it was previously visible
759 $('#pQuantityAvailable:visible').hide('slow');
760
761 //hide the choice of quantities
762 if (!allowBuyWhenOutOfStock)
763 $('#quantity_wanted_p:visible').hide('slow');
764
765 //display that the product is unavailable with theses attributes
766 if (!selectedCombination['unavailable'])
767 {
768 $('#availability_value').text(doesntExistNoMore + (globalQuantity > 0 ? ' ' + doesntExistNoMoreBut : ''));
769 if (!allowBuyWhenOutOfStock)
770 $('#availability_value').removeClass('label-success').addClass('label-warning');
771 }
772 else
773 {
774 $('#availability_value').text(doesntExist).removeClass('label-success').addClass('label-warning');
775 $('#oosHook').hide();
776 }
777
778 if ((stock_management == 1 && !allowBuyWhenOutOfStock) || (!stock_management && selectedCombination['unavailable']))
779 $('#availability_statut:hidden').show();
780
781 if (typeof(selectedCombination['available_date']) !== 'undefined' && typeof(selectedCombination['available_date']['date_formatted']) !== 'undefined' && selectedCombination['available_date']['date'].length != 0)
782 {
783 var available_date = selectedCombination['available_date']['date'];
784 var tab_date = available_date.split('-');
785 var time_available = new Date(tab_date[0], tab_date[1], tab_date[2]);
786 time_available.setMonth(time_available.getMonth()-1);
787 var now = new Date();
788 if (now.getTime() < time_available.getTime() && $('#availability_date_value').text() != selectedCombination['available_date']['date_formatted'])
789 {
790 $('#availability_date').fadeOut('normal', function(){
791 $('#availability_date_value').text(selectedCombination['available_date']['date_formatted']);
792 $(this).fadeIn();
793 });
794 }
795 else if (now.getTime() < time_available.getTime())
796 $('#availability_date').fadeIn();
797 }
798 else
799 $('#availability_date').fadeOut();
800
801 //show the 'add to cart' button ONLY IF it's possible to buy when out of stock AND if it was previously invisible
802 if (allowBuyWhenOutOfStock && !selectedCombination['unavailable'] && productAvailableForOrder)
803 {
804 $('#add_to_cart:hidden').fadeIn(600);
805
806 if (stock_management && availableLaterValue != '')
807 {
808 $('#availability_value').addClass('label-warning').text(availableLaterValue).show('slow');
809 $('#availability_statut:hidden').show('slow');
810 }
811 else
812 $('#availability_statut:visible').hide('slow');
813 }
814 else
815 {
816 $('#add_to_cart:visible').fadeOut(600);
817 if (stock_management == 1 && productAvailableForOrder)
818 $('#availability_statut:hidden').show('slow');
819 }
820
821 if (productAvailableForOrder == 0)
822 $('#availability_statut:visible').hide();
823 }
824
825 if (selectedCombination['reference'] || productReference)
826 {
827 if (selectedCombination['reference'])
828 $('#product_reference span').text(selectedCombination['reference']);
829 else if (productReference)
830 $('#product_reference span').text(productReference);
831 $('#product_reference:hidden').show('slow');
832 }
833 else
834 $('#product_reference:visible').hide('slow');
835
836 // If we have combinations, update price section: amounts, currency, discount amounts,...
837 if (productHasAttributes)
838 updatePrice();
839}
840
841function updatePrice()
842{
843 // Get combination prices
844 var combID = $('#idCombination').val();
845 var combination = combinationsFromController[combID];
846 if (typeof combination == 'undefined')
847 return;
848
849 // Set product (not the combination) base price
850 var basePriceWithoutTax = +productPriceTaxExcluded;
851 var basePriceWithTax = +productPriceTaxIncluded;
852 var priceWithGroupReductionWithoutTax = 0;
853
854 priceWithGroupReductionWithoutTax = basePriceWithoutTax * (1 - groupReduction);
855
856 // Apply combination price impact (only if there is no specific price)
857 // 0 by default, +x if price is inscreased, -x if price is decreased
858 basePriceWithoutTax = basePriceWithoutTax + +combination.price;
859 basePriceWithTax = basePriceWithTax + +combination.price * (taxRate/100 + 1);
860
861 // If a specific price redefine the combination base price
862 if (combination.specific_price && combination.specific_price.price > 0)
863 {
864 basePriceWithoutTax = +combination.specific_price.price;
865 basePriceWithTax = +combination.specific_price.price * (taxRate/100 + 1);
866 }
867
868 var priceWithDiscountsWithoutTax = basePriceWithoutTax;
869 var priceWithDiscountsWithTax = basePriceWithTax;
870
871 if (default_eco_tax)
872 {
873 // combination.ecotax doesn't modify the price but only the display
874 priceWithDiscountsWithoutTax = priceWithDiscountsWithoutTax + default_eco_tax * (1 + ecotaxTax_rate / 100);
875 priceWithDiscountsWithTax = priceWithDiscountsWithTax + default_eco_tax * (1 + ecotaxTax_rate / 100);
876 basePriceWithTax = basePriceWithTax + default_eco_tax * (1 + ecotaxTax_rate / 100);
877 basePriceWithoutTax = basePriceWithoutTax + default_eco_tax * (1 + ecotaxTax_rate / 100);
878 }
879
880 // Apply specific price (discount)
881 // We only apply percentage discount and discount amount given before tax
882 // Specific price give after tax will be handled after taxes are added
883 if (combination.specific_price && combination.specific_price.reduction > 0)
884 {
885 if (combination.specific_price.reduction_type == 'amount')
886 {
887 if (typeof combination.specific_price.reduction_tax !== 'undefined' && combination.specific_price.reduction_tax === "0")
888 {
889 var reduction = combination.specific_price.reduction;
890 if (combination.specific_price.id_currency == 0)
891 reduction = reduction * currencyRate * (1 - groupReduction);
892 priceWithDiscountsWithoutTax -= reduction;
893 priceWithDiscountsWithTax -= reduction * (taxRate/100 + 1);
894 }
895 }
896 else if (combination.specific_price.reduction_type == 'percentage')
897 {
898 priceWithDiscountsWithoutTax = priceWithDiscountsWithoutTax * (1 - +combination.specific_price.reduction);
899 priceWithDiscountsWithTax = priceWithDiscountsWithTax * (1 - +combination.specific_price.reduction);
900 }
901 }
902
903
904 // Apply Tax if necessary
905 if (noTaxForThisProduct || customerGroupWithoutTax)
906 {
907 basePriceDisplay = basePriceWithoutTax;
908 priceWithDiscountsDisplay = priceWithDiscountsWithoutTax;
909 }
910 else
911 {
912 basePriceDisplay = basePriceWithTax;
913 priceWithDiscountsDisplay = priceWithDiscountsWithTax;
914 }
915
916 // If the specific price was given after tax, we apply it now
917 if (combination.specific_price && combination.specific_price.reduction > 0)
918 {
919 if (combination.specific_price.reduction_type == 'amount')
920 {
921 if (typeof combination.specific_price.reduction_tax === 'undefined'
922 || (typeof combination.specific_price.reduction_tax !== 'undefined' && combination.specific_price.reduction_tax === '1'))
923 {
924 var reduction = combination.specific_price.reduction;
925
926 if (typeof specific_currency !== 'undefined' && specific_currency && parseInt(combination.specific_price.id_currency) && combination.specific_price.id_currency != currency.id)
927 reduction = reduction / currencyRate;
928 else if(!specific_currency)
929 reduction = reduction * currencyRate;
930
931 if (typeof groupReduction !== 'undefined' && groupReduction > 0)
932 reduction *= 1 - parseFloat(groupReduction);
933
934 priceWithDiscountsDisplay -= reduction;
935 // We recalculate the price without tax in order to keep the data consistency
936 priceWithDiscountsWithoutTax = priceWithDiscountsDisplay - reduction * ( 1/(1+taxRate/100) );
937 }
938 }
939 }
940
941 if (priceWithDiscountsDisplay < 0)
942 {
943 priceWithDiscountsDisplay = 0;
944 }
945
946 // Compute discount value and percentage
947 // Done just before display update so we have final prices
948 if (basePriceDisplay != priceWithDiscountsDisplay)
949 {
950 var discountValue = basePriceDisplay - priceWithDiscountsDisplay;
951 var discountPercentage = (1-(priceWithDiscountsDisplay/basePriceDisplay))*100;
952 }
953
954 var unit_impact = +combination.unit_impact;
955 if (productUnitPriceRatio > 0 || unit_impact)
956 {
957 if (unit_impact)
958 {
959 baseUnitPrice = productBasePriceTaxExcl / productUnitPriceRatio;
960 unit_price = baseUnitPrice + unit_impact;
961
962 if (!noTaxForThisProduct || !customerGroupWithoutTax)
963 unit_price = unit_price * (taxRate/100 + 1);
964 }
965 else
966 unit_price = priceWithDiscountsDisplay / productUnitPriceRatio;
967 }
968
969 /* Update the page content, no price calculation happens after */
970
971 // Hide everything then show what needs to be shown
972 $('#reduction_percent').hide();
973 $('#reduction_amount').hide();
974 $('#old_price, #old_price_display, #old_price_display_taxes').hide();
975 $('.price-ecotax').hide();
976 $('.unit-price').hide();
977
978 if (priceWithDiscountsDisplay > 0)
979 {
980 $('#our_price_display').text(formatCurrency(priceWithDiscountsDisplay, currencyFormat, currencySign, currencyBlank)).trigger('change');
981 }
982 else
983 {
984 $('#our_price_display').text(formatCurrency(0, currencyFormat, currencySign, currencyBlank)).trigger('change');
985 }
986
987 // If the calculated price (after all discounts) is different than the base price
988 // we show the old price striked through
989
990 if (priceWithDiscountsDisplay.toFixed(2) != basePriceDisplay.toFixed(2))
991 {
992 $('#old_price_display span.price').text(formatCurrency(basePriceDisplay, currencyFormat, currencySign, currencyBlank));
993 $('#old_price, #old_price_display, #old_price_display_taxes').removeClass('hidden').show();
994
995 // Then if it's not only a group reduction we display the discount in red box
996 if (priceWithDiscountsWithoutTax != priceWithGroupReductionWithoutTax)
997 {
998 if (combination.specific_price.reduction_type == 'amount')
999 {
1000 $('#reduction_amount_display').html('-' + formatCurrency(discountValue, currencyFormat, currencySign, currencyBlank));
1001 $('#reduction_amount').show();
1002 }
1003 else
1004 {
1005 var toFix = 2;
1006 if ((parseFloat(discountPercentage).toFixed(2) - parseFloat(discountPercentage).toFixed(0)) == 0)
1007 toFix = 0;
1008 $('#reduction_percent_display').html('-' + parseFloat(discountPercentage).toFixed(toFix) + '%');
1009 $('#reduction_percent').show();
1010 }
1011 }
1012 }
1013
1014 // Green Tax (Eco tax)
1015 // Update display of Green Tax
1016 if (default_eco_tax)
1017 {
1018 ecotax = default_eco_tax;
1019
1020 // If the default product ecotax is overridden by the combination
1021 if (combination.ecotax)
1022 ecotax = +combination.ecotax;
1023
1024 if (!noTaxForThisProduct)
1025 ecotax = ecotax * (1 + ecotaxTax_rate/100)
1026
1027 $('#ecotax_price_display').text(formatCurrency(ecotax * currencyRate, currencyFormat, currencySign, currencyBlank));
1028 $('.price-ecotax').show();
1029 }
1030
1031 // Unit price are the price per piece, per Kg, per m²
1032 // It doesn't modify the price, it's only for display
1033 if (productUnitPriceRatio > 0)
1034 {
1035 $('#unit_price_display').text(formatCurrency(unit_price * currencyRate, currencyFormat, currencySign, currencyBlank));
1036 $('.unit-price').show();
1037 }
1038
1039 if (noTaxForThisProduct || customerGroupWithoutTax)
1040 updateDiscountTable(priceWithDiscountsWithoutTax);
1041 else
1042 updateDiscountTable(priceWithDiscountsWithTax);
1043}
1044
1045//update display of the large image
1046function displayImage(domAAroundImgThumb, no_animation)
1047{
1048 if (typeof(no_animation) == 'undefined')
1049 no_animation = false;
1050 if (domAAroundImgThumb.attr('href'))
1051 {
1052 var new_src = domAAroundImgThumb.attr('href').replace('thickbox', 'large');
1053 var new_title = domAAroundImgThumb.attr('title');
1054 var new_href = domAAroundImgThumb.attr('href');
1055 if ($('#bigpic').attr('src') != new_src)
1056 {
1057 $('#bigpic').attr({
1058 'src' : new_src,
1059 'alt' : new_title,
1060 'title' : new_title
1061 }).load(function(){
1062 if (typeof(jqZoomEnabled) !== 'undefined' && jqZoomEnabled)
1063 $(this).attr('rel', new_href);
1064 });
1065 }
1066 $('#views_block li a').removeClass('shown');
1067 $(domAAroundImgThumb).addClass('shown');
1068 }
1069}
1070
1071/**
1072 * Update display of the discounts table.
1073 * @param combination Combination ID.
1074 */
1075function displayDiscounts(combination)
1076{
1077 // Tables & rows selection
1078 var quantityDiscountTable = $('#quantityDiscount');
1079 var combinationsSpecificQuantityDiscount = $('#quantityDiscount_'+combination, quantityDiscountTable);
1080 var allQuantityDiscount = $('#quantityDiscount_0', quantityDiscountTable);
1081
1082 // If there is some combinations specific quantity discount, show them, else, if there are some
1083 // products quantity discount: show them. In case of result, show the category.
1084 if (combinationsSpecificQuantityDiscount.length != 0) {
1085 combinationsSpecificQuantityDiscount.show();
1086 quantityDiscountTable.show();
1087 } else if(allQuantityDiscount.length != 0) {
1088 allQuantityDiscount.show();
1089 $('tbody tr', quantityDiscountTable).not('#quantityDiscount_0').hide();
1090 quantityDiscountTable.show();
1091 } else {
1092 quantityDiscountTable.hide();
1093 }
1094}
1095
1096function updateDiscountTable(newPrice)
1097{
1098 $('#quantityDiscount tbody tr').each(function(){
1099 var type = $(this).data("discount-type");
1100 var discount = $(this).data("discount");
1101 var quantity = $(this).data("discount-quantity");
1102
1103 if (type == 'percentage')
1104 {
1105 var discountedPrice = newPrice * (1 - discount/100);
1106 var discountUpTo = newPrice * (discount/100) * quantity;
1107 }
1108 else if (type == 'amount')
1109 {
1110 var discountedPrice = newPrice - discount;
1111 var discountUpTo = discount * quantity;
1112 }
1113
1114 if (displayDiscountPrice != 0)
1115 $(this).children('td').eq(1).text( formatCurrency(discountedPrice * currencyRate, currencyFormat, currencySign, currencyBlank) );
1116 $(this).children('td').eq(2).text(upToTxt + ' ' + formatCurrency(discountUpTo * currencyRate, currencyFormat, currencySign, currencyBlank));
1117 });
1118}
1119
1120function serialScrollFixLock(event, targeted, scrolled, items, position)
1121{
1122 var serialScrollNbImages = $('#thumbs_list li:visible').length;
1123 var leftArrow = position == 0 ? true : false;
1124 var rightArrow = position + serialScrollNbImagesDisplayed >= serialScrollNbImages ? true : false;
1125
1126 $('#view_scroll_left').css('cursor', leftArrow ? 'default' : 'pointer').css('display', leftArrow ? 'none' : 'block').fadeTo(0, leftArrow ? 0 : 1);
1127 $('#view_scroll_right').css('cursor', rightArrow ? 'default' : 'pointer').fadeTo(0, rightArrow ? 0 : 1).css('display', rightArrow ? 'none' : 'block');
1128 return true;
1129}
1130
1131function serialScrollSetNbImages()
1132{
1133 serialScrollNbImagesDisplayed = 4;
1134 if ($('#thumbs_list').outerWidth(true) < 194)
1135 serialScrollNbImagesDisplayed = 1;
1136 else if ($('#thumbs_list').outerWidth(true) < 294)
1137 serialScrollNbImagesDisplayed = 2;
1138 else if ($('#thumbs_list').outerWidth(true) < 392)
1139 serialScrollNbImagesDisplayed = 3;
1140}
1141
1142
1143// Change the current product images regarding the combination selected
1144function refreshProductImages(id_product_attribute)
1145{
1146 id_product_attribute = parseInt(id_product_attribute);
1147
1148 if (id_product_attribute > 0 && typeof(combinationImages) !== 'undefined' && typeof(combinationImages[id_product_attribute]) !== 'undefined')
1149 {
1150 $('#thumbs_list li').hide();
1151 for (var i = 0; i < combinationImages[id_product_attribute].length; i++)
1152 if (typeof(jqZoomEnabled) !== 'undefined' && jqZoomEnabled)
1153 $('#thumbnail_' + parseInt(combinationImages[id_product_attribute][i])).show().children('a.shown').trigger('click');
1154 else
1155 $('#thumbnail_' + parseInt(combinationImages[id_product_attribute][i])).show();
1156 }
1157 else
1158 {
1159 $('#thumbs_list li').show();
1160
1161 var choice = [];
1162 var radio_inputs = parseInt($('#attributes .checked > input[type=radio]').length);
1163 if (radio_inputs)
1164 radio_inputs = '#attributes .checked > input[type=radio]';
1165 else
1166 radio_inputs = '#attributes input[type=radio]:checked';
1167
1168 $('#attributes select, #attributes input[type=hidden], ' + radio_inputs).each(function(){
1169 choice.push(parseInt($(this).val()));
1170 });
1171
1172 if (typeof combinationsHashSet !== 'undefined') {
1173 var combination = combinationsHashSet[choice.sort().join('-')];
1174 if(combination) {
1175 //show the large image in relation to the selected combination
1176 if (combination['image'] && combination['image'] != -1)
1177 displayImage($('#thumb_' + combination['image']).parent());
1178 }
1179 }
1180 }
1181
1182 if (parseInt($('#thumbs_list_frame >li:visible').length) != parseInt($('#thumbs_list_frame >li').length))
1183 $('#wrapResetImages').stop(true, true).show();
1184 else
1185 $('#wrapResetImages').stop(true, true).hide();
1186
1187 $('#thumbs_list_frame').width(parseInt($('#thumbs_list_frame >li').outerWidth(true) * $('#thumbs_list_frame >li').length) + 'px');
1188 $('#thumbs_list').trigger('goto', 0);
1189 serialScrollFixLock('', '', '', '', 0);
1190}
1191
1192function saveCustomization()
1193{
1194 $('#quantityBackup').val($('#quantity_wanted').val());
1195 $('#customizationForm').submit();
1196}
1197
1198function submitPublishProduct(url, redirect, token)
1199{
1200 var id_product = $('#admin-action-product-id').val();
1201
1202 $.ajaxSetup({async: false});
1203 $.post(url + '/index.php', {
1204 action:'publishProduct',
1205 id_product: id_product,
1206 status: 1,
1207 redirect: redirect,
1208 ajax: 1,
1209 tab: 'AdminProducts',
1210 token: token
1211 },
1212 function(data)
1213 {
1214 if (data.indexOf('error') === -1)
1215 document.location.href = data;
1216 }
1217 );
1218 return true;
1219}
1220
1221function checkMinimalQuantity(minimal_quantity)
1222{
1223 if ($('#quantity_wanted').val() < minimal_quantity)
1224 {
1225 $('#quantity_wanted').css('border', '1px solid red');
1226 $('#minimal_quantity_wanted_p').css('color', 'red');
1227 }
1228 else
1229 {
1230 $('#quantity_wanted').css('border', '1px solid #BDC2C9');
1231 $('#minimal_quantity_wanted_p').css('color', '#374853');
1232 }
1233}
1234
1235function colorPickerClick(elt)
1236{
1237 id_attribute = $(elt).attr('id').replace('color_', '');
1238 $(elt).parent().parent().children().removeClass('selected');
1239 $(elt).fadeTo('fast', 1, function(){
1240 $(this).fadeTo('fast', 0, function(){
1241 $(this).fadeTo('fast', 1, function(){
1242 $(this).parent().addClass('selected');
1243 });
1244 });
1245 });
1246 $(elt).parent().parent().parent().children('.color_pick_hidden').val(id_attribute);
1247}
1248
1249
1250function getProductAttribute()
1251{
1252 // get every attributes values
1253 request = '';
1254 //create a temporary 'tab_attributes' array containing the choices of the customer
1255 var tab_attributes = [];
1256 var radio_inputs = parseInt($('#attributes .checked > input[type=radio]').length);
1257 if (radio_inputs)
1258 radio_inputs = '#attributes .checked > input[type=radio]';
1259 else
1260 radio_inputs = '#attributes input[type=radio]:checked';
1261
1262 $('#attributes select, #attributes input[type=hidden], ' + radio_inputs).each(function(){
1263 tab_attributes.push($(this).val());
1264 });
1265
1266 // build new request
1267 for (var i in attributesCombinations)
1268 for (var a in tab_attributes)
1269 if (attributesCombinations[i]['id_attribute'] === tab_attributes[a])
1270 request += '/' + attributesCombinations[i]['id_attribute'] + '-' + attributesCombinations[i]['group'] + attribute_anchor_separator + attributesCombinations[i]['attribute'];
1271 request = request.replace(request.substring(0, 1), '#/');
1272 var url = window.location + '';
1273
1274 // redirection
1275 if (url.indexOf('#') != -1)
1276 url = url.substring(0, url.indexOf('#'));
1277
1278 if ($('#customizationForm').length)
1279 {
1280 // set ipa to the customization form
1281 customAction = $('#customizationForm').attr('action');
1282 if (customAction.indexOf('#') != -1)
1283 customAction = customAction.substring(0, customAction.indexOf('#'));
1284 $('#customizationForm').attr('action', customAction + request);
1285 }
1286
1287 window.location.replace(url + request);
1288}
1289
1290function checkUrl()
1291{
1292 if (original_url != window.location || first_url_check)
1293 {
1294 first_url_check = false;
1295 var url = window.location + '';
1296 // if we need to load a specific combination
1297 if (url.indexOf('#/') != -1)
1298 {
1299 // get the params to fill from a "normal" url
1300 params = url.substring(url.indexOf('#') + 1, url.length);
1301 tabParams = params.split('/');
1302 tabValues = [];
1303 if (tabParams[0] == '')
1304 tabParams.shift();
1305
1306 var len = tabParams.length;
1307 for (var i=0; i<len; i++)
1308 {
1309 tabParams[i] = tabParams[i].replace(attribute_anchor_separator, '-');
1310 tabValues.push(tabParams[i].split('-'));
1311 }
1312
1313 // fill html with values
1314 $('.color_pick').removeClass('selected').parent().parent().children().removeClass('selected');
1315
1316 count = 0;
1317 for (var z in tabValues)
1318 for (var a in attributesCombinations)
1319 if (attributesCombinations[a]['group'] === decodeURIComponent(tabValues[z][1])
1320 && attributesCombinations[a]['id_attribute'] === decodeURIComponent(tabValues[z][0]))
1321 {
1322 count++;
1323
1324 // add class 'selected' to the selected color
1325 $('#color_' + attributesCombinations[a]['id_attribute']).addClass('selected').parent().addClass('selected');
1326 $('input:radio[value=' + attributesCombinations[a]['id_attribute'] + ']').prop('checked', true);
1327 $('input[type=hidden][name=group_' + attributesCombinations[a]['id_attribute_group'] + ']').val(attributesCombinations[a]['id_attribute']);
1328 $('select[name=group_' + attributesCombinations[a]['id_attribute_group'] + ']').val(attributesCombinations[a]['id_attribute']);
1329 if (!!$.prototype.uniform)
1330 $.uniform.update('input[name=group_' + attributesCombinations[a]['id_attribute_group'] + '], select[name=group_' + attributesCombinations[a]['id_attribute_group'] + ']');
1331
1332 }
1333 // find combination and select corresponding thumbs
1334 if (count)
1335 {
1336 if (firstTime)
1337 {
1338 firstTime = false;
1339 findCombination();
1340 }
1341 original_url = url;
1342 return true;
1343 }
1344 // no combination found = removing attributes from url
1345 else
1346 window.location.replace(url.substring(0, url.indexOf('#')));
1347 }
1348 }
1349 return false;
1350}