1/* 2 * @author Tomas Opekar <[email protected]> 3 * 4 */ 5 6var BS = BS || {}; 7 8BS.Basket = { 9 /** 10 *Ukazatel na tento objekt 11 */ 12 $this: null, 13 /** 14 * Pritomnost qtip, zobrazujici obsah kosiku 15 */ 16 $qtip_basket_info: true, 17 18 /** 19 * Sablona, ktera nema defaultni styl kosiku (horniho) 20 */ 21 $default_top_basket: true, 22 23 /* 24 *Typ vkladani do kosiku 25 */ 26 $variant: 5, 27 28 /** 29 * Obsah qtipu obsahu koÅ¡Ãku 30 */ 31 $qtip_basket_obj: null, 32 33 /** 34 *Default hláška, která se alertne, pokud nenà zbožà skladem 35 */ 36 $not_in_stock: "We are sorry, but there was some error.", 37 38/** 39 *Default hláška, která se alertne, pokud nenà objednáno minimálnà množstvà 40 */ 41 $not_bought_minimum: "minimum", 42 43/** 44 *Možnost použÃvat varianty i v detailu produktu 45 */ 46 $detail_buy: false, 47 48 $basket_show_items: "false", 49 50 /** 51 *Znefukcneni funkcionalit 52 */ 53 $halt : false, 54 55 $wait_text: "Äekejte", 56 /** 57 * Vrati variantu kosiku 58 */ 59 variant: function() 60 { 61 return this.$variant; 62 }, 63 64 refresh_small_basket: function() 65 { 66 var ebar_class = ""; 67 if(BS.Design.template.is_selected("platinum")) 68 { 69 this.$basket_show_items = true; 70 ebar_class = ",#ebar" 71 } 72 73 $.get("/wa_script/basket_ajax.php?basket_variant_34_show_items=true&show_easy_content=1&id=" + uzivatel_id + "&_=" + new Date().getTime(), function(data2) { 74 BS.Design.recolor(jQuery('<input class="buy_btn">').hide().appendTo("body"), jQuery(".recolor") 75 ); 76 if(BS.Basket.$qtip_basket_obj !== undefined) { 77 BS.Basket.$qtip_basket_obj.qtip('api').set('content.text',data2); 78 // Trigger event to initialize reservation countdown timers and other components 79 var tooltipContent = BS.Basket.$qtip_basket_obj.qtip('api').elements.content; 80 if(tooltipContent) { 81 BS.event.trigger('basket.content.loaded', {content: tooltipContent}); 82 } 83 } 84 }); 85 return true; 86 }, 87 88 /** 89 * Nacte data o cene / kusech 90 */ 91 refresh_top_basket_data: function() 92 { 93 jQuery.ajax({ 94 url: "/wa_script/basket_ajax.php?method=refresh_info&id=" + uzivatel_id, 95 type: "POST", 96 dataType: "json", 97 data: { 98 method: "refresh_info", 99 id: uzivatel_id 100 } 101 }).done(function(data){ 102 BS.Basket.refresh_top_basket_info(data.kusy, data.cena); 103 }).fail(function(){ 104 console.log("Cannot update basket info."); 105 }); 106 }, 107 108 refresh_top_basket_info: function (kusy, cena) 109 { 110 if($("body").hasClass("slider_available")) 111 { 112 //může pÅijÃt také deset. ÄÃslo 113 var count = BS.Number.parse(kusy.split(' ')[0]); 114 if(BS.Number.isNumber(count)) 115 { 116 $('#quantity_tag .quantity_count').text(count); 117 if(!$('#basket_icon').hasClass('basket-full') && count > 0) 118 { 119 $('#basket_icon').addClass('basket-full'); 120 } 121 else if(count == 0) 122 { 123 $('#basket_icon').removeClass('basket-full'); 124 } 125 // Infobox je druhý span uvnitÅ #quantity_tag 126 var infobox = $("#quantity_tag span:not(.quantity_count)"); 127 if(infobox.length) 128 { 129 if(count > 0) 130 { 131 infobox 132 .removeClass("basket_empty"); 133 infobox.html(this.basket_full_text || ""); 134 } 135 else 136 { 137 infobox 138 .addClass("basket_empty"); 139 infobox.html(this.basket_is_empty); 140 } 141 } 142 } 143 } 144 else 145 { 146 if(this.$default_top_basket == false) 147 { 148 jQuery("#basket_tag_right").html(kusy); 149 } 150 if(jQuery("#basket_content_tag").length > 0) 151 { 152 jQuery("#basket_tag_right").html(kusy); 153 jQuery("#quantity_tag").html(kusy + " / " + cena); 154 } 155 jQuery(".img_cart").find("a").html(kusy + " / " + cena); 156 } 157 158 return true; 159 }, 160 161 delete_from_basket: function(id) { 162 var that = this; 163 if(this.$qtip_basket_info == true) 164 { 165 jQuery(".ajax-basket-easy").find(".top").html('<div class="basket-loading"><p style=""><span class="icon-spinner icon-2x icon-spin"></span> '+BS.Basket.$wait_text+'</p></div>'); 166 }
167 $.get("/wa_script/basket_ajax.php?method=remove&id_record=" + id + "&id=" + uzivatel_id, function(data2) { 168 BS.Conversion.getEvent('', '', '', 'remove_from_cart'); 169 that.fetchContents(that.updateBodyClass); 170 }); 171 setTimeout("BS.Basket.refresh_small_basket()", 1000); 172 return true; 173 }, 174 register_close_event: function(){ 175 // Pouze pro Palladium - delegovaný event handler pro dynamický obsah 176 if(BS.Design.template.is_selected("palladium")) { 177 jQuery(document).off('click.basket-close').on('click.basket-close', '.close-box', function(el){ 178 if(BS.Basket.$qtip_basket_obj && BS.Basket.$qtip_basket_obj.qtip) { 179 BS.Basket.$qtip_basket_obj.qtip('hide'); 180 } 181 if(typeof $overlay !== 'undefined'){ 182 $overlay.fade_out(); 183 } 184 jQuery("#ajax-basket").fadeOut(200); 185 jQuery("#ajax-basket").remove(); 186 el.preventDefault(); 187 return false; 188 }); 189 } 190 // Pro ostatnà šablony - původnà chovánà 191 else { 192 jQuery(".close-box").click(function(el){ 193 if(typeof $overlay !== 'undefined'){ 194 $overlay.fade_out(); 195 } 196 jQuery("#ajax-basket").fadeOut(200); 197 jQuery("#ajax-basket").remove(); 198 el.preventDefault(); 199 return false; 200 }); 201 } 202 }, 203 204 close_qtip: function(){ 205 206 }, 207 208 explode: function(delimiter, string, limit) { 209 210 if ( arguments.length < 2 || typeof delimiter == 'undefined' || typeof string == 'undefined' ) return null; 211 if ( delimiter === '' || delimiter === false || delimiter === null) return false; 212 if ( typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object'){ 213 return { 214 0: '' 215 }; 216 } 217 if ( delimiter === true ) delimiter = '1'; 218 219 // Here we go... 220 delimiter += ''; 221 string += ''; 222 223 var s = string.split( delimiter ); 224 225 226 if ( typeof limit === 'undefined' ) return s; 227 228 // Support for limit 229 if ( limit === 0 ) limit = 1; 230 231 // Positive limit 232 if ( limit > 0 ){ 233 if ( limit >= s.length ) return s; 234 return s.slice( 0, limit - 1 ).concat( [ s.slice( limit - 1 ).join( delimiter ) ] ); 235 } 236 237 // Negative limit 238 if ( -limit >= s.length ) return []; 239 240 s.splice( s.length + limit ); 241 return s; 242 }, 243 244 fetchContents: function(callback) { 245 var r = $.ajax({ 246 url: "/wa_script/basket_ajax.php?", 247 method: "GET", 248 data: { 249 show_easy_content: 1, 250 cart: 1, 251 id: BS.User.id 252 } 253 }); 254 r.done(function(response) { 255 callback(JSON.parse(response)); 256 }); 257 }, 258 259 updateBodyClass: function(basketInfo) { 260 var isEmpty = !!parseInt(basketInfo.empty); 261 if(isEmpty) { 262 document.body.classList.add("basket-empty"); 263 } else { 264 document.body.classList.remove("basket-empty"); 265 } 266 }, 267 268 calcMultiplesInc: function(el, count) 269 { 270 const submit_input = el.querySelectorAll('input[type=submit], button[type=submit], input[type=image]')[0]; 271 if(submit_input !== undefined && submit_input.dataset.hasOwnProperty('productInfo')) 272 { 273 const objProductData = JSON.parse(submit_input.dataset.productInfo); 274 if( typeof objProductData.count_type !== undefined 275 && typeof objProductData.multiples !== undefined 276 && objProductData.count_type == 1) { 277 return objProductData.multiples; 278 } 279 } 280 return count; 281 }, 282 notifyMultiplesInc: function(data) 283 { 284 if(data !== undefined && data.hasOwnProperty('count_type') && data.count_type == 1) { 285 BS.ui.popMessage.warning(WA.Translation._multiples_inc_notify.replace('#inc#',data.multiples_inc + ".\n").replace(/(<([^>]+)>)/ig, '')); 286 } 287 288 }, 289 loadingHtml: function () 290 { 291 return "<div style='width: 100%; text-align: center; padding: 50px 0;'><img src='/images/loading.gif' style='text-align: center'></div>"; 292 } 293} 294 295/** 296 * Zkontroluje, zda lze produkt pÅidat do koÅ¡Ãku (výbÄr varianty, omezený pÅÃstup). 297 * Vracà Promise<boolean> â false pokud byl tok pÅeruÅ¡en (pÅesmÄrovánà / popup). 298 * 299 * @param {string|number} product_id 300 * @returns {Promise<boolean>} 301 */ 302BS.Basket.checkCanAdd = function (product_id, variant_id) { 303 variant_id = parseInt(variant_id) || 0; 304 return fetch( 305 '/request.php?action=Basket_control' + 306 '&main_id=' + encodeURIComponent(product_id) + 307 '&id_zakaznik=' + encodeURIComponent(BS.User.id), 308 { method: 'POST', headers: { 'Content-Type': 'application/json;charset=UTF-8' } } 309 ) 310 .then(function (response) { return response.json(); }) 311 .then(function (data) { 312 if (variant_id === 0 && data.params.choose_variant && data.success) { 313 window.location.href = data.params.url + '?variant=not_selected'; 314 return false;
315 } 316 if (data.params.control_type === 'restricted_access') { 317 BS.Fce.restricted_popup2(data.params.variables, null); 318 return false; 319 } 320 return true; 321 }); 322}; 323 324// âââ Coupon-with-product flow ââââââââââââââââââââââââââââââââââââââââââââââââ 325 326window._bs_voucher_to_apply = null; 327 328BS.Coupon = BS.Coupon || {}; 329 330(($) => { 331 'use strict'; 332 333 var $modal = null; 334 var pendingAction = null; 335 336 function ensureModal() { 337 if ($modal) { return; } 338 $('body').append( 339 '<div id="coupon_apply_modal" class="modal-dialog modal-dialog-centered mfp-hide">' + 340 '<div class="modal-block modal-block-sm confirm-modal">' + 341 '<div class="modal-content">' + 342 '<div class="modal-body">' + 343 '<div class="coupon-modal-product">' + 344 '<img class="coupon-modal-img" src="" alt="">' + 345 '<div class="coupon-modal-prices">' + 346 '<span class="coupon-modal-name"></span>' + 347 '<span class="coupon-modal-price-original"></span>' + 348 '<span class="coupon-modal-price-discounted"></span>' + 349 '</div>' + 350 '</div>' + 351 '<div class="coupon-modal-message"></div>' + 352 '<p class="text-end">' + 353 '<button type="button" class="btn btn-cancel" data-coupon-cancel>' + WA.Translation._voucher_widget_cancel_btn + '</button>' + 354 '<button type="button" class="btn btn-confirm" data-coupon-confirm>' + WA.Translation._voucher_widget_confirm_btn + '</button>' + 355 '</p>' + 356 '</div>' + 357 '</div>' + 358 '</div>' + 359 '</div>' 360 ); 361 $modal = $('#coupon_apply_modal'); 362 363 $modal.find('[data-coupon-confirm]').on('click', function () { 364 $.magnificPopup.close(); 365 if (pendingAction) { pendingAction(); pendingAction = null; } 366 }); 367 $modal.find('[data-coupon-cancel]').on('click', function () { 368 $.magnificPopup.close(); 369 pendingAction = null; 370 }); 371 } 372 373 BS.Coupon.notifyVoucherStatus = function (status) { 374 status = parseInt(status, 10); 375 if (status === 0) { return; } // success â basket page / AJAX modal already reflects it 376 var messages = { 377 2: WA.Translation._voucher_code_invalid, 378 3: WA.Translation._voucher_code_used, 379 4: WA.Translation._voucher_min_not_met, 380 5: WA.Translation._voucher_required_product_missing, 381 6: WA.Translation._voucher_not_stackable 382 }; 383 BS.ui.popMessage.alert(messages[status] || WA.Translation._voucher_code_invalid); 384 }; 385 386 function _parseFormParams($form) { 387 var product_id, variant_id = 0; 388 389 // PrimárnÄ zkusÃme .buy-button-action, které má spolehlivé data atributy 390 var $buyBtn = $form.find('.buy-button-action').first(); 391 if ($buyBtn.length) { 392 product_id = $buyBtn.data('id'); 393 variant_id = parseInt($buyBtn.data('variantId')) || 0; 394 } else { 395 // Fallback: parsovánà z action URL 396 var form_action = $form.attr('action'); 397 if (WA.Url_translator.enabled === true) { 398 var p = BS.Basket.explode("pid=", form_action); 399 var p2 = BS.Basket.explode("&vid=", p[1]); 400 product_id = p2[0]; 401 if (typeof p2[1] !== 'undefined') { variant_id = parseInt(p2[1]) || 0; } 402 } else { 403 var p = BS.Basket.explode("/", form_action); 404 product_id = p[6]; 405 if (typeof p[7] !== 'undefined') { variant_id = parseInt(p[7]) || 0; } 406 } 407 } 408 409 var variant_selected = $form.find('input[name=variant_selected]').val() || ''; 410 // Pokud variant_id stále 0, zkusÃme hidden input variant_selected 411 if (variant_id === 0 && variant_selected) { 412 variant_id = parseInt(variant_selected) || 0; 413 } 414 415 var kusy = $form.find('.prKs').val() || $('#kusy').val() || 1; 416 var add_product_info = null; 417 var submitEl = $form.get(0).querySelector('input[type=submit], input[type=image]'); 418 if (submitEl) { add_product_info = submitEl.dataset.productInfo || null; } 419 kusy = BS.Basket.calcMultiplesInc($form.get(0), kusy); 420 return { product_id: product_id, variant_id: variant_id, kusy: kusy, variant_selected: variant_selected, add_product_info: add_product_info }; 421 } 422 423 $(document).on('click', '.coupon-widget[data-coupon-code]', function (e) { 424 e.preventDefault(); 425 e.stopPropagation(); 426 427 if ($(this).hasClass('coupon-widget--no-click')) { return; } 428 429 var voucherCode = $(this).data('coupon-code'); 430 var isBox = $(this).data('entry') === 'box'; 431 var color = $(this).data('coupon-color'); 432 var colorLight = $(this).data('coupon-color-light'); 433 var $container = isBox ? $(this).closest('.product, .product3') : $(this).closest('.detail-box-product'); 434 var $form = $container.find('form').first(); 435 if (!voucherCode || !$form.length) { return; } 436 437 ensureModal(); 438 439 // Product image 440 var $imgSource; 441 if (isBox) { 442 $imgSource = $container.find('.product3ImageBox, .img_box').find('img').first(); 443 } else { 444 $imgSource = $container.find('.image img').first(); 445 446 } 447 var imgSrc = $imgSource.attr('src') || ''; 448 var $productBlock = $modal.find('.coupon-modal-product'); 449 if (imgSrc) { 450 $modal.find('.coupon-modal-img').attr('src', imgSrc); 451 } else { 452 $modal.find('.coupon-modal-img').attr('src', ''); 453 } 454 455 var productName; 456 if(isBox) { 457 productName = $container.data('name'); 458 } else { 459 productName = $container.find('h1').first().text().trim(); 460 } 461 462 // Prices 463 var discountedPrice = $(this).data('discounted-price'); 464 var originalPrice = $(this).data('original-price'); 465 $modal.find('.coupon-modal-price-original').html(originalPrice || ''); 466 $modal.find('.coupon-modal-price-discounted').html(discountedPrice || ''); 467 $modal.find('.coupon-modal-name').html(productName || ''); 468 $productBlock.toggle(!!(imgSrc || discountedPrice || originalPrice)); 469 470 var modalMessage = $modal.find('.coupon-modal-message'); 471 var msgStyle = `background-color: ${colorLight}; border-color: ${color};`; 472 if (BS.Design.template.is_selected("palladium")) { 473 msgStyle += ` color: ${color};`; 474 modalMessage.attr('data-discount-value', $(this).data('discount-value') || ''); 475 } 476 modalMessage.attr('style', msgStyle); 477 478 $modal.find('.coupon-modal-message').html(` 479 <p class="apply-coupon-text">${WA.Translation._voucher_widget_confirm_coupon}<span class="coupon-code" style="color: ${color}">${voucherCode}</span></p> 480 <p class="apply-coupon-subtext">${WA.Translation._voucher_widget_confirm_add.replace('{discount}', $(this).data('discount-value'))}</p> 481 `); 482 483 pendingAction = function () { 484 window._bs_voucher_to_apply = voucherCode; 485 486 487 var p = _parseFormParams($form); 488 489 BS.Basket.checkCanAdd(p.product_id, p.variant_id).then(function (canAdd) { 490 if (!canAdd) { 491 window._bs_voucher_to_apply = null; 492 return; 493 } 494 495 var variant = BS.Basket.variant(); 496 var promise = null; 497 498 if (variant === 2 && typeof add_basket_v2 === 'function') { 499 promise = add_basket_v2(p.kusy, p.product_id, p.variant_id, p.variant_selected, p.add_product_info, null, $form); 500 } else if (variant === 3 && typeof add_basket_v3 === 'function') { 501 promise = add_basket_v3(p.kusy, p.product_id, p.variant_id, p.variant_selected, isBox ? 1 : 2, $form, p.add_product_info); 502 } else if (variant === 4 && typeof add_basket_v4 === 'function') { 503 var random_id = Math.floor((Math.random() * 10000) + 1); 504 if (typeof basket_add_popup4 === 'function') { 505 var $btn = $form.find('.buy_btn, #buy_btn'); 506 basket_add_popup4(random_id, $btn.offset().top - 60, $btn.offset().left - 90); 507 } 508 promise = add_basket_v4(p.kusy, p.product_id, p.variant_id, random_id, p.variant_selected, p.add_product_info, $form.get(0)); 509 } else {
510 // Non-AJAX fallback (variant 1) 511 var $hidden = $form.find('input[name="voucher_code"]'); 512 if (!$hidden.length) { 513 $hidden = $('<input type="hidden" name="voucher_code">').appendTo($form); 514 } 515 $hidden.val(voucherCode); 516 $form.get(0).requestSubmit(); 517 return; 518 } 519 520 if (promise) { 521 promise.always(function (dataOrJqXHR, textStatus, jqXHROrThrown) { 522 window._bs_voucher_to_apply = null; 523 // Variant 2 (HTML response): voucher status is in response header 524 var jqXHR = textStatus === 'success' ? jqXHROrThrown : dataOrJqXHR; 525 var headerStatus = jqXHR && jqXHR.getResponseHeader ? jqXHR.getResponseHeader('X-Voucher-Status') : null; 526 if (headerStatus !== null && typeof BS.Coupon !== 'undefined') { 527 BS.Coupon.notifyVoucherStatus(parseInt(headerStatus, 10)); 528 } 529 }); 530 } 531 }); 532 }; 533 534 $.magnificPopup.open({ 535 items: { src: $modal }, 536 modal: true, 537 closeOnBgClick: true, 538 showCloseBtn: false 539 }); 540 }); 541})(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.