1/* 2 * mini cart 3 */ 4(function($) { 5 6 var stTotalPrice = 0; 7 var stTotalQty = 0; 8 var stPrevShip = 0; 9 var stPrevTax = 0; 10 var lstProducts = new Array(); 11 var removed = 0; 12 13 function cart_AddProduct(product , qty) 14 { 15 if (!$('#cart_no_products').length) 16 { 17 return; 18 } 19 20 $('#cart_no_products').css('display', 'none'); 21 $('#order_buttons').css('display', 'block'); 22 23 $('#minicart_summary').css('display', 'block'); 24 $('#minicart').css('display', 'block'); 25 26 bFound = false; 27 28 for (i = 0; i < lstProducts.length; i++) 29 { 30 if (lstProducts[i].hash == product.hash) 31 { 32 bFound = true; 33 34 if (!qty) 35 { 36 lstProducts[i].qty += Math.floor(product.qty); 37 } 38 else 39 { 40 lstProducts[i].qty = qty; 41 } 42 43 $('#qty_'+ product.hash).val(lstProducts[i].qty); 44 id = i; 45 46 break; 47 } 48 } 49 50 pOptions = '<ul>'; 51 52 for (i = 0; i < product.optionList.length; i++) 53 { 54 if (product.optionList[i].type == Shout.configuration.module.store.cart.mini.product_option_types.price) 55 { 56 pOptions += '<li>' + product.optionList[i].name + ': ' + formatCurrency(product.optionList[i].label) + '</li>'; 57 } 58 else 59 { 60 pOptions += '<li>' + product.optionList[i].name + ': ' + product.optionList[i].label + '</li>'; 61 } 62 } 63 64 pOptions += '</ul>'; 65 66 pConfiguration = '<ul>'; 67 68 for (i = 0; i < product.configList.length; i++) 69 { 70 pOptions += '<li>' + product.configList[i].title + '</li>'; 71 } 72 73 pConfiguration += '</ul>'; 74 75 if (!bFound) 76 { 77 id = lstProducts.length; 78 79 if (Shout.configuration.module.store.cart.mini.store_mode_checkout) 80 { 81 qty = 'QTY ' + product.qty; 82 } 83 else 84 { 85 qty = 'QTY <input id="qty_'+ product.hash +'" size="2" name="qty['+ product.hash +']" value="'+ product.qty +'" />'; 86 } 87 88 pic = ''; 89 90 if (product.pic != '') 91 { 92 pic = '<img src="' + product.pic + '" />'; 93 } 94 95 divObj = document.createElement('div'); 96 divObj.innerHTML = '<div id="product_'+ product.hash +'">'+ eval(Shout.configuration.module.store.cart.mini.cell) +'</div>'; 97 $('#minicart_product_list').append(divObj); 98 99 lstProducts[ id ] = product; 100 } 101 102 $('#product_' + product.hash).css('display', 'block'); 103 104 stTotalPrice += product.adjustedPrice * product.qty; 105 stTotalQty += product.qty; 106 107 _renderTotalPrice(stTotalPrice); 108 _renderTotalItems(stTotalQty); 109 } 110 111 function _isNumeric(n) 112 { 113 return !isNaN(parseFloat(n)) && isFinite(n); 114 } 115 116 function _renderTotalPrice(price) 117 { 118 if ($('#minicart_product_total').length) 119 { 120 if (price) 121 { 122 if (_isNumeric(price)) 123 { 124 $('#minicart_product_total').html('Total Price: ' + formatCurrency(price)); 125 } 126 else 127 { 128 $('#minicart_product_total').html('Total Price: ' + price); 129 } 130 } 131 else 132 { 133 $('#minicart_product_total').html(''); 134 } 135 } 136 } 137 138 function _renderTotalItems(qty) 139 { 140 // console.log(qty); 141 142 if ($('#minicart_qty_total').length) 143 { 144 if (qty) 145 { 146 $('#minicart_qty_total').html('Total Items: ' + qty); 147 } 148 else 149 { 150 $('#minicart_qty_total').html(''); 151 } 152 } 153 } 154 155 function cart_changeQTY(noSubmit) 156 { 157 var product; 158 var qty; 159 var diffQy; 160 161 removed = 0; 162 for (var i = 0; i < lstProducts.length; i++) 163 { 164 product = lstProducts[ i ]; 165 166 if (product.qty > 0) 167 { 168 qty = parseInt($('#qty_' + product.hash).val()); 169 170 if (isNaN(qty)) 171 { 172 qty = 0; 173 } 174 175 $('#qty_' + product.hash).val(qty); 176
177 diffQy = parseInt(qty) - parseInt(product.qty); 178 stTotalPrice += diffQy * product.adjustedPrice; 179 180 stTotalQty += diffQy; 181 182 lstProducts[ i ].qty = qty; 183 184 if (qty == 0) 185 { 186 $('#product_' + product.hash).css('display', 'none'); 187 removed++; 188 } 189 } 190 191 if (removed == lstProducts.length) 192 { 193 $('#order_buttons').css('display', 'none'); 194 $('#cart_no_products').css('display', 'block'); 195 196 $('#minicart_summary').css('display', 'none'); 197 $('#minicart').css('display', 'none'); 198 } 199 } 200 201 if ($('#minicart_product_total').length) 202 { 203 $('#minicart_product_total').html("Total Price: Working..."); 204 } 205 206 _renderTotalPrice('Working...'); 207 _renderTotalItems(stTotalQty); 208 209 if (!noSubmit) 210 { 211 $('#updateCart').submit(); 212 } 213 } 214 215 function cart_AddToCartFormReset(id) 216 { 217 var selector; 218 219 if (id != null) 220 { 221 selector = "#add_to_cart-"+id+"-form"; 222 } 223 else 224 { 225 selector = "#add_to_cart-form"; 226 } 227 228 var $form = $(selector); 229 230 $form.get(0).reset(); 231 } 232 233 function cart_Message(msg, id) 234 { 235 if (id != null) 236 { 237 $("#add_to_cart-"+id+"-cart_Add_Message").html(msg); 238 } 239 else 240 { 241 if ($('#cart_Add_Message').length > 0) 242 { 243 $('#cart_Add_Message').html(msg); 244 } 245 else 246 { 247 $('#minicart_feedback').html(msg); 248 } 249 } 250 } 251 252 function cart_ButtonUpdate(status, id) 253 { 254 if (id != null) 255 { 256 $("#add_to_cart-"+id+"-form").removeClass('add_to_cart-form--adding'); 257 258 if ('success' === status) 259 { 260 $("#add_to_cart-"+id+"-form").addClass('add_to_cart-form--success'); 261 } 262 else if ('failed' === status) 263 { 264 $("#add_to_cart-"+id+"-form").addClass('add_to_cart-form--failed'); 265 } 266 267 setTimeout(function(){ 268 269 $("#add_to_cart-"+id+"-form").removeClass('add_to_cart-form--adding add_to_cart-form--success add_to_cart-form--failed add_to_cart-form--cart add_to_cart-form--quote'); 270 271 }, 3000); 272 } 273 else 274 { 275 console.log('noid:'+id); 276 } 277 } 278 279 function cart_updateOrderShipping(price) 280 { 281 if (!$('#minicart_ship').length) 282 { 283 return; 284 } 285 286 $('#minicart_ship').html('Shipping:' + formatCurrency(price)); 287 288 stTotalPrice -= stPrevShip; 289 290 _updateTotal( price ); 291 stPrevShip = price; 292 } 293 294 function cart_updateOrderTaxes(tax) 295 { 296 var taxTotal = 0; 297 298 if (!$('#minicart_tax').length) 299 { 300 return; 301 } 302 303 $('#minicart_tax').html(''); 304 305 for (i = 0; i < tax.length; i++) 306 { 307 $('#minicart_tax').html($('#minicart_tax').html() + tax[i].name + ' ' + formatCurrency(tax[i].amount) + '<br>'); 308 taxTotal = tax[i].amount * 1; 309 } 310 311 stTotalPrice -= stPrevTax; 312 stPrevTax = taxTotal; 313 _updateTotal(taxTotal); 314 } 315 316 function _updateTotal(total) 317 { 318 stTotalPrice += total; 319 320 if (!$('#minicart_product_total').length) 321 { 322 return; 323 } 324 325 _renderTotalPrice(stTotalPrice); 326 } 327 328 function cart_Update(prices) 329 { 330 stTotalPrice = 0; 331 stTotalQty = 0; 332 333 for (var i = 0; i < prices.length; i++) 334 { 335 stTotalPrice += prices[i][0] * $('#qty_' + prices[i][1]).val(); 336 stTotalQty += parseInt($('#qty_' + prices[i][1]).val()); 337 } 338 339 _renderTotalPrice(stTotalPrice); 340 _renderTotalItems(stTotalQty); 341 } 342 343 function cart_Reset() 344 { 345 stTotalPrice = 0; 346 stTotalQty = 0; 347 348 for (var i = 0; i < lstProducts.length; i++) 349 { 350 product = lstProducts[ i ]; 351 352 qty = 0; 353 354 $('#qty_' + product.hash).val(qty); 355 356 lstProducts[ i ].qty = qty; 357 358 $('#product_' + product.hash).css('display', 'none'); 359 360 $('#order_buttons').css('display', 'none'); 361 $('#cart_no_products').css('display', 'block'); 362 363 $('#minicart_summary').css('display', 'none'); 364 $('#minicart').css('display', 'none'); 365 } 366 367 _renderTotalPrice(stTotalPrice); 368 _renderTotalItems(stTotalQty); 369 } 370 371 window.cart_AddProduct = cart_AddProduct; 372 // window.cart_isNumeric = _isNumeric; 373 // window.cart_renderTotalPrice = _renderTotalPrice; 374 // window.cart_renderTotalItems = _renderTotalItems; 375 window.cart_changeQTY = cart_changeQTY; 376 window.cart_AddToCartFormReset = cart_AddToCartFormReset; 377 window.cart_Message = cart_Message; 378 window.cart_ButtonUpdate = cart_ButtonUpdate; 379 window.cart_updateOrderShipping = cart_updateOrderShipping; 380 window.cart_updateOrderTaxes = cart_updateOrderTaxes; 381 // window.cart_updateTotal = _updateTotal; 382 // window.cart_init = cart_init; 383 window.cart_Update = cart_Update; 384 window.cart_Reset = cart_Reset; 385 386})(jQuery); 387 388/* 389 * add to cart 390 */ 391(function($) { 392 393 var GENERIC_ERROR = 1; 394 var SPECIFIC_ERROR = 2; 395 396 function cart_init(formidselector, productoptions) 397 { 398 function cart_process() 399 { 400 var $self = $(this); 401 402 var errs = new Array(); 403 404 // var product_id = $self.find('.add_to_cart-product_id').val(); 405 var unique = $self.find('.add_to_cart-uid').val(); 406 407 var cart_opts = $self.find('.add_to_cart-options'); 408 cart_opts = cart_opts.get(0); 409 410 if (cart_opts != null) 411 { 412 var size = cart_opts.options.length; 413 var offset = 0; 414 415 for (var i = 0; i < size; i++) 416 { 417 cart_opts.options[i - offset] = null; 418 offset++; 419 } 420 } 421 422 if (productoptions != null 423 && cart_opts != null) 424 { 425 var cart_options = new Array(); 426 427 for (var i = 0; i < productoptions.length; i++) 428 { 429 var curName = "product_options["+unique+"]["+ productoptions[i].set +"]["+ productoptions[i].dbId +"]"; 430 var curId = "product_options-"+unique+"-"+ productoptions[i].set +"-"+ productoptions[i].dbId; 431 432 var $cur = $('#'+curId); 433 var $curCon = $('[name="'+curName+'"]'); 434 435 if (!$curCon.length) 436 { 437 continue; 438 } 439 440 var selVal = null; 441 442 var option = productoptions[i]; 443 // var option_name = $('<span><a href="#'+curId+'">'+option.name+'</a></span>').html(); 444 var option_name = $('<span>'+option.name+'</span>').html(); 445 446 if (productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.listbox) 447 { 448 if (productoptions[i].required 449 && '' === $curCon.val()) 450 { 451 showError( $cur, 'Please select an Option' ); 452 errs[productoptions[i].dbId] = {errorType: SPECIFIC_ERROR, errorMessage:option_name+' is required'}; 453 } 454 else 455 { 456 hideError( $cur ); 457 458 var $selOpt = $curCon.find('> option:selected'); 459 var selVal = $selOpt.val(); 460 } 461 } 462 else if (productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.checkbox 463 || productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.radio 464 || productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.buttonlist 465 || productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.content 466 ) 467 { 468 if (0 < $curCon.filter(':checked').length) 469 { 470 $element = $curCon.filter(':checked').first(); 471 472 // if (productoptions[i].required 473 // && $element == $curCon.first()) 474 if (productoptions[i].required 475 && '' === $element.val()) 476 { 477 showError( $cur, 'Please select an Option' ); 478 errs[productoptions[i].dbId] = { errorType: SPECIFIC_ERROR, errorMessage:option_name+' is required'}; 479 } 480 else 481 { 482 hideError( $cur ); 483 484 var selVal = $element.val(); 485 } 486 } 487 else if (productoptions[i].required) 488 { 489 showError( $cur, 'Please select an Option' ); 490 errs[productoptions[i].dbId] = { errorType: SPECIFIC_ERROR, errorMessage:option_name+' is required'}; 491 492 continue; 493 } 494 else 495 { 496 continue; 497 } 498 } 499 else if (productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.quantity) 500 { 501 var selVal = $curCon.val(); 502 503 var option = productoptions[i]; 504 var option_name = $('<div/>').text(option.name).html(); 505 var qty_max = $.isNumeric(option.qty_max) ? option.qty_max : null; 506 var qty_min = $.isNumeric(option.qty_min) ? option.qty_min : null; 507 var required = option.required; 508 509 // validate the quantity 510 if (required && selVal == '') 511 { 512 showError( $cur ); 513 errs[option.dbId] = { errorType: SPECIFIC_ERROR, errorMessage:option_name+' is required'}; 514 } 515 else 516 { 517 if (qty_min !== null && $.isNumeric(qty_max) && (selVal < qty_min || selVal > qty_max)) 518 { 519 showError( $cur ); 520 errs[option.dbId] = { errorType: SPECIFIC_ERROR, errorMessage: option_name + ' should be between ' + qty_min + ' and ' + qty_max}; 521 } 522 else if (qty_min !== null && selVal < qty_min) 523 { 524 showError( $cur ); 525 errs[option.dbId] = { errorType: SPECIFIC_ERROR, errorMessage: option_name + ' should be bigger than ' + qty_min}; 526 } 527 else if (qty_max !== null && selVal > qty_max) 528 { 529 showError( $cur ); 530 errs[option.dbId] = { errorType: SPECIFIC_ERROR, errorMessage: option_name + ' should be smaller than ' + qty_max}; 531 } 532 } 533 } 534 else if ( 535 false 536 || productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.square 537 || productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.circle 538 || productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.rectangle 539 || productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.sphere 540 || productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.cylinder 541 || productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.cube 542 || productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.rectangular_prism 543 ) 544 { 545 var selVal = $curCon.val(); 546 547 var option = productoptions[i]; 548 var option_name = $('<div/>').text(option.name).html(); 549 var qty_max = $.isNumeric(option.qty_max) ? option.qty_max : null; 550 var qty_min = $.isNumeric(option.qty_min) ? option.qty_min : null; 551 var required = option.required; 552 553 // validate the quantity 554 if (required && selVal == '') 555 { 556 showError( $cur ); 557 errs[option.dbId] = { errorType: SPECIFIC_ERROR, errorMessage:option_name+' is required'}; 558 } 559 else 560 { 561 if (qty_min !== null && $.isNumeric(qty_max) && (selVal < qty_min || selVal > qty_max)) 562 { 563 showError( $cur ); 564 errs[option.dbId] = { errorType: SPECIFIC_ERROR, errorMessage: option_name + ' should be between ' + qty_min + ' and ' + qty_max}; 565 } 566 else if (qty_min !== null && selVal < qty_min) 567 { 568 showError( $cur ); 569 errs[option.dbId] = { errorType: SPECIFIC_ERROR, errorMessage: option_name + ' should be bigger than ' + qty_min}; 570 } 571 else if (qty_max !== null && selVal > qty_max) 572 { 573 showError( $cur ); 574 errs[option.dbId] = { errorType: SPECIFIC_ERROR, errorMessage: option_name + ' should be smaller than ' + qty_max}; 575 } 576 } 577 } 578 else if (productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.browse_product) 579 { 580 var $jqCurCorn = $curCon.filter(':checked').first() 581 582 var selVal = $jqCurCorn.val(); 583 if (productoptions[i].required 584 && selVal == undefined) 585 { 586 showError($curCon.eq(0).parents('div.product_browse-items'),'Please select a product.'); 587 errs[productoptions[i].dbId] = 'required field not filled'; 588 589 continue; 590 } 591 else 592 { 593 hideError($curCon.eq(0).parents('div.product_browse-items')); 594 } 595 } 596 else if (productoptions[i].type == Shout.configuration.module.store.cart.mini.product_option_types.email) 597 { 598 var selVal = $curCon.val(); 599 600 if (productoptions[i].required && selVal == '') 601 { 602 showError( $curCon ); 603 errs[productoptions[i].dbId] = { errorType: SPECIFIC_ERROR, errorMessage:option_name+' is required'}; 604 }
605 else if ((selVal != '') && (selVal.indexOf('@') < 0)) 606 { 607 showError( $curCon ); 608 errs[productoptions[i].dbId] = { errorType: SPECIFIC_ERROR, errorMessage:option_name+' should be an email address'}; 609 } 610 else 611 { 612 hideError( $curCon ); 613 } 614 } 615 else 616 { 617 var selVal = $curCon.val(); 618 619 if (productoptions[i].required && selVal == '') 620 { 621 showError( $curCon ); 622 errs[productoptions[i].dbId] = { errorType: SPECIFIC_ERROR, errorMessage:option_name+' is required'}; 623 } 624 else 625 { 626 hideError( $curCon ); 627 } 628 } 629 630 var index = cart_options.length; 631 cart_options[index] = new Option( productoptions[i].dbId + '::::' + selVal, selVal + Shout.configuration.module.store.cart.mini.sep + productoptions[i].dbId + Shout.configuration.module.store.cart.mini.sep + productoptions[i].set); 632 cart_options[index].selected = true; 633 } 634 635 if (0 < errs.length) 636 { 637 // console.log('errors found: ', errs); 638 var errorMessage = '<div class="errorText">Required fields missing or invalid, unable to add product.</div>'; 639 640 $.each(errs, function(optionDbId, error) 641 { 642 if (('undefined' == typeof error) || (error.errorType == GENERIC_ERROR)) 643 { 644 return; 645 } 646 errorMessage += '<div class="errorText">' + error.errorMessage + '</div>'; 647 }); 648 cart_Message(errorMessage, unique); 649 cart_ButtonUpdate('failed', unique); 650 651 return false; 652 } 653 else 654 { 655 cart_Message('', unique); 656 } 657 658 for (var i = 0; i < cart_options.length; i++) 659 { 660 cart_opts[i] = cart_options[i]; 661 } 662 /* 663 var cfg = $self.find('[name="product_configuration[]"]'); 664 var cart_cfg = $self.find('[name="cart_product_configuration[]"]'); 665 cfg = cfg.get(0); 666 cart_cfg = cart_cfg.get(0); 667 668 if (cfg != null 669 && cart_cfg != null) 670 { 671 var size = null; 672 var offset = null; 673 674 for (size = cart_cfg.options.length, offset = 0, i = 0; i < size; i++, offset++) 675 { 676 cart_cfg.options[i - offset] = null; 677 } 678 679 for (var i = 0; i < cfg.options.length; i++) 680 { 681 var group = document.getElementsByName(cfg.options[i].text) 682 683 for (j=0; j < group.length; j++) 684 { 685 if (group[j].checked) 686 { 687 var cur = cart_cfg.options.length; 688 689 cart_cfg[cur] = new Option(cfg.options[i].text, group[j].value, true, true); 690 cart_cfg[cur].selected = true; 691 } 692 } 693 } 694 } 695 */ 696 } 697 698 return true; 699 } 700 701 $(formidselector).on('submit', cart_process); 702 } 703 704 window.cart_init = cart_init; 705 706})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.