Guest User

product.js

a guest
Mar 7th, 2018
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.00 KB | None | 0 0
  1. /*
  2. * 2007-2014 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 [email protected] 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 <[email protected]>
  21. * @copyright 2007-2014 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.  
  26. //global variables
  27. var selectedCombination = [];
  28. var globalQuantity = 0;
  29. var colors = [];
  30.  
  31. $(document).ready(function(){
  32. if (typeof customizationFields !== 'undefined' && customizationFields)
  33. {
  34. var customizationFieldsBk = customizationFields;
  35. customizationFields = [];
  36. var j = 0;
  37. for (var i = 0; i < customizationFieldsBk.length; ++i)
  38. {
  39. var key = 'pictures_' + parseInt(id_product) + '_' + parseInt(customizationFieldsBk[i]['id_customization_field']);
  40. customizationFields[i] = [];
  41. customizationFields[i][0] = (parseInt(customizationFieldsBk[i]['type']) == 0) ? 'img' + i : 'textField' + j++;
  42. customizationFields[i][1] = (parseInt(customizationFieldsBk[i]['type']) == 0 && customizationFieldsBk[i][key]) ? 2 : parseInt(customizationFieldsBk[i]['required']);
  43. }
  44. }
  45.  
  46. if (typeof combinationImages !== 'undefined' && combinationImages)
  47. {
  48. combinationImagesJS = [];
  49. combinationImagesJS[0] = [];
  50. var k = 0;
  51. for (var i in combinationImages)
  52. {
  53. combinationImagesJS[i] = [];
  54. for (var j in combinationImages[i])
  55. {
  56. var id_image = parseInt(combinationImages[i][j]['id_image']);
  57. if (id_image)
  58. {
  59. combinationImagesJS[0][k++] = id_image;
  60. combinationImagesJS[i][j] = [];
  61. combinationImagesJS[i][j] = id_image;
  62. }
  63. }
  64. }
  65.  
  66. if (typeof combinationImagesJS[0] !== 'undefined' && combinationImagesJS[0])
  67. {
  68. var array_values = [];
  69. for (var key in arrayUnique(combinationImagesJS[0]))
  70. array_values.push(combinationImagesJS[0][key]);
  71. combinationImagesJS[0] = array_values;
  72. }
  73. combinationImages = combinationImagesJS;
  74. }
  75.  
  76. if (typeof combinations !== 'undefined' && combinations)
  77. {
  78. combinationsJS = [];
  79. var k = 0;
  80. for (var i in combinations)
  81. {
  82. globalQuantity += combinations[i]['quantity'];
  83. combinationsJS[k] = [];
  84. combinationsJS[k]['idCombination'] = parseInt(i);
  85. combinationsJS[k]['idsAttributes'] = combinations[i]['attributes'];
  86. combinationsJS[k]['quantity'] = combinations[i]['quantity'];
  87. combinationsJS[k]['price'] = combinations[i]['price'];
  88. combinationsJS[k]['ecotax'] = combinations[i]['ecotax'];
  89. combinationsJS[k]['image'] = parseInt(combinations[i]['id_image']);
  90. combinationsJS[k]['reference'] = combinations[i]['reference'];
  91. combinationsJS[k]['unit_price'] = combinations[i]['unit_impact'];
  92. combinationsJS[k]['minimal_quantity'] = parseInt(combinations[i]['minimal_quantity']);
  93.  
  94. combinationsJS[k]['available_date'] = [];
  95. combinationsJS[k]['available_date']['date'] = combinations[i]['available_date'];
  96. combinationsJS[k]['available_date']['date_formatted'] = combinations[i]['date_formatted'];
  97.  
  98. combinationsJS[k]['specific_price'] = [];
  99. 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;
  100. 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;
  101. 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'];
  102.  
  103. combinationsJS[k]['reduction_type'] = (combinations[i]['specific_price'] && combinations[i]['specific_price']['reduction_type']) ? combinations[i]['specific_price']['reduction_type'] : '';
  104. combinationsJS[k]['id_product_attribute'] = (combinations[i]['specific_price'] && combinations[i]['specific_price']['id_product_attribute']) ? combinations[i]['specific_price']['id_product_attribute'] : 0;
  105. k++;
  106. }
  107. combinations = combinationsJS;
  108. }
  109.  
  110. //init the serialScroll for thumbs
  111. $('#thumbs_list').serialScroll({
  112. items:'li:visible',
  113. prev:'#view_scroll_left',
  114. next:'#view_scroll_right',
  115. axis:'x',
  116. offset:0,
  117. start:0,
  118. stop:true,
  119. onBefore:serialScrollFixLock,
  120. duration:700,
  121. step: 2,
  122. lazy: true,
  123. lock: false,
  124. force:false,
  125. cycle:false
  126. });
  127.  
  128. $('#thumbs_list').trigger('goto', 1);// SerialScroll Bug on goto 0 ?
  129. $('#thumbs_list').trigger('goto', 0);
  130.  
  131. //hover 'other views' images management
  132. $('#views_block li a').hover(
  133. function(){displayImage($(this));},
  134. function(){}
  135. );
  136.  
  137. //set jqZoom parameters if needed
  138. if (typeof(jqZoomEnabled) != 'undefined' && jqZoomEnabled)
  139. {
  140. $('.jqzoom').jqzoom({
  141. zoomType: 'standard', //innerzoom/standard/reverse/drag
  142. zoomWidth: 320, //zooming div default width(default width value is 200)
  143. zoomHeight: 320, //zooming div default width(default height value is 200)
  144. xOffset: 21, //zooming div default offset(default offset value is 10)
  145. yOffset: 0,
  146. title: false
  147. });
  148. }
  149. //add a link on the span 'view full size' and on the big image
  150. $(document).on('click', '#view_full_size, #image-block', function(e){
  151. $('#views_block .shown').click();
  152. });
  153.  
  154. //catch the click on the "more infos" button at the top of the page
  155. $(document).on('click', '#short_description_block .button', function(e){
  156. $('#more_info_tab_more_info').click();
  157. $.scrollTo( '#more_info_tabs', 1200 );
  158. });
  159.  
  160. // Hide the customization submit button and display some message
  161. $(document).on('click', '#customizedDatas input', function(e){
  162. $('#customizedDatas input').hide();
  163. $('#ajax-loader').fadeIn();
  164. $('#customizedDatas').append(uploading_in_progress);
  165. });
  166.  
  167. original_url = window.location + '';
  168. first_url_check = true;
  169. var url_found = checkUrl();
  170. initLocationChange();
  171.  
  172. //init the price in relation of the selected attributes
  173. if (typeof productHasAttributes != 'undefined' && productHasAttributes && !url_found)
  174. findCombination(true);
  175. else if (typeof productHasAttributes != 'undefined' && !productHasAttributes && !url_found)
  176. refreshProductImages(0);
  177.  
  178. $(document).on('click', 'a[name=resetImages]', function(e){
  179. e.preventDefault();
  180. refreshProductImages(0);
  181. });
  182.  
  183. $(document).on('click', '.color_pick', function(e){
  184. e.preventDefault();
  185. colorPickerClick($(this));
  186. getProductAttribute();
  187. });
  188.  
  189. $(document).on('change', '.attribute_select', function(e){
  190. e.preventDefault();
  191. findCombination();
  192. getProductAttribute();
  193. });
  194.  
  195. $(document).on('click', '.attribute_radio', function(e){
  196. e.preventDefault();
  197. findCombination();
  198. getProductAttribute();
  199. });
  200.  
  201. $(document).on('click', 'button[name=saveCustomization]', function(e){
  202. saveCustomization();
  203. });
  204.  
  205. if (contentOnly == false)
  206. {
  207. if(!!$.prototype.fancybox)
  208. $('.fancybox').fancybox({
  209. 'hideOnContentClick': true,
  210. 'openEffect' : 'elastic',
  211. 'closeEffect' : 'elastic'
  212. });
  213. }
  214. else
  215. {
  216. $(document).on('click', '.fancybox', function(e){
  217. e.preventDefault();
  218. });
  219.  
  220. $(document).on('click', '#image-block', function(e){
  221. e.preventDefault();
  222. var productUrl= window.document.location.href + '';
  223. var data = productUrl.replace('content_only=1', '');
  224. window.parent.document.location.href = data;
  225. });
  226.  
  227. if (typeof ajax_allowed != 'undefined' && !ajax_allowed)
  228. $('#buy_block').attr('target', '_top');
  229. }
  230.  
  231. if (!!$.prototype.bxSlider)
  232. $('#bxslider').bxSlider({
  233. minSlides: 1,
  234. maxSlides: 6,
  235. slideWidth: 178,
  236. slideMargin: 20,
  237. pager: false,
  238. nextText: '',
  239. prevText: '',
  240. moveSlides:1,
  241. infiniteLoop:false,
  242. hideControlOnEnd: true
  243. });
  244.  
  245. // The button to increment the product value
  246. $(document).on('click', '.product_quantity_up', function(e){
  247. e.preventDefault();
  248. fieldName = $(this).data('field-qty');
  249. var currentVal = parseInt($('input[name='+fieldName+']').val());
  250. if (quantityAvailable > 0) {
  251. quantityAvailableT = quantityAvailable;
  252. } else {
  253. quantityAvailableT = 100000000;
  254. }
  255. if (!isNaN(currentVal) && currentVal < quantityAvailableT) {
  256. $('input[name='+fieldName+']').val(currentVal + 1).trigger('keyup');
  257. } else {
  258. $('input[name='+fieldName+']').val(quantityAvailableT);
  259. }
  260. });
  261. // The button to decrement the product value
  262. $(document).on('click', '.product_quantity_down', function(e){
  263. e.preventDefault();
  264. fieldName = $(this).data('field-qty');
  265. var currentVal = parseInt($('input[name='+fieldName+']').val());
  266. if (!isNaN(currentVal) && currentVal > 1) {
  267. $('input[name='+fieldName+']').val(currentVal - 1).trigger('keyup');
  268. } else {
  269. $('input[name='+fieldName+']').val(1);
  270. }
  271. });
  272.  
  273. if (typeof minimalQuantity != 'undefined' && minimalQuantity)
  274. {
  275. checkMinimalQuantity();
  276. $(document).on('keyup', 'input[name=qty]', function(e){
  277. checkMinimalQuantity(minimalQuantity);
  278. });
  279. }
  280.  
  281. if (typeof ad !== 'undefined' && ad && typeof adtoken !== 'undefined' && adtoken)
  282. {
  283. $(document).on('click', 'input[name=publish_button]', function(e){
  284. e.preventDefault();
  285. submitPublishProduct(ad, 0, adtoken);
  286. });
  287. $(document).on('click', 'input[name=lnk_view]', function(e){
  288. e.preventDefault();
  289. submitPublishProduct(ad, 1, adtoken);
  290. });
  291. }
  292. });
  293.  
  294. function arrayUnique(a)
  295. {
  296. return a.reduce(function(p, c){
  297. if (p.indexOf(c) < 0)
  298. p.push(c);
  299. return p;
  300. }, []);
  301. };
  302.  
  303. //check if a function exists
  304. function function_exists(function_name)
  305. {
  306. if (typeof function_name == 'string')
  307. return (typeof window[function_name] == 'function');
  308. return (function_name instanceof Function);
  309. }
  310.  
  311. //execute oosHook js code
  312. function oosHookJsCode()
  313. {
  314. for (var i = 0; i < oosHookJsCodeFunctions.length; i++)
  315. {
  316. if (function_exists(oosHookJsCodeFunctions[i]))
  317. setTimeout(oosHookJsCodeFunctions[i] + '()', 0);
  318. }
  319. }
  320.  
  321. //add a combination of attributes in the global JS sytem
  322. function addCombination(idCombination, arrayOfIdAttributes, quantity, price, ecotax, id_image, reference, unit_price, minimal_quantity, available_date, combination_specific_price)
  323. {
  324. globalQuantity += quantity;
  325.  
  326. var combination = [];
  327. combination['idCombination'] = idCombination;
  328. combination['quantity'] = quantity;
  329. combination['idsAttributes'] = arrayOfIdAttributes;
  330. combination['price'] = price;
  331. combination['ecotax'] = ecotax;
  332. combination['image'] = id_image;
  333. combination['reference'] = reference;
  334. combination['unit_price'] = unit_price;
  335. combination['minimal_quantity'] = minimal_quantity;
  336. combination['available_date'] = [];
  337. combination['available_date'] = available_date;
  338. combination['specific_price'] = [];
  339. combination['specific_price'] = combination_specific_price;
  340. combinations.push(combination);
  341. }
  342.  
  343. // search the combinations' case of attributes and update displaying of availability, prices, ecotax, and image
  344. function findCombination(firstTime)
  345. {
  346. $('#minimal_quantity_wanted_p').fadeOut();
  347. if (typeof $('#minimal_quantity_label').text() === 'undefined' || $('#minimal_quantity_label').html() > 1)
  348. $('#quantity_wanted').val(1);
  349.  
  350. //create a temporary 'choice' array containing the choices of the customer
  351. var choice = [];
  352. $('#attributes select, #attributes input[type=hidden], #attributes input[type=radio]:checked').each(function(){
  353. choice.push(parseInt($(this).val()));
  354. });
  355.  
  356. if (typeof combinations == 'undefined' || !combinations)
  357. combinations = [];
  358. //testing every combination to find the conbination's attributes' case of the user
  359. for (var combination = 0; combination < combinations.length; ++combination)
  360. {
  361. //verify if this combinaison is the same that the user's choice
  362. var combinationMatchForm = true;
  363. $.each(combinations[combination]['idsAttributes'], function(key, value)
  364. {
  365. if (!in_array(parseInt(value), choice))
  366. combinationMatchForm = false;
  367. });
  368.  
  369. if (combinationMatchForm)
  370. {
  371. if (combinations[combination]['minimal_quantity'] > 1)
  372. {
  373. $('#minimal_quantity_label').html(combinations[combination]['minimal_quantity']);
  374. $('#minimal_quantity_wanted_p').fadeIn();
  375. $('#quantity_wanted').val(combinations[combination]['minimal_quantity']);
  376. $('#quantity_wanted').bind('keyup', function() {checkMinimalQuantity(combinations[combination]['minimal_quantity']);});
  377. }
  378. //combination of the user has been found in our specifications of combinations (created in back office)
  379. selectedCombination['unavailable'] = false;
  380. selectedCombination['reference'] = combinations[combination]['reference'];
  381. $('#idCombination').val(combinations[combination]['idCombination']);
  382.  
  383. //get the data of product with these attributes
  384. quantityAvailable = combinations[combination]['quantity'];
  385. selectedCombination['price'] = combinations[combination]['price'];
  386. selectedCombination['unit_price'] = combinations[combination]['unit_price'];
  387. selectedCombination['specific_price'] = combinations[combination]['specific_price'];
  388. if (combinations[combination]['ecotax'])
  389. selectedCombination['ecotax'] = combinations[combination]['ecotax'];
  390. else
  391. selectedCombination['ecotax'] = default_eco_tax;
  392.  
  393. //show the large image in relation to the selected combination
  394. if (combinations[combination]['image'] && combinations[combination]['image'] != -1)
  395. displayImage($('#thumb_' + combinations[combination]['image']).parent());
  396.  
  397. //show discounts values according to the selected combination
  398. if (combinations[combination]['idCombination'] && combinations[combination]['idCombination'] > 0)
  399. displayDiscounts(combinations[combination]['idCombination']);
  400.  
  401. //get available_date for combination product
  402. selectedCombination['available_date'] = combinations[combination]['available_date'];
  403.  
  404. //update the display
  405. updateDisplay();
  406.  
  407. if(typeof(firstTime) != 'undefined' && firstTime)
  408. refreshProductImages(0);
  409. else
  410. refreshProductImages(combinations[combination]['idCombination']);
  411. //leave the function because combination has been found
  412. return;
  413. }
  414. }
  415. //this combination doesn't exist (not created in back office)
  416. selectedCombination['unavailable'] = true;
  417. if (typeof(selectedCombination['available_date']) != 'undefined')
  418. delete selectedCombination['available_date'];
  419. updateDisplay();
  420. }
  421.  
  422. //update display of the availability of the product AND the prices of the product
  423. function updateDisplay()
  424. {
  425. var productPriceDisplay = productPrice;
  426. var productPriceWithoutReductionDisplay = productPriceWithoutReduction;
  427.  
  428. if (!selectedCombination['unavailable'] && quantityAvailable > 0 && productAvailableForOrder == 1)
  429. {
  430. //show the choice of quantities
  431. $('#quantity_wanted_p:hidden').show('slow');
  432.  
  433. //show the "add to cart" button ONLY if it was hidden
  434. $('#add_to_cart:hidden').fadeIn(600);
  435.  
  436. //hide the hook out of stock
  437. $('#oosHook').hide();
  438.  
  439. $('#availability_date').fadeOut();
  440.  
  441. //availability value management
  442. if (availableNowValue != '')
  443. {
  444. //update the availability statut of the product
  445. $('#availability_value').removeClass('warning_inline');
  446. $('#availability_value').text(availableNowValue);
  447. if(stock_management == 1)
  448. $('#availability_statut:hidden').show();
  449. }
  450. else
  451. $('#availability_statut:visible').hide();
  452.  
  453. //'last quantities' message management
  454. if (!allowBuyWhenOutOfStock)
  455. {
  456. if (quantityAvailable <= maxQuantityToAllowDisplayOfLastQuantityMessage)
  457. $('#last_quantities').show('slow');
  458. else
  459. $('#last_quantities').hide('slow');
  460. }
  461.  
  462. if (quantitiesDisplayAllowed)
  463. {
  464. $('#pQuantityAvailable:hidden').show('slow');
  465. $('#quantityAvailable').text(quantityAvailable);
  466.  
  467. if (quantityAvailable < 2) // we have 1 or less product in stock and need to show "item" instead of "items"
  468. {
  469. $('#quantityAvailableTxt').show();
  470. $('#quantityAvailableTxtMultiple').hide();
  471. }
  472. else
  473. {
  474. $('#quantityAvailableTxt').hide();
  475. $('#quantityAvailableTxtMultiple').show();
  476. }
  477. }
  478. }
  479. else
  480. {
  481. //show the hook out of stock
  482. if (productAvailableForOrder == 1)
  483. {
  484. $('#oosHook').show();
  485. if ($('#oosHook').length > 0 && function_exists('oosHookJsCode'))
  486. oosHookJsCode();
  487. }
  488.  
  489. //hide 'last quantities' message if it was previously visible
  490. $('#last_quantities:visible').hide('slow');
  491.  
  492. //hide the quantity of pieces if it was previously visible
  493. $('#pQuantityAvailable:visible').hide('slow');
  494.  
  495. //hide the choice of quantities
  496. if (!allowBuyWhenOutOfStock)
  497. $('#quantity_wanted_p:visible').hide('slow');
  498.  
  499. //display that the product is unavailable with theses attributes
  500. if (!selectedCombination['unavailable'])
  501. $('#availability_value').text(doesntExistNoMore + (globalQuantity > 0 ? ' ' + doesntExistNoMoreBut : '')).addClass('warning_inline');
  502. else
  503. {
  504. $('#availability_value').text(doesntExist).addClass('warning_inline');
  505. $('#oosHook').hide();
  506. }
  507. if(stock_management == 1 && !allowBuyWhenOutOfStock)
  508. $('#availability_statut:hidden').show();
  509.  
  510. if (typeof(selectedCombination['available_date']) != 'undefined' && selectedCombination['available_date']['date'].length != 0)
  511. {
  512. var available_date = selectedCombination['available_date']['date'];
  513. var tab_date = available_date.split('-');
  514. var time_available = new Date(tab_date[0], tab_date[1], tab_date[2]);
  515. time_available.setMonth(time_available.getMonth()-1);
  516. var now = new Date();
  517. if (now.getTime() < time_available.getTime() && $('#availability_date_value').text() != selectedCombination['available_date']['date_formatted'])
  518. {
  519. $('#availability_date').fadeOut('normal', function(){
  520. $('#availability_date_value').text(selectedCombination['available_date']['date_formatted']);
  521. $(this).fadeIn();
  522. });
  523. }
  524. else if(now.getTime() < time_available.getTime())
  525. $('#availability_date').fadeIn();
  526. }
  527. else
  528. $('#availability_date').fadeOut();
  529.  
  530. //show the 'add to cart' button ONLY IF it's possible to buy when out of stock AND if it was previously invisible
  531. if (allowBuyWhenOutOfStock && !selectedCombination['unavailable'] && productAvailableForOrder == 1)
  532. {
  533. $('#add_to_cart:hidden').fadeIn(600);
  534.  
  535. if (availableLaterValue != '')
  536. {
  537. $('#availability_value').text(availableLaterValue);
  538. if(stock_management == 1)
  539. $('#availability_statut:hidden').show('slow');
  540. }
  541. else
  542. $('#availability_statut:visible').hide('slow');
  543. }
  544. else
  545. {
  546. $('#add_to_cart:visible').fadeOut(600);
  547. if(stock_management == 1)
  548. $('#availability_statut:hidden').show('slow');
  549. }
  550.  
  551. if (productAvailableForOrder == 0)
  552. $('#availability_statut:visible').hide();
  553. }
  554.  
  555. if (selectedCombination['reference'] || productReference)
  556. {
  557. if (selectedCombination['reference'])
  558. $('#product_reference span').text(selectedCombination['reference']);
  559. else if (productReference)
  560. $('#product_reference span').text(productReference);
  561. $('#product_reference:hidden').show('slow');
  562. }
  563. else
  564. $('#product_reference:visible').hide('slow');
  565.  
  566. //update display of the the prices in relation to tax, discount, ecotax, and currency criteria
  567. if (!selectedCombination['unavailable'] && productShowPrice == 1)
  568. {
  569. // retrieve price without group_reduction in order to compute the group reduction after
  570. // the specific price discount (done in the JS in order to keep backward compatibility)
  571.  
  572. var tax = (taxRate / 100) + 1;
  573.  
  574. combID = $('#idCombination').val();
  575. comb2 = combinationsFromController[combID];
  576. if (comb2.price != 0)
  577. {
  578. var taxExclPrice = productPriceTaxExcluded + comb2.price;
  579. productPriceWithoutReductionDisplay = productPriceWithoutReductionDisplay + (comb2.price * tax);
  580. }
  581. else
  582. var taxExclPrice = productPriceTaxExcluded;
  583.  
  584.  
  585. if (!displayPrice && !noTaxForThisProduct)
  586. productPriceDisplay = ps_round(taxExclPrice * tax, 2); // Need to be global => no var
  587. else
  588. productPriceDisplay = ps_round(taxExclPrice, 2); // Need to be global => no var
  589.  
  590. var reduction = 0;
  591. if (selectedCombination['specific_price'].reduction_price || selectedCombination['specific_price'].reduction_percent)
  592. {
  593. reduction_price = (specific_currency ? selectedCombination['specific_price'].reduction_price : selectedCombination['specific_price'].reduction_price * currencyRate);
  594. reduction = productPriceDisplay * (parseFloat(selectedCombination['specific_price'].reduction_percent) / 100) + reduction_price;
  595. if (reduction_price && (displayPrice || noTaxForThisProduct))
  596. reduction = ps_round(reduction / tax, 6);
  597.  
  598. }
  599. else if (product_specific_price && product_specific_price.reduction && !selectedCombination.specific_price)
  600. {
  601. if (product_specific_price.reduction_type == 'amount')
  602. reduction_price = (specific_currency ? product_specific_price.reduction : product_specific_price.reduction * currencyRate);
  603. else
  604. reduction_price = 0;
  605.  
  606. if (product_specific_price.reduction_type == 'percentage')
  607. reduction_percent = productPriceDisplay * parseFloat(product_specific_price.reduction);
  608.  
  609. reduction = reduction_price + reduction_percent;
  610. if (reduction_price && (displayPrice || noTaxForThisProduct))
  611. reduction = ps_round(reduction / tax, 6);
  612. }
  613.  
  614. if (selectedCombination.specific_price)
  615. {
  616. if (selectedCombination.specific_price.reduction_percent > 0) {
  617. $('#reduction_amount').hide();
  618. $('#reduction_percent_display').html('-' + parseFloat(selectedCombination['specific_price'].reduction_percent) + '%');
  619. $('#reduction_percent').show();
  620. } else if (selectedCombination.specific_price.reduction_price > 0) {
  621. $('#reduction_amount_display').html('-' + formatCurrency(reduction_price, currencyFormat, currencySign, currencyBlank));
  622. $('#reduction_percent').hide();
  623. $('#reduction_amount').show();
  624. } else {
  625. $('#reduction_percent').hide();
  626. $('#reduction_amount').hide();
  627. }
  628. }
  629.  
  630. if (product_specific_price['reduction_type'] != '' || selectedCombination.specific_price.reduction_percent > 0 || selectedCombination.specific_price.reduction_price > 0)
  631. $('#discount_reduced_price,#old_price').show();
  632. else
  633. $('#discount_reduced_price,#old_price').hide();
  634. if ((product_specific_price['reduction_type'] == 'percentage' && selectedCombination.specific_price.reduction_percent > 0) || selectedCombination['specific_price'].reduction_type == 'percentage')
  635. $('#reduction_percent').show();
  636. else
  637. $('#reduction_percent').hide();
  638. if (product_specific_price['price'] || (selectedCombination.specific_price && selectedCombination.specific_price['price']))
  639. $('#not_impacted_by_discount').show();
  640. else
  641. $('#not_impacted_by_discount').hide();
  642.  
  643.  
  644. productPriceDisplay -= reduction;
  645. productPriceDisplay = ps_round(productPriceDisplay * (1 - group_reduction), 2);
  646.  
  647. var ecotaxAmount = !displayPrice ? ps_round(selectedCombination['ecotax'] * (1 + ecotaxTax_rate / 100), 2) : selectedCombination['ecotax'];
  648.  
  649. if (ecotaxAmount != default_eco_tax)
  650. productPriceDisplay += ecotaxAmount - default_eco_tax;
  651. else
  652. productPriceDisplay += ecotaxAmount;
  653.  
  654. if (ecotaxAmount != default_eco_tax)
  655. productPriceWithoutReductionDisplay += ecotaxAmount - default_eco_tax;
  656. else
  657. productPriceWithoutReductionDisplay += ecotaxAmount;
  658.  
  659. var our_price = '';
  660. if (productPriceDisplay > 0) {
  661. our_price = formatCurrency(productPriceDisplay, currencyFormat, currencySign, currencyBlank);
  662. } else {
  663. our_price = formatCurrency(0, currencyFormat, currencySign, currencyBlank);
  664. }
  665.  
  666. $('#our_price_display').text(our_price);
  667. $('#old_price_display').text(formatCurrency(productPriceWithoutReductionDisplay, currencyFormat, currencySign, currencyBlank));
  668.  
  669. if (productPriceWithoutReductionDisplay > productPriceDisplay)
  670. $('#old_price,#old_price_display,#old_price_display_taxes').show();
  671. else
  672. $('#old_price,#old_price_display,#old_price_display_taxes').hide();
  673. // Special feature: "Display product price tax excluded on product page"
  674. var productPricePretaxed = '';
  675. if (!noTaxForThisProduct)
  676. productPricePretaxed = productPriceDisplay / tax;
  677. else
  678. productPricePretaxed = productPriceDisplay;
  679. $('#pretaxe_price_display').text(formatCurrency(productPricePretaxed, currencyFormat, currencySign, currencyBlank));
  680. // Unit price
  681. productUnitPriceRatio = parseFloat(productUnitPriceRatio);
  682. if (productUnitPriceRatio > 0 )
  683. {
  684. newUnitPrice = (productPriceDisplay / parseFloat(productUnitPriceRatio)) + parseFloat(selectedCombination['unit_price']);
  685. $('#unit_price_display').text(formatCurrency(newUnitPrice, currencyFormat, currencySign, currencyBlank));
  686. }
  687.  
  688. // Ecotax
  689. ecotaxAmount = !displayPrice ? ps_round(selectedCombination['ecotax'] * (1 + ecotaxTax_rate / 100), 2) : selectedCombination['ecotax'];
  690. $('#ecotax_price_display').text(formatCurrency(ecotaxAmount, currencyFormat, currencySign, currencyBlank));
  691.  
  692.  
  693. updateDiscountTable(productPriceDisplay);
  694.  
  695. }
  696. }
  697.  
  698. //update display of the large image
  699. function displayImage(domAAroundImgThumb, no_animation)
  700. {
  701. if (typeof(no_animation) == 'undefined')
  702. no_animation = false;
  703. if (domAAroundImgThumb.prop('href'))
  704. {
  705. var new_src = domAAroundImgThumb.attr('href').replace('thickbox', 'large');
  706. var new_title = domAAroundImgThumb.attr('title');
  707. var new_href = domAAroundImgThumb.attr('href');
  708. if ($('#bigpic').prop('src') != new_src)
  709. {
  710. $('#bigpic').attr({
  711. 'src' : new_src,
  712. 'alt' : new_title,
  713. 'title' : new_title
  714. }).load(function(){
  715. if (typeof(jqZoomEnabled) != 'undefined' && jqZoomEnabled)
  716. $(this).attr('rel', new_href);
  717. });
  718. }
  719. $('#views_block li a').removeClass('shown');
  720. $(domAAroundImgThumb).addClass('shown');
  721. }
  722. }
  723.  
  724. //update display of the discounts table
  725. function displayDiscounts(combination)
  726. {
  727. $('#quantityDiscount tbody tr').each(function(){
  728. if (($(this).attr('id') != 'quantityDiscount_0') &&
  729. ($(this).attr('id') != 'quantityDiscount_' + combination) &&
  730. ($(this).attr('id') != 'noQuantityDiscount'))
  731. $(this).fadeOut('slow');
  732. });
  733.  
  734. if ($('#quantityDiscount_' + combination+',.quantityDiscount_' + combination).length != 0
  735. || $('#quantityDiscount_0,.quantityDiscount_0').length != 0)
  736. {
  737. $('#quantityDiscount').parent().show();
  738. $('#quantityDiscount_' + combination+',.quantityDiscount_' + combination).show();
  739. $('#noQuantityDiscount').hide();
  740. }
  741. else
  742. {
  743. $('#quantityDiscount').parent().hide();
  744. $('#noQuantityDiscount').show();
  745. }
  746. }
  747.  
  748. function updateDiscountTable(newPrice)
  749. {
  750. $('#quantityDiscount tbody tr').each(function(){
  751. var type = $(this).data("discount-type");
  752. var discount = $(this).data("discount");
  753. var quantity = $(this).data("discount-quantity");
  754.  
  755. if (type == 'percentage')
  756. {
  757. var discountedPrice = newPrice * (1 - discount/100);
  758. var discountUpTo = newPrice * (discount/100) * quantity;
  759. }
  760. else if (type == 'amount')
  761. {
  762. var discountedPrice = newPrice - discount;
  763. var discountUpTo = discount * quantity;
  764. }
  765.  
  766. if (displayDiscountPrice != 0)
  767. $(this).children('td').eq(1).text( formatCurrency(discountedPrice, currencyFormat, currencySign, currencyBlank) );
  768. $(this).children('td').eq(2).text(upToTxt + ' ' + formatCurrency(discountUpTo, currencyFormat, currencySign, currencyBlank));
  769. });
  770. }
  771.  
  772. // Serialscroll exclude option bug ?
  773. function serialScrollFixLock(event, targeted, scrolled, items, position)
  774. {
  775. serialScrollNbImages = $('#thumbs_list li:visible').length;
  776. serialScrollNbImagesDisplayed = 3;
  777.  
  778. var leftArrow = position == 0 ? true : false;
  779. var rightArrow = position + serialScrollNbImagesDisplayed >= serialScrollNbImages ? true : false;
  780.  
  781. $('#view_scroll_left').css('cursor', leftArrow ? 'default' : 'pointer').css('display', leftArrow ? 'none' : 'block').fadeTo(0, leftArrow ? 0 : 1);
  782. $('#view_scroll_right').css('cursor', rightArrow ? 'default' : 'pointer').fadeTo(0, rightArrow ? 0 : 1).css('display', rightArrow ? 'none' : 'block');
  783. return true;
  784. }
  785.  
  786. // Change the current product images regarding the combination selected
  787. function refreshProductImages(id_product_attribute)
  788. {
  789. $('#thumbs_list_frame').scrollTo('li:eq(0)', 700, {axis:'x'});
  790.  
  791. id_product_attribute = parseInt(id_product_attribute);
  792.  
  793. if (id_product_attribute > 0 && typeof(combinationImages) != 'undefined' && typeof(combinationImages[id_product_attribute]) != 'undefined')
  794. {
  795. $('#thumbs_list li').hide();
  796. $('#thumbs_list').trigger('goto', 0);
  797. for (var i = 0; i < combinationImages[id_product_attribute].length; i++)
  798. if (typeof(jqZoomEnabled) != 'undefined' && jqZoomEnabled)
  799. $('#thumbnail_' + parseInt(combinationImages[id_product_attribute][i])).show().children('a.shown').trigger('click');
  800. else
  801. $('#thumbnail_' + parseInt(combinationImages[id_product_attribute][i])).show();
  802. }
  803. else
  804. $('#thumbs_list li').show();
  805.  
  806. if (parseInt($('#thumbs_list_frame >li:visible').length) != parseInt($('#thumbs_list_frame >li').length))
  807. $('#wrapResetImages').stop(true, true).show();
  808. else
  809. $('#wrapResetImages').stop(true, true).hide();
  810.  
  811. var thumb_width = $('#thumbs_list_frame >li').width() + parseInt($('#thumbs_list_frame >li').css('marginRight'));
  812. $('#thumbs_list_frame').width((parseInt((thumb_width) * $('#thumbs_list_frame >li').length)) + 'px');
  813. $('#thumbs_list').trigger('goto', 0);
  814. serialScrollFixLock('', '', '', '', 0);// SerialScroll Bug on goto 0 ?
  815. }
  816.  
  817. function saveCustomization()
  818. {
  819. $('#quantityBackup').val($('#quantity_wanted').val());
  820. customAction = $('#customizationForm').attr('action');
  821. $('body select[id^="group_"]').each(function() {
  822. customAction = customAction.replace(new RegExp(this.id + '=\\d+'), this.id +'=' + this.value);
  823. });
  824. $('#customizationForm').attr('action', customAction);
  825. $('#customizationForm').submit();
  826. }
  827.  
  828. function submitPublishProduct(url, redirect, token)
  829. {
  830. var id_product = $('#admin-action-product-id').val();
  831.  
  832. $.ajaxSetup({async: false});
  833. $.post(url + '/index.php', {
  834. action:'publishProduct',
  835. id_product: id_product,
  836. status: 1,
  837. redirect: redirect,
  838. ajax: 1,
  839. tab: 'AdminProducts',
  840. token: token
  841. },
  842. function(data)
  843. {
  844. if (data.indexOf('error') === -1)
  845. document.location.href = data;
  846. }
  847. );
  848. return true;
  849. }
  850.  
  851. function checkMinimalQuantity(minimal_quantity)
  852. {
  853. if ($('#quantity_wanted').val() < minimal_quantity)
  854. {
  855. $('#quantity_wanted').css('border', '1px solid red');
  856. $('#minimal_quantity_wanted_p').css('color', 'red');
  857. }
  858. else
  859. {
  860. $('#quantity_wanted').css('border', '1px solid #BDC2C9');
  861. $('#minimal_quantity_wanted_p').css('color', '#374853');
  862. }
  863. }
  864.  
  865. function colorPickerClick(elt)
  866. {
  867. id_attribute = $(elt).attr('id').replace('color_', '');
  868. $(elt).parent().parent().children().removeClass('selected');
  869. $(elt).fadeTo('fast', 1, function(){
  870. $(this).fadeTo('fast', 0, function(){
  871. $(this).fadeTo('fast', 1, function(){
  872. $(this).parent().addClass('selected');
  873. });
  874. });
  875. });
  876. $(elt).parent().parent().parent().children('.color_pick_hidden').val(id_attribute);
  877. findCombination(false);
  878. }
  879.  
  880.  
  881. function getProductAttribute()
  882. {
  883. // get product attribute id
  884. product_attribute_id = $('#idCombination').val();
  885. product_id = $('#product_page_product_id').val();
  886.  
  887. // get every attributes values
  888. request = '';
  889. //create a temporary 'tab_attributes' array containing the choices of the customer
  890. var tab_attributes = [];
  891. $('#attributes select, #attributes input[type=hidden], #attributes input[type=radio]:checked').each(function(){
  892. tab_attributes.push($(this).val());
  893. });
  894.  
  895. // build new request
  896. for (var i in attributesCombinations)
  897. for (var a in tab_attributes)
  898. if (attributesCombinations[i]['id_attribute'] === tab_attributes[a])
  899. request += '/'+attributesCombinations[i]['group'] + attribute_anchor_separator + attributesCombinations[i]['attribute'];
  900. request = request.replace(request.substring(0, 1), '#/');
  901. url = window.location + '';
  902.  
  903. // redirection
  904. if (url.indexOf('#') != -1)
  905. url = url.substring(0, url.indexOf('#'));
  906.  
  907. // set ipa to the customization form
  908. $('#customizationForm').attr('action', $('#customizationForm').attr('action') + request);
  909. window.location = url + request;
  910. }
  911.  
  912. function initLocationChange(time)
  913. {
  914. if(!time) time = 500;
  915. setInterval(checkUrl, time);
  916. }
  917.  
  918. function checkUrl()
  919. {
  920. if (original_url != window.location || first_url_check)
  921. {
  922. first_url_check = false;
  923. url = window.location + '';
  924. // if we need to load a specific combination
  925. if (url.indexOf('#/') != -1)
  926. {
  927. // get the params to fill from a "normal" url
  928. params = url.substring(url.indexOf('#') + 1, url.length);
  929. tabParams = params.split('/');
  930. tabValues = [];
  931. if (tabParams[0] == '')
  932. tabParams.shift();
  933. for (var i in tabParams)
  934. tabValues.push(tabParams[i].split(attribute_anchor_separator));
  935. product_id = $('#product_page_product_id').val();
  936. // fill html with values
  937. $('.color_pick').removeClass('selected');
  938. $('.color_pick').parent().parent().children().removeClass('selected');
  939. count = 0;
  940. for (var z in tabValues)
  941. for (var a in attributesCombinations)
  942. if (attributesCombinations[a]['group'] === decodeURIComponent(tabValues[z][0])
  943. && attributesCombinations[a]['attribute'] === tabValues[z][1])
  944. {
  945. count++;
  946. // add class 'selected' to the selected color
  947. $('#color_' + attributesCombinations[a]['id_attribute']).addClass('selected');
  948. $('#color_' + attributesCombinations[a]['id_attribute']).parent().addClass('selected');
  949. $('input:radio[value=' + attributesCombinations[a]['id_attribute'] + ']').attr('checked', true);
  950. $('input[type=hidden][name=group_' + attributesCombinations[a]['id_attribute_group'] + ']').val(attributesCombinations[a]['id_attribute']);
  951. $('select[name=group_' + attributesCombinations[a]['id_attribute_group'] + ']').val(attributesCombinations[a]['id_attribute']);
  952. }
  953. // find combination
  954. if (count >= 0)
  955. {
  956. findCombination(false);
  957. original_url = url;
  958. return true;
  959. }
  960. // no combination found = removing attributes from url
  961. else
  962. window.location = url.substring(0, url.indexOf('#'));
  963. }
  964. }
  965. return false;
  966. }
Advertisement
Add Comment
Please, Sign In to add comment