1 2; /* Start:"a:4:{s:4:"full";s:115:"/local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/script.js?178187500041568";s:6:"source";s:99:"/local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/script.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/ 3 4BasketPoolQuantity = function() 5{ 6 this.processing = false; 7 this.poolQuantity = {}; 8 this.updateTimer = null; 9 this.currentQuantity = {}; 10 this.lastStableQuantities = {}; 11 12 this.updateQuantity(); 13}; 14 15 16BasketPoolQuantity.prototype.updateQuantity = function() 17{ 18 var items = BX('basket_items'); 19 basketJSParams = []; 20 if (basketJSParams && basketJSParams != 'undefined' && basketJSParams['USE_ENHANCED_ECOMMERCE'] === 'Y') 21 { 22 checkAnalytics(this.lastStableQuantities, items); 23 } 24 25 if (!!items && items.rows.length > 0) 26 { 27 for (var i = 1; items.rows.length > i; i++) 28 { 29 var itemId = items.rows[i].id; 30 this.currentQuantity[itemId] = BX('QUANTITY_' + itemId).value; 31 } 32 } 33 34 this.lastStableQuantities = BX.clone(this.currentQuantity, true); 35}; 36 37 38BasketPoolQuantity.prototype.changeQuantity = function(itemId) 39{ 40 var quantity = BX('QUANTITY_' + itemId).value; 41 var isPoolEmpty = this.isPoolEmpty(); 42 43 if (this.currentQuantity[itemId] && this.currentQuantity[itemId] != quantity) 44 { 45 this.poolQuantity[itemId] = this.currentQuantity[itemId] = quantity; 46 } 47 48 if (!isPoolEmpty) 49 { 50 this.enableTimer(true); 51 } 52 else 53 { 54 this.trySendPool(); 55 } 56}; 57 58 59BasketPoolQuantity.prototype.trySendPool = function() 60{ 61 if (!this.isPoolEmpty() && !this.isProcessing()) 62 { 63 this.enableTimer(false); 64 recalcBasketAjax({}); 65 } 66}; 67 68BasketPoolQuantity.prototype.isPoolEmpty = function() 69{ 70 return ( Object.keys(this.poolQuantity).length == 0 ); 71}; 72 73BasketPoolQuantity.prototype.clearPool = function() 74{ 75 this.poolQuantity = {}; 76}; 77 78BasketPoolQuantity.prototype.isProcessing = function() 79{ 80 return (this.processing === true); 81}; 82 83BasketPoolQuantity.prototype.setProcessing = function(value) 84{ 85 this.processing = (value === true); 86}; 87 88BasketPoolQuantity.prototype.enableTimer = function(value) 89{ 90 clearTimeout(this.updateTimer); 91 if (value === false) 92 return; 93 94 this.updateTimer = setTimeout(function(){ basketPoolQuantity.trySendPool(); }, 1500); 95}; 96 97/** 98 * @param basketItemId 99 * @param {{BASKET_ID : string, BASKET_DATA : { GRID : { ROWS : {} }}, COLUMNS: {}, PARAMS: {}, DELETE_ORIGINAL : string }} res 100 */ 101function updateBasketTable(basketItemId, res) 102{ 103 var table = BX("basket_items"), 104 rows, 105 newBasketItemId, 106 arItem, 107 lastRow, 108 newRow, 109 arColumns, 110 bShowDeleteColumn = false, 111 bShowDelayColumn = false, 112 bShowPropsColumn = false, 113 bShowPriceType = false, 114 bUseFloatQuantity, 115 origBasketItem, 116 oCellMargin, 117 i, 118 oCellName, 119 imageURL, 120 cellNameHTML, 121 oCellItem, 122 cellItemHTML, 123 bSkip, 124 j, 125 val, 126 propId, 127 arProp, 128 bIsImageProperty, 129 countValues, 130 full, 131 fullWidth, 132 itemWidth, 133 arVal, 134 valId, 135 arSkuValue, 136 selected, 137 valueId, 138 k, 139 arItemProp, 140 oCellQuantity, 141 oCellQuantityHTML, 142 ratio, 143 isUpdateQuantity, 144 oldQuantity, 145 oCellPrice, 146 fullPrice, 147 id, 148 oCellDiscount, 149 oCellWeight, 150 oCellCustom, 151 customColumnVal, 152 propsMap, 153 selectedIndex, 154 counter, 155 marginLeft, 156 createNewItem; 157 158 if (!table || typeof res !== 'object') 159 { 160 return; 161 } 162 163 rows = table.rows; 164 lastRow = rows[rows.length - 1]; 165 bUseFloatQuantity = (res.PARAMS.QUANTITY_FLOAT === 'Y'); 166 167 // insert new row instead of original basket item row 168 if (basketItemId !== null && !!res.BASKET_DATA) 169 { 170 origBasketItem = BX(basketItemId); 171 172 newBasketItemId = res.BASKET_ID; 173 createNewItem = BX.type.isPlainObject(res.BASKET_DATA.GRID.ROWS[newBasketItemId]); 174 if (createNewItem) 175 { 176 arItem = res.BASKET_DATA.GRID.ROWS[newBasketItemId]; 177 newRow = document.createElement('tr'); 178 179 newRow.setAttribute('id', res.BASKET_ID); 180 newRow.setAttribute('data-item-name', arItem['NAME']); 181 newRow.setAttribute('data-item-brand', arItem[basketJSParams['BRAND_PROPERTY'] + '_VALUE']); 182 newRow.setAttribute('data-item-price', arItem['PRICE']); 183 newRow.setAttribute('data-item-currency', arItem['CURRENCY']); 184 185 lastRow.parentNode.insertBefore(newRow, origBasketItem.nextSibling); 186 } 187 188 if (res.DELETE_ORIGINAL === 'Y') 189 { 190 origBasketItem.parentNode.removeChild(origBasketItem); 191 } 192 193 if (createNewItem) 194 { 195 // fill row with fields' values 196 oCellMargin = newRow.insertCell(-1); 197 oCellMargin.setAttribute('class', 'margin'); 198 199 arColumns = res.COLUMNS.split(','); 200 201 for (i = 0; i < arColumns.length; i++) 202 { 203 if (arColumns[i] === 'DELETE') 204 { 205 bShowDeleteColumn = true; 206 } 207 else if (arColumns[i] === 'DELAY') 208 { 209 bShowDelayColumn = true; 210 } 211 else if (arColumns[i] === 'PROPS') 212 { 213 bShowPropsColumn = true; 214 } 215 else if (arColumns[i] === 'TYPE') 216 { 217 bShowPriceType = true; 218 } 219 } 220 221 for (i = 0; i < arColumns.length; i++) 222 { 223 switch (arColumns[i]) 224 { 225 case 'PROPS': 226 case 'DELAY':
227 case 'DELETE': 228 case 'TYPE': 229 break; 230 case 'NAME': 231 // first <td> - image and brand 232 oCellName = newRow.insertCell(-1); 233 imageURL = ''; 234 cellNameHTML = ''; 235 236 oCellName.setAttribute('class', 'itemphoto'); 237 238 if (arItem.PREVIEW_PICTURE_SRC.length > 0) 239 { 240 imageURL = arItem.PREVIEW_PICTURE_SRC; 241 } 242 else if (arItem.DETAIL_PICTURE_SRC.length > 0) 243 { 244 imageURL = arItem.DETAIL_PICTURE_SRC; 245 } 246 else 247 { 248 imageURL = basketJSParams.TEMPLATE_FOLDER + '/images/no_photo.png'; 249 } 250 251 if (arItem.DETAIL_PAGE_URL.length > 0) 252 { 253 cellNameHTML = '<div class="bx_ordercart_photo_container">\ 254 <a href="' + arItem.DETAIL_PAGE_URL + '">\ 255 <div class="bx_ordercart_photo" style="background-image:url(\'' + imageURL + '\')"></div>\ 256 </a>\ 257 </div>'; 258 } 259 else 260 { 261 cellNameHTML = '<div class="bx_ordercart_photo_container">\ 262 <div class="bx_ordercart_photo" style="background-image:url(\'' + imageURL + '\')"></div>\ 263 </div>'; 264 } 265 266 if (arItem.BRAND && arItem.BRAND.length > 0) 267 { 268 cellNameHTML += '<div class="bx_ordercart_brand">\ 269 <img alt="" src="' + arItem.BRAND + '"/>\ 270 </div>'; 271 } 272 273 oCellName.innerHTML = cellNameHTML; 274 275 // second <td> - name, basket props, sku props 276 oCellItem = newRow.insertCell(-1); 277 cellItemHTML = ''; 278 oCellItem.setAttribute('class', 'item'); 279 280 if (arItem['DETAIL_PAGE_URL'].length > 0) 281 cellItemHTML += '<h2 class="bx_ordercart_itemtitle"><a href="' + arItem['DETAIL_PAGE_URL'] + '">' + arItem['NAME'] + '</a></h2>'; 282 else 283 cellItemHTML += '<h2 class="bx_ordercart_itemtitle">' + arItem['NAME'] + '</h2>'; 284 285 cellItemHTML += '<div class="bx_ordercart_itemart">'; 286 287 if (bShowPropsColumn) 288 { 289 for (j = 0; j < arItem['PROPS'].length; j++) 290 { 291 val = arItem['PROPS'][j]; 292 293 if (arItem.SKU_DATA) 294 { 295 bSkip = false; 296 for (propId in arItem.SKU_DATA) 297 { 298 if (arItem.SKU_DATA.hasOwnProperty(propId)) 299 { 300 arProp = arItem.SKU_DATA[propId]; 301 302 if (arProp['CODE'] === val['CODE']) 303 { 304 bSkip = true; 305 break; 306 } 307 } 308 } 309 if (bSkip) 310 continue; 311 } 312 313 cellItemHTML += BX.util.htmlspecialchars(val['NAME']) + ': <span>' + val['VALUE'] + '</span><br/>'; 314 } 315 } 316 cellItemHTML += '</div>'; 317 318 if (arItem.SKU_DATA) 319 { 320 propsMap = {}; 321 for (k = 0; k < arItem['PROPS'].length; k++) 322 { 323 arItemProp = arItem['PROPS'][k]; 324 propsMap[arItemProp['CODE']] = (BX.type.isNotEmptyString(arItemProp['~VALUE']) ? arItemProp['~VALUE'] : arItemProp['VALUE']); 325 } 326 for (propId in arItem.SKU_DATA) 327 { 328 if (arItem.SKU_DATA.hasOwnProperty(propId)) 329 { 330 selectedIndex = 0; 331 arProp = arItem.SKU_DATA[propId]; 332 bIsImageProperty = false; 333 countValues = BX.util.array_keys(arProp['VALUES']).length; 334 if (countValues > 5) 335 { 336 full = 'full'; 337 fullWidth = (countValues*20) + '%'; 338 itemWidth = (100/countValues) + '%'; 339 } 340 else 341 { 342 full = ''; 343 fullWidth = '100%'; 344 itemWidth = '20%'; 345 } 346 347 counter = 0; 348 for (valId in arProp['VALUES']) 349 { 350 counter++; 351 arVal = arProp['VALUES'][valId]; 352 if (BX.type.isNotEmptyString(propsMap[arProp['CODE']])) 353 { 354 if (propsMap[arProp['CODE']] == arVal['NAME'] || propsMap[arProp['CODE']] == arVal['XML_ID']) 355 selectedIndex = counter; 356 } 357 if (!!arVal && typeof arVal === 'object' && !!arVal['PICT']) 358 { 359 bIsImageProperty = true; 360 } 361 } 362 363 marginLeft = '0'; 364 if (full !== '' && selectedIndex > 5) 365 marginLeft = ((5 - selectedIndex) * 20) + '%'; 366 367 // sku property can contain list of images or values 368 if (bIsImageProperty) 369 { 370 cellItemHTML += '<div class="bx_item_detail_scu_small_noadaptive ' + full + '">'; 371 cellItemHTML += '<span class="bx_item_section_name_gray">' + BX.util.htmlspecialchars(arProp['NAME']) + '</span>'; 372 cellItemHTML += '<div class="bx_scu_scroller_container">'; 373 cellItemHTML += '<div class="bx_scu">'; 374 375 cellItemHTML += '<ul id="prop_' + arProp['CODE'] + '_' + arItem['ID'] + '" style="width: ' + fullWidth + '; margin-left: ' + marginLeft + ';" class="sku_prop_list">'; 376 377 counter = 0; 378 for (valueId in arProp['VALUES']) 379 { 380 counter++; 381 arSkuValue = arProp['VALUES'][valueId]; 382 selected = (selectedIndex == counter ? ' bx_active' : ''); 383 384 cellItemHTML += '<li style="width: ' + itemWidth + '; padding-top: ' + itemWidth + ';"\ 385 class="sku_prop' + selected + '" \ 386 data-sku-selector="Y" \ 387 data-value-id="' + arSkuValue['XML_ID'] + '" \ 388 data-sku-name="' + BX.util.htmlspecialchars(arSkuValue['NAME']) + '" \ 389 data-element="' + arItem['ID'] + '" \ 390 data-property="' + arProp['CODE'] + '"\ 391 >\ 392 <a href="javascript:void(0)" class="cnt"><span class="cnt_item" style="background-image:url(' + arSkuValue['PICT']['SRC'] + '"></span></a>\ 393 </li>'; 394 } 395 396 cellItemHTML += '</ul>'; 397 cellItemHTML += '</div>'; 398 399 cellItemHTML += '<div class="bx_slide_left" onclick="leftScroll(\'' + arProp['CODE'] + '\', ' + arItem['ID'] + ', ' + BX.util.array_keys(arProp['VALUES']).length + ');"></div>'; 400 cellItemHTML += '<div class="bx_slide_right" onclick="rightScroll(\'' + arProp['CODE'] + '\', ' + arItem['ID'] + ', ' + BX.util.array_keys(arProp['VALUES']).length + ');"></div>'; 401 402 cellItemHTML += '</div>'; 403 cellItemHTML += '</div>'; 404 } 405 else // not image 406 { 407 cellItemHTML += '<div class="bx_item_detail_size_small_noadaptive ' + full + '">'; 408 cellItemHTML += '<span class="bx_item_section_name_gray">' + BX.util.htmlspecialchars(arProp['NAME']) + '</span>'; 409 cellItemHTML += '<div class="bx_size_scroller_container">'; 410 cellItemHTML += '<div class="bx_size">'; 411 412 cellItemHTML += '<ul id="prop_' + arProp['CODE'] + '_' + arItem['ID'] + '" style="width: ' + fullWidth + '; margin-left: ' + marginLeft + ';" class="sku_prop_list">'; 413 414 counter = 0; 415 for (valueId in arProp['VALUES']) 416 { 417 counter++; 418 arSkuValue = arProp['VALUES'][valueId]; 419 selected = (selectedIndex == counter ? ' bx_active' : ''); 420 421 cellItemHTML += '<li style="width: ' + itemWidth + ';"\ 422 class="sku_prop ' + selected + '" \ 423 data-sku-selector="Y" \ 424 data-value-id="' + (arProp['TYPE'] === 'S' && arProp['USER_TYPE'] === 'directory' ? arSkuValue['XML_ID'] : BX.util.htmlspecialchars(arSkuValue['NAME'])) + '" \ 425 data-sku-name="' + BX.util.htmlspecialchars(arSkuValue['NAME']) + '" \ 426 data-element="' + arItem['ID'] + '" \ 427 data-property="' + arProp['CODE'] + '" \ 428 >\ 429 <a href="javascript:void(0)" class="cnt">' + BX.util.htmlspecialchars(arSkuValue['NAME']) + '</a>\ 430 </li>'; 431 } 432 433 cellItemHTML += '</ul>'; 434 cellItemHTML += '</div>'; 435 436 cellItemHTML += '<div class="bx_slide_left" onclick="leftScroll(\'' + arProp['CODE'] + '\', ' + arItem['ID'] + ', ' + BX.util.array_keys(arProp['VALUES']).length + ');"></div>'; 437 cellItemHTML += '<div class="bx_slide_right" onclick="rightScroll(\'' + arProp['CODE'] + '\', ' + arItem['ID'] + ', ' + BX.util.array_keys(arProp['VALUES']).length + ');"></div>'; 438 439 cellItemHTML += '</div>'; 440 cellItemHTML += '</div>'; 441 } 442 } 443 } 444 } 445 446 oCellItem.innerHTML = cellItemHTML; 447 break; 448 case 'QUANTITY': 449 oCellQuantity = newRow.insertCell(-1); 450 oCellQuantityHTML = ''; 451 ratio = (parseFloat(arItem['MEASURE_RATIO']) > 0) ? arItem['MEASURE_RATIO'] : 1; 452 453 isUpdateQuantity = false; 454 455 if (ratio != 0 && ratio != '') 456 { 457 oldQuantity = arItem['QUANTITY']; 458 arItem['QUANTITY'] = getCorrectRatioQuantity(arItem['QUANTITY'], ratio, bUseFloatQuantity); 459 460 if (oldQuantity != arItem['QUANTITY']) 461 { 462 isUpdateQuantity = true; 463 } 464 } 465 466 oCellQuantity.setAttribute('class', 'custom'); 467 oCellQuantityHTML += '<span>' + getColumnName(res, arColumns[i]) + ':</span>'; 468 469 oCellQuantityHTML += '<div class="centered">'; 470 oCellQuantityHTML += '<table cellspacing="0" cellpadding="0" class="counter">'; 471 oCellQuantityHTML += '<tr>'; 472 oCellQuantityHTML += '<td>'; 473 474 oCellQuantityHTML += '<input type="text" size="3" id="QUANTITY_INPUT_' + arItem['ID'] + '"\ 475 name="QUANTITY_INPUT_' + arItem['ID'] + '"\ 476 style="max-width: 50px"\ 477 value="' + arItem['QUANTITY'] + '"\ 478 onchange="updateQuantity(\'QUANTITY_INPUT_' + arItem['ID'] + '\',\'' + arItem['ID'] + '\', ' + ratio + ',' + bUseFloatQuantity + ')"\ 479 >'; 480 481 oCellQuantityHTML += '</td>'; 482 483 if (ratio != 0 484 && ratio != '' 485 ) // if not Set parent, show quantity control 486 { 487 oCellQuantityHTML += '<td id="basket_quantity_control">\ 488 <div class="basket_quantity_control">\ 489 <a href="javascript:void(0);" class="plus" onclick="setQuantity(' + arItem['ID'] + ', ' + ratio + ', \'up\', ' + bUseFloatQuantity + ');"></a>\ 490 <a href="javascript:void(0);" class="minus" onclick="setQuantity(' + arItem['ID'] + ', ' + ratio + ', \'down\', ' + bUseFloatQuantity + ');"></a>\ 491 </div>\ 492 </td>'; 493 } 494 495 if (arItem.hasOwnProperty('MEASURE_TEXT') && arItem['MEASURE_TEXT'].length > 0) 496 oCellQuantityHTML += '<td style="text-align: left">' + BX.util.htmlspecialchars(arItem['MEASURE_TEXT']) + '</td>'; 497 498 oCellQuantityHTML += '</tr>'; 499 oCellQuantityHTML += '</table>'; 500 oCellQuantityHTML += '</div>'; 501 502 oCellQuantityHTML += '<input type="hidden" id="QUANTITY_' + arItem['ID'] + '" name="QUANTITY_' + arItem['ID'] + '" value="' + arItem['QUANTITY'] + '" />'; 503 504 oCellQuantity.innerHTML = oCellQuantityHTML; 505 506 if (isUpdateQuantity) 507 { 508 updateQuantity('QUANTITY_INPUT_' + arItem['ID'], arItem['ID'], ratio, bUseFloatQuantity); 509 } 510 break; 511 case 'PRICE': 512 oCellPrice = newRow.insertCell(-1); 513 fullPrice = (arItem['DISCOUNT_PRICE_PERCENT'] > 0) ? arItem['FULL_PRICE_FORMATED'] : ''; 514 515 oCellPrice.setAttribute('class', 'price'); 516 oCellPrice.innerHTML = '<div class="current_price" id="current_price_' + arItem['ID'] + '">' + arItem['PRICE_FORMATED'] + '</div>' + 517 '<div class="old_price" id="old_price_' + arItem['ID'] + '">' + fullPrice + '</div>'; 518 519 if (bShowPriceType && arItem['NOTES'].length > 0) 520 { 521 oCellPrice.innerHTML += '<div class="type_price">' + basketJSParams['SALE_TYPE'] + '</div>'; 522 oCellPrice.innerHTML += '<div class="type_price_value">' + arItem['NOTES'] + '</div>'; 523 } 524 break; 525 case 'DISCOUNT': 526 oCellDiscount = newRow.insertCell(-1); 527 oCellDiscount.setAttribute('class', 'custom'); 528 oCellDiscount.innerHTML = '<span>' + getColumnName(res, arColumns[i]) + ':</span>'; 529 oCellDiscount.innerHTML += '<div id="discount_value_' + arItem['ID'] + '">' + arItem['DISCOUNT_PRICE_PERCENT_FORMATED'] + '</div>'; 530 break; 531 case 'WEIGHT': 532 oCellWeight = newRow.insertCell(-1); 533 oCellWeight.setAttribute('class', 'custom'); 534 oCellWeight.innerHTML = '<span>' + getColumnName(res, arColumns[i]) + ':</span>'; 535 oCellWeight.innerHTML += arItem['WEIGHT_FORMATED']; 536 break; 537 default: 538 oCellCustom = newRow.insertCell(-1); 539 customColumnVal = ''; 540 541 oCellCustom.setAttribute('class', 'custom'); 542 oCellCustom.innerHTML = '<span>' + getColumnName(res, arColumns[i]) + ':</span>'; 543 544 if (arColumns[i] == 'SUM') 545 customColumnVal += '<div id="sum_' + arItem['ID'] + '">'; 546 547 if (typeof(arItem[arColumns[i]]) != 'undefined') 548 { 549 customColumnVal += arItem[arColumns[i]]; 550 } 551 552 if (arColumns[i] == 'SUM') 553 customColumnVal += '</div>'; 554 555 oCellCustom.innerHTML += customColumnVal; 556 break; 557 } 558 } 559 560 if (bShowDeleteColumn || bShowDelayColumn) 561 { 562 var oCellControl = newRow.insertCell(-1); 563 oCellControl.setAttribute('class', 'control'); 564 565 if (bShowDeleteColumn) 566 oCellControl.innerHTML = '<a href="' + basketJSParams['DELET
566E_URL'].replace('#ID#', arItem['ID']) + '">' + basketJSParams['SALE_DELETE'] + '</a><br />'; 567 568 if (bShowDelayColumn) 569 oCellControl.innerHTML += '<a href="' + basketJSParams['DELAY_URL'].replace('#ID#', arItem['ID']) + '">' + basketJSParams['SALE_DELAY'] + '</a>'; 570 } 571 572 var oCellMargin2 = newRow.insertCell(-1); 573 oCellMargin2.setAttribute('class', 'margin'); 574 } 575 } 576 577 // update product params after recalculation 578 if (!!res.BASKET_DATA) 579 { 580 for (id in res.BASKET_DATA.GRID.ROWS) 581 { 582 if (res.BASKET_DATA.GRID.ROWS.hasOwnProperty(id)) 583 { 584 var item = res.BASKET_DATA.GRID.ROWS[id]; 585 586 if (BX('discount_value_' + id)) 587 BX('discount_value_' + id).innerHTML = item.DISCOUNT_PRICE_PERCENT_FORMATED; 588 589 if (BX('current_price_' + id)) 590 BX('current_price_' + id).innerHTML = item.PRICE_FORMATED; 591 592 if (BX('old_price_' + id)) 593 BX('old_price_' + id).innerHTML = (item.DISCOUNT_PRICE_PERCENT > 0) ? item.FULL_PRICE_FORMATED : ''; 594 595 if (BX('sum_' + id)) 596 BX('sum_' + id).innerHTML = item.SUM; 597 598 // if the quantity was set by user to 0 or was too much, we need to show corrected quantity value from ajax response 599 if (BX('QUANTITY_' + id)) 600 { 601 BX('QUANTITY_INPUT_' + id).value = item.QUANTITY; 602 BX('QUANTITY_INPUT_' + id).defaultValue = item.QUANTITY; 603 604 BX('QUANTITY_' + id).value = item.QUANTITY; 605 } 606 } 607 } 608 } 609 610 // update coupon info 611 if (!!res.BASKET_DATA) 612 couponListUpdate(res.BASKET_DATA); 613 614 // update warnings if any 615 if (res.hasOwnProperty('WARNING_MESSAGE')) 616 { 617 var warningText = ''; 618 619 for (i = res['WARNING_MESSAGE'].length - 1; i >= 0; i--) 620 warningText += res['WARNING_MESSAGE'][i] + '<br/>'; 621 622 BX('warning_message').innerHTML = warningText; 623 } 624 625 // update total basket values 626 if (!!res.BASKET_DATA) 627 { 628 if (BX('allWeight_FORMATED')) 629 BX('allWeight_FORMATED').innerHTML = res['BASKET_DATA']['allWeight_FORMATED'].replace(/\s/g, ' '); 630 631 if (BX('allSum_wVAT_FORMATED')) 632 BX('allSum_wVAT_FORMATED').innerHTML = res['BASKET_DATA']['allSum_wVAT_FORMATED'].replace(/\s/g, ' '); 633 634 if (BX('allVATSum_FORMATED')) 635 BX('allVATSum_FORMATED').innerHTML = res['BASKET_DATA']['allVATSum_FORMATED'].replace(/\s/g, ' '); 636 637 if (BX('allSum_FORMATED')) 638 BX('allSum_FORMATED').innerHTML = res['BASKET_DATA']['allSum_FORMATED'].replace(/\s/g, ' '); 639 640 if (BX('PRICE_WITHOUT_DISCOUNT')) 641 { 642 var showPriceWithoutDiscount = (res['BASKET_DATA']['PRICE_WITHOUT_DISCOUNT'] != res['BASKET_DATA']['allSum_FORMATED']); 643 BX('PRICE_WITHOUT_DISCOUNT').innerHTML = showPriceWithoutDiscount ? res['BASKET_DATA']['PRICE_WITHOUT_DISCOUNT'].replace(/\s/g, ' ') : ''; 644 BX.style(BX('PRICE_WITHOUT_DISCOUNT').parentNode, 'display', (showPriceWithoutDiscount ? 'table-row' : 'none')); 645 } 646 647 BX.onCustomEvent('OnBasketChange'); 648 } 649} 650/** 651 * @param couponBlock 652 * @param {COUPON: string, JS_STATUS: string} oneCoupon - new coupon. 653 */ 654function couponCreate(couponBlock, oneCoupon) 655{ 656 var couponClass = 'disabled'; 657 658 if (!BX.type.isElementNode(couponBlock)) 659 return; 660 if (oneCoupon.JS_STATUS === 'BAD') 661 couponClass = 'bad'; 662 else if (oneCoupon.JS_STATUS === 'APPLYED') 663 couponClass = 'good'; 664 665 couponBlock.appendChild(BX.create( 666 'div', 667 { 668 props: { 669 className: 'bx_ordercart_coupon' 670 }, 671 children: [ 672 BX.create( 673 'input', 674 { 675 props: { 676 className: couponClass, 677 type: 'text', 678 value: oneCoupon.COUPON, 679 name: 'OLD_COUPON[]' 680 }, 681 attrs: { 682 disabled: true, 683 readonly: true 684 } 685 } 686 ), 687 BX.create( 688 'span', 689 { 690 props: { 691 className: couponClass 692 }, 693 attrs: { 694 'data-coupon': oneCoupon.COUPON 695 } 696 } 697 ), 698 BX.create( 699 'div', 700 { 701 props: { 702 className: 'bx_ordercart_coupon_notes' 703 }, 704 html: oneCoupon.JS_CHECK_CODE 705 } 706 ) 707 ] 708 } 709 )); 710} 711 712/** 713 * @param {COUPON_LIST : []} res 714 */ 715function couponListUpdate(res) 716{ 717 var couponBlock, 718 couponClass, 719 fieldCoupon, 720 couponsCollection, 721 couponFound, 722 i, 723 j, 724 key; 725 726 if (!!res && typeof res !== 'object') 727 { 728 return; 729 } 730 731 couponBlock = BX('coupons_block'); 732 if (!!couponBlock) 733 { 734 if (!!res.COUPON_LIST && BX.type.isArray(res.COUPON_LIST)) 735 { 736 fieldCoupon = BX('coupon'); 737 if (!!fieldCoupon) 738 { 739 fieldCoupon.value = ''; 740 } 741 couponsCollection = BX.findChildren(couponBlock, { tagName: 'input', property: { name: 'OLD_COUPON[]' } }, true); 742 743 if (!!couponsCollection) 744 { 745 if (BX.type.isElementNode(couponsCollection)) 746 { 747 couponsCollection = [couponsCollection]; 748 } 749 for (i = 0; i < res.COUPON_LIST.length; i++) 750 { 751 couponFound = false; 752 key = -1; 753 for (j = 0; j < couponsCollection.length; j++) 754 { 755 if (couponsCollection[j].value === res.COUPON_LIST[i].COUPON
755) 756 { 757 couponFound = true; 758 key = j; 759 couponsCollection[j].couponUpdate = true; 760 break; 761 } 762 } 763 if (couponFound) 764 { 765 couponClass = 'disabled'; 766 if (res.COUPON_LIST[i].JS_STATUS === 'BAD') 767 couponClass = 'bad'; 768 else if (res.COUPON_LIST[i].JS_STATUS === 'APPLYED') 769 couponClass = 'good'; 770 771 BX.adjust(couponsCollection[key], {props: {className: couponClass}}); 772 BX.adjust(couponsCollection[key].nextSibling, {props: {className: couponClass}}); 773 BX.adjust(couponsCollection[key].nextSibling.nextSibling, {html: res.COUPON_LIST[i].JS_CHECK_CODE}); 774 } 775 else 776 { 777 couponCreate(couponBlock, res.COUPON_LIST[i]); 778 } 779 } 780 for (j = 0; j < couponsCollection.length; j++) 781 { 782 if (typeof (couponsCollection[j].couponUpdate) === 'undefined' || !couponsCollection[j].couponUpdate) 783 { 784 BX.remove(couponsCollection[j].parentNode); 785 couponsCollection[j] = null; 786 } 787 else 788 { 789 couponsCollection[j].couponUpdate = null; 790 } 791 } 792 } 793 else 794 { 795 for (i = 0; i < res.COUPON_LIST.length; i++) 796 { 797 couponCreate(couponBlock, res.COUPON_LIST[i]); 798 } 799 } 800 } 801 } 802 couponBlock = null; 803} 804 805function skuPropClickHandler() 806{ 807 var target = this, 808 basketItemId, 809 property, 810 property_values = {}, 811 postData = {}, 812 action_var, 813 all_sku_props, 814 i, 815 sku_prop_value, 816 m; 817 818 if (!!target && target.hasAttribute('data-value-id')) 819 { 820 BX.showWait(); 821 822 basketItemId = target.getAttribute('data-element'); 823 property = target.getAttribute('data-property'); 824 action_var = BX('action_var').value; 825 826 property_values[property] = BX.util.htmlspecialcharsback(target.getAttribute('data-value-id')); 827 828 // if already selected element is clicked 829 if (BX.hasClass(target, 'bx_active')) 830 { 831 BX.closeWait(); 832 return; 833 } 834 835 // get other basket item props to get full unique set of props of the new product 836 all_sku_props = BX.findChildren(BX(basketItemId), {tagName: 'ul', className: 'sku_prop_list'}, true); 837 if (!!all_sku_props && all_sku_props.length > 0) 838 { 839 for (i = 0; all_sku_props.length > i; i++) 840 { 841 if (all_sku_props[i].id !== 'prop_' + property + '_' + basketItemId) 842 { 843 sku_prop_value = BX.findChildren(BX(all_sku_props[i].id), {tagName: 'li', className: 'bx_active'}, true); 844 if (!!sku_prop_value && sku_prop_value.length > 0) 845 { 846 for (m = 0; sku_prop_value.length > m; m++) 847 { 848 if (sku_prop_value[m].hasAttribute('data-value-id')) 849 { 850 property_values[sku_prop_value[m].getAttribute('data-property')] = BX.util.htmlspecialcharsback(sku_prop_value[m].getAttribute('data-value-id')); 851 } 852 } 853 } 854 } 855 } 856 } 857 858 postData = { 859 'basketItemId': basketItemId, 860 'sessid': BX.bitrix_sessid(), 861 'site_id': BX.message('SITE_ID'), 862 'props': property_values, 863 'action_var': action_var, 864 'select_props': BX('column_headers').value, 865 'offers_props': BX('offers_props').value, 866 'quantity_float': BX('quantity_float').value, 867 'price_vat_show_value': BX('price_vat_show_value').value, 868 'hide_coupon': BX('hide_coupon').value, 869 'use_prepayment': BX('use_prepayment').value 870 }; 871 872 postData[action_var] = 'select_item'; 873 874 BX.ajax({ 875 url: '/bitrix/components/bitrix/sale.basket.basket/ajax.php', 876 method: 'POST', 877 data: postData, 878 dataType: 'json', 879 onsuccess: function(result) 880 { 881 BX.closeWait(); 882 updateBasketTable(basketItemId, result); 883 } 884 }); 885 } 886} 887 888function getColumnName(result, columnCode) 889{ 890 if (BX('col_' + columnCode)) 891 { 892 return BX.util.trim(BX('col_' + columnCode).innerHTML); 893 } 894 else 895 { 896 return ''; 897 } 898} 899 900function leftScroll(prop, id, count) 901{ 902 count = parseInt(count, 10); 903 var el = BX('prop_' + prop + '_' + id); 904 905 if (el) 906 { 907 var curVal = parseInt(el.style.marginLeft, 10); 908 if (curVal <= -20) 909 el.style.marginLeft = curVal + 20 + '%'; 910 } 911} 912 913function rightScroll(prop, id, count) 914{ 915 count = parseInt(count, 10); 916 917 var el = BX('prop_' + prop + '_' + id); 918 919 if (el) 920 { 921 var curVal = parseInt(el.style.marginLeft, 10); 922 if (curVal > (5 - count)*20) 923 el.style.marginLeft = curVal - 20 + '%'; 924 } 925} 926 927function checkOut() 928{ 929 if (!!BX('coupon')) 930 BX('coupon').disabled = true; 931 BX("basket_form").submit(); 932 return true; 933} 934 935function updateBasket() 936{ 937 recalcBasketAjax({}); 938} 939 940function enterCoupon() 941{ 942 var newCoupon = BX('coupon'); 943 if (!!newCoupon && !!newCoupon.value) 944 recalcBasketAjax({'coupon' : newCoupon.value}); 945} 946 947// check if quantity is valid 948// and update values of both controls (text input field for PC and mobile quantity select) simultaneously 949function updateQuantity(controlId, basketId, ratio, bUseFloatQuantity) 950{ 951 var oldVal = BX(controlId).defaultValue, 952 newVal = parseFloat(BX(controlId).value) || 0, 953 bIsCorrectQuantityForRatio = false, 954 autoCalculate = ((BX("auto_calculation") && BX("auto_calculation").value == "Y") || !BX("auto_calculation")); 955 956 if (ratio === 0 || ratio == 1) 957 { 958 bIsCorrectQuantityForRatio = true; 959 } 960 else 961 { 962 963 var newValInt = newVal * 10000, 964 ratioInt = ratio * 10000, 965 reminder = newValInt % ratioInt, 966 newValRound = parseInt(newVal); 967 968 if (reminder === 0) 969 { 970 bIsCorrectQuantityForRatio = true; 971 } 972 } 973 974 var bIsQuantityFloat = false; 975 976 if (parseInt(newVal) != parseFloat(newVal)) 977 { 978 bIsQuantityFloat = true; 979 } 980 981 newVal = (bUseFloatQuantity === false && bIsQuantityFloat === false) ? parseInt(newVal) : parseFloat(newVal).toFixed(4); 982 newVal = correctQuantity(newVal); 983 984 if (bIsCorrectQuantityForRatio) 985 { 986 BX(controlId).defaultValue = newVal; 987 988 BX("QUANTITY_INPUT_" + basketId).value = newVal; 989 990 // set hidden real quantity value (will be used in actual calculation) 991 BX("QUANTITY_" + basketId).value = newVal; 992 993 if (autoCalculate) 994 { 995 basketPoolQuantity.changeQuantity(basketId); 996 } 997 } 998 else 999 { 1000 newVal = getCorrectRatioQuantity(newVal, ratio, bUseFloatQuantity); 1001 newVal = correctQuantity(newVal); 1002 1003 if (newVal != oldVal) 1004 { 1005 BX("QUANTITY_INPUT_" + basketId).value = newVal; 1006 BX("QUANTITY_" + basketId).value = newVal; 1007 1008 if (autoCalculate) 1009 { 1010 basketPoolQuantity.changeQuantity(basketId); 1011 } 1012 }else 1013 { 1014 BX(controlId).value = oldVal; 1015 } 1016 } 1017} 1018 1019// used when quantity is changed by clicking on arrows 1020function setQuantity(basketId, ratio, sign, bUseFloatQuantity) 1021{ 1022 var curVal = parseFloat(BX("QUANTITY_INPUT_" + basketId).value), 1023 newVal; 1024 1025 newVal = (sign == 'up') ? curVal + ratio : curVal - ratio; 1026 1027 if (newVal < 0) 1028 newVal = 0; 1029 1030 if (bUseFloatQuantity) 1031 { 1032 newVal = parseFloat(newVal).toFixed(4); 1033 } 1034 newVal = correctQuantity(newVal); 1035 1036 if (ratio > 0 && newVal < ratio) 1037 { 1038 newVal = ratio; 1039 } 1040 1041 if (!bUseFloatQuantity && newVal != newVal.toFixed(4)) 1042 { 1043 newVal = parseFloat(newVal).toFixed(4); 1044 } 1045 1046 newVal = getCorrectRatioQuantity(newVal, ratio, bUseFloatQuantity); 1047 newVal = correctQuantity(newVal); 1048 1049 BX("QUANTITY_INPUT_" + basketId).value = newVal; 1050 BX("QUANTITY_INPUT_" + basketId).defaultValue = newVal; 1051 1052 updateQuantity('QUANTITY_INPUT_' + basketId, basketId, ratio, bUseFloatQuantity); 1053} 1054 1055function getCorrectRatioQuantity(quantity, ratio, bUseFloatQuantity) 1056{ 1057 var newValInt = quantity * 10000, 1058 ratioInt = ratio * 10000, 1059 reminder = (quantity / ratio - ((quantity / ratio).toFixed(0))).toFixed(6), 1060 result = quantity, 1061 bIsQuantityFloat = false, 1062 i; 1063 ratio = parseFloat(ratio); 1064 1065 if (reminder == 0) 1066 { 1067 return result; 1068 } 1069 1070 if (ratio !== 0 && ratio != 1) 1071 { 1072 for (i = ratio, max = parseFloat(quantity) + parseFloat(ratio); i <= max; i = parseFloat(parseFloat(i) + parseFloat(ratio)).toFixed(4)) 1073 { 1074 result = i; 1075 } 1076 1077 }else if (ratio === 1) 1078 { 1079 result = quantity | 0; 1080 } 1081 1082 if (parseInt(result, 10) != parseFloat(result)) 1083 { 1084 bIsQuantityFloat = true; 1085 } 1086 1087 result = (bUseFloatQuantity === false && bIsQuantityFloat === false) ? parseInt(result, 10) : parseFloat(result).toFixed(4); 1088 result = correctQuantity(result); 1089 return result; 1090} 1091 1092function correctQuantity(quantity) 1093{ 1094 return parseFloat((quantity * 1).toString()); 1095} 1096 1097 1098/** 1099 * 1100 * @param {} params 1101 */ 1102function recalcBasketAjax(params) 1103{ 1104 if (basketPoolQuantity.isProcessing()) 1105 { 1106 return false; 1107 } 1108 1109 BX.showWait(); 1110 1111 var property_values = {}, 1112 action_var = BX('action_var').value, 1113 items = BX('basket_items'), 1114 delayedItems = BX('delayed_items'), 1115 postData, 1116 i; 1117 1118 postData = { 1119 'sessid': BX.bitrix_sessid(), 1120 'site_id': BX.message('SITE_ID'), 1121 'props': property_values, 1122 'action_var': action_var, 1123 'select_props': BX('column_headers').value, 1124 'offers_props': BX('offers_props').value, 1125 'quantity_float': BX('quantity_float').value, 1126 'price_vat_show_value': BX('price_vat_show_value').value, 1127 'hide_coupon': BX('hide_coupon').value, 1128 'use_prepayment': BX('use_prepayment').value 1129 }; 1130 postData[action_var] = 'recalculate'; 1131 if (!!params && typeof params === 'object') 1132 { 1133 for (i in params) 1134 { 1135 if (params.hasOwnProperty(i)) 1136 postData[i] = params[i]; 1137 } 1138 } 1139 1140 if (!!items && items.rows.length > 0) 1141 { 1142 for (i = 1; items.rows.length > i; i++) 1143 postData['QUANTITY_' + items.rows[i].id] = BX('QUANTITY_' + items.rows[i].id).value; 1144 } 1145 1146 if (!!delayedItems && delayedItems.rows.length > 0) 1147 { 1148 for (i = 1; delayedItems.rows.length > i; i++) 1149 postData['DELAY_' + delayedItems.rows[i].id] = 'Y'; 1150 } 1151 1152 basketPoolQuantity.setProcessing(true); 1153 basketPoolQuantity.clearPool(); 1154
1155 BX.ajax({ 1156 url: '/bitrix/components/bitrix/sale.basket.basket/ajax.php', 1157 method: 'POST', 1158 data: postData, 1159 dataType: 'json', 1160 onsuccess: function(result) 1161 { 1162 BX.closeWait(); 1163 basketPoolQuantity.setProcessing(false); 1164 1165 if(params.coupon) 1166 { 1167 //hello, gifts! 1168 if(!!result && !!result.BASKET_DATA && !!result.BASKET_DATA.NEED_TO_RELOAD_FOR_GETTING_GIFTS) 1169 { 1170 BX.reload(); 1171 } 1172 } 1173 1174 if (basketPoolQuantity.isPoolEmpty()) 1175 { 1176 updateBasketTable(null, result); 1177 basketPoolQuantity.updateQuantity(); 1178 } 1179 else 1180 { 1181 basketPoolQuantity.enableTimer(true); 1182 } 1183 } 1184 }); 1185} 1186 1187function showBasketItemsList(val) 1188{ 1189 BX.removeClass(BX("basket_toolbar_button"), "current"); 1190 BX.removeClass(BX("basket_toolbar_button_delayed"), "current"); 1191 BX.removeClass(BX("basket_toolbar_button_subscribed"), "current"); 1192 BX.removeClass(BX("basket_toolbar_button_not_available"), "current"); 1193 1194 BX("normal_count").style.display = 'inline-block'; 1195 BX("delay_count").style.display = 'inline-block'; 1196 BX("subscribe_count").style.display = 'inline-block'; 1197 BX("not_available_count").style.display = 'inline-block'; 1198 1199 if (val == 2) 1200 { 1201 if (BX("basket_items_list")) 1202 BX("basket_items_list").style.display = 'none'; 1203 if (BX("basket_items_delayed")) 1204 { 1205 BX("basket_items_delayed").style.display = 'block'; 1206 BX.addClass(BX("basket_toolbar_button_delayed"), "current"); 1207 BX("delay_count").style.display = 'none'; 1208 } 1209 if (BX("basket_items_subscribed")) 1210 BX("basket_items_subscribed").style.display = 'none'; 1211 if (BX("basket_items_not_available")) 1212 BX("basket_items_not_available").style.display = 'none'; 1213 } 1214 else if(val == 3) 1215 { 1216 if (BX("basket_items_list")) 1217 BX("basket_items_list").style.display = 'none'; 1218 if (BX("basket_items_delayed")) 1219 BX("basket_items_delayed").style.display = 'none'; 1220 if (BX("basket_items_subscribed")) 1221 { 1222 BX("basket_items_subscribed").style.display = 'block'; 1223 BX.addClass(BX("basket_toolbar_button_subscribed"), "current"); 1224 BX("subscribe_count").style.display = 'none'; 1225 } 1226 if (BX("basket_items_not_available")) 1227 BX("basket_items_not_available").style.display = 'none'; 1228 } 1229 else if (val == 4) 1230 { 1231 if (BX("basket_items_list")) 1232 BX("basket_items_list").style.display = 'none'; 1233 if (BX("basket_items_delayed")) 1234 BX("basket_items_delayed").style.display = 'none'; 1235 if (BX("basket_items_subscribed")) 1236 BX("basket_items_subscribed").style.display = 'none'; 1237 if (BX("basket_items_not_available")) 1238 { 1239 BX("basket_items_not_available").style.display = 'block'; 1240 BX.addClass(BX("basket_toolbar_button_not_available"), "current"); 1241 BX("not_available_count").style.display = 'none'; 1242 } 1243 } 1244 else 1245 { 1246 if (BX("basket_items_list")) 1247 { 1248 BX("basket_items_list").style.display = 'block'; 1249 BX.addClass(BX("basket_toolbar_button"), "current"); 1250 BX("normal_count").style.display = 'none'; 1251 } 1252 if (BX("basket_items_delayed")) 1253 BX("basket_items_delayed").style.display = 'none'; 1254 if (BX("basket_items_subscribed")) 1255 BX("basket_items_subscribed").style.display = 'none'; 1256 if (BX("basket_items_not_available")) 1257 BX("basket_items_not_available").style.display = 'none'; 1258 } 1259} 1260 1261function deleteCoupon() 1262{ 1263 var target = this, 1264 value; 1265 1266 if (BX.type.isElementNode(target) && target.hasAttribute('data-coupon')) 1267 { 1268 value = target.getAttribute('data-coupon'); 1269 if (BX.type.isNotEmptyString(value)) 1270 { 1271 recalcBasketAjax({'delete_coupon' : value}); 1272 } 1273 } 1274} 1275 1276function deleteProductRow(target) 1277{ 1278 var targetRow = BX.findParent(target, {tagName: 'TR'}), 1279 quantityNode, 1280 delItem; 1281 1282 if (targetRow) 1283 { 1284 quantityNode = BX('QUANTITY_' + targetRow.id); 1285 if (quantityNode) 1286 { 1287 delItem = getCurrentItemAnalyticsInfo(targetRow, quantityNode.value); 1288 } 1289 } 1290 1291 setAnalyticsDataLayer([], [delItem]); 1292 1293 document.location.href = target.href; 1294 1295 return false; 1296} 1297 1298function checkAnalytics(currentQuantity, newItems) 1299{ 1300 if (!currentQuantity || !newItems || BX.util.array_values(currentQuantity).length === 0) 1301 return; 1302 1303 var itemId, diff, 1304 current = {}, addItems = [], delItems = [], 1305 i; 1306 1307 if (!!newItems && newItems.rows.length) 1308 { 1309 for (i = 1; newItems.rows.length > i; i++) 1310 { 1311 itemId = newItems.rows[i].id; 1312 diff = BX('QUANTITY_' + itemId).value - currentQuantity[itemId]; 1313 1314 if (diff != 0) 1315 { 1316 current = getCurrentItemAnalyticsInfo(newItems.rows[i], diff); 1317 1318 if (diff > 0) 1319 { 1320 addItems.push(current); 1321 } 1322 else 1323 { 1324 delItems.push(current); 1325 } 1326 } 1327 } 1328 } 1329 1330 if (addItems.length || delItems.length) 1331 { 1332 setAnalyticsDataLayer(addItems, delItems); 1333 } 1334} 1335 1336function getCurrentItemAnalyticsInfo(row, diff) 1337{ 1338 if (!row) 1339 return; 1340 1341 var temp, k, variants = []; 1342 1343 var current = { 1344 'name': row.getAttribute('data-item-name') || '', 1345 'id': row.id, 1346 'price': row.getAttribute('data-item-price') || 0, 1347 'brand': (row.getAttribute('data-item-brand') || '').split(', ').join('/'), 1348 'variant': '', 1349 'quantity': Math.abs(diff) 1350 }; 1351 1352 temp = row.querySelectorAll('.bx_active[data-sku-name]'); 1353 for (k = 0; k < temp.length; k++) 1354 { 1355 variants.push(temp[k].getAttribute('data-sku-name')); 1356 } 1357 1358 current.variant = variants.join('/'); 1359 1360 return current; 1361} 1362 1363function setAnalyticsDataLayer(addItems, delItems) 1364{ 1365 window[basketJSParams['DATA_LAYER_NAME']] = window[basketJSParams['DATA_LAYER_NAME']] || []; 1366 1367 if (addItems && addItems.length) 1368 { 1369 window[basketJSParams['DATA_LAYER_NAME']].push({ 1370 'event': 'addToCart', 1371 'ecommerce': { 1372 'currencyCode': getCurrencyCode(), 1373 'add': { 1374 'products': addItems 1375 } 1376 } 1377 }); 1378 } 1379 1380 if (delItems && delItems.length) 1381 { 1382 window[basketJSParams['DATA_LAYER_NAME']].push({ 1383 'event': 'removeFromCart', 1384 'ecommerce': { 1385 'currencyCode': getCurrencyCode(), 1386 'remove': { 1387 'products': delItems 1388 } 1389 } 1390 }); 1391 } 1392} 1393 1394function getCurrencyCode() 1395{ 1396 var root = BX('basket_items'), 1397 node, 1398 currency = ''; 1399 1400 if (root) 1401 {
1402 node = root.querySelector('[data-item-currency]'); 1403 node && (currency = node.getAttribute('data-item-currency')); 1404 } 1405 1406 return currency; 1407 1408 1409} 1410 1411BX.ready(function() { 1412 basketPoolQuantity = new BasketPoolQuantity(); 1413 var couponBlock = BX('coupons_block'), 1414 basketItems = BX('basket_items'); 1415 1416 if (BX.type.isElementNode(couponBlock)) 1417 BX.bindDelegate(couponBlock, 'click', { 'attribute': 'data-coupon' }, deleteCoupon); 1418 1419 if (BX.type.isElementNode(basketItems)) 1420 BX.bindDelegate(basketItems, 'click', {tagName: 'li', 'attr': { 'data-sku-selector': 'Y' }}, skuPropClickHandler); 1421 1422 if (BX.type.isNotEmptyString(basketJSParams['EVENT_ONCHANGE_ON_START']) && basketJSParams['EVENT_ONCHANGE_ON_START'] == "Y") 1423 BX.onCustomEvent('OnBasketChange'); 1424 1425 const authBlock = document.querySelector('.user-auth-info-link'); 1426 1427 if (authBlock) { 1428 1429 const authLink = authBlock.querySelector(".personal-link-login"); 1430 const registerLink = authBlock.querySelector(".personal-link-signup"); 1431 1432 if (authLink && registerLink) { 1433 1434 authLink.addEventListener('click', () => { 1435 window.showBXMakerFormLogin(); 1436 }); 1437 1438 registerLink.addEventListener('click', () => { 1439 window.showBXMakerFormRegister(); 1440 }); 1441 } 1442 1443 // authBlock.querySelector(".personal-link-login").addEventListener('click' () => { 1444 // window.showBXMakerFormLogin(); 1445 // }); 1446 1447 // authBlock.querySelector(".personal-link-signup").addEventListener('click' () => { 1448 // window.showBXMakerFormRegister(); 1449 // }); 1450 } 1451}); 1452 1453 1454function toggleItemBacket () { 1455 if ($(window).width() <= '767') { 1456 var currentItem = $('.basket-items-list-header-filter-item.active').html(); 1457 1458 $('.basket-items-list-header-filter-visibleItem-js').html(currentItem); 1459 if(!$(".basket-items-list-header-filter-visibleItem-js").hasClass('open')) { 1460 $(".basket-items-list-header-filter-visibleItem-js").addClass('open'); 1461 } else { 1462 $(".basket-items-list-header-filter-visibleItem-js").removeClass('open'); 1463 } 1464 1465 $('.basket-items-list-header-filter-item').css('display', 'block'); 1466 if(!$(".basket-items-list-header-filter-hide-js").hasClass('open')) { 1467 $(".basket-items-list-header-filter-hide-js").addClass('open'); 1468 $(".basket-items-list-header-filter-hide-js").css('display', 'flex'); 1469 } else { 1470 $(".basket-items-list-header-filter-hide-js").removeClass('open'); 1471 $(".basket-items-list-header-filter-hide-js").css('display', 'none'); 1472 } 1473 } 1474} 1475 1476 1477$(document).on('click', ".basket-items-list-header-filter-visible-js", function () { 1478 toggleItemBacket (); 1479}); 1480/* End */ 1481; 1482; /* Start:"a:4:{s:4:"full";s:120:"/local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/mustache.js?178187500020177";s:6:"source";s:104:"/local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/mustache.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/ 1483/*! 1484 * mustache.js - Logic-less {{mustache}} templates with JavaScript 1485 * http://github.com/janl/mustache.js 1486 * 1487 * Copyright (c) 2009 Chris Wanstrath (Ruby) 1488 * Copyright (c) 2010-2014 Jan Lehnardt (JavaScript) 1489 * Copyright (c) 2010-2015 The mustache.js community 1490 * 1491 * Licensed under MIT (https://github.com/janl/mustache.js/blob/master/LICENSE) 1492 */ 1493 1494/*global define: false Mustache: true*/ 1495 1496(function defineMustache (global, factory) { 1497 if (typeof exports === 'object' && exports && typeof exports.nodeName !== 'string') { 1498 factory(exports); // CommonJS 1499 } else if (typeof define === 'function' && define.amd) { 1500 define(['exports'], factory); // AMD 1501 } else { 1502 global.Mustache = {}; 1503 factory(global.Mustache); // script, wsh, asp 1504 } 1505}(this, function mustacheFactory (mustache) { 1506 1507 var objectToString = Object.prototype.toString; 1508 var isArray = Array.isArray || function isArrayPolyfill (object) { 1509 return objectToString.call(object) === '[object Array]'; 1510 }; 1511 1512 function isFunction (object) { 1513 return typeof object === 'function'; 1514 } 1515 1516 /** 1517 * More correct typeof string handling array 1518 * which normally returns typeof 'object' 1519 */ 1520 function typeStr (obj) { 1521 return isArray(obj) ? 'array' : typeof obj; 1522 } 1523 1524 function escapeRegExp (string) { 1525 return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&'); 1526 } 1527 1528 /** 1529 * Null safe way of checking whether or not an object, 1530 * including its prototype, has a given property 1531 */ 1532 function hasProperty (obj, propName) { 1533 return obj != null && typeof obj === 'object' && (propName in obj); 1534 } 1535 1536 // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577 1537 // See https://github.com/janl/mustache.js/issues/189 1538 var regExpTest = RegExp.prototype.test; 1539 function testRegExp (re, string) { 1540 return regExpTest.call(re, string); 1541 } 1542 1543 var nonSpaceRe = /\S/; 1544 function isWhitespace (string) { 1545 return !testRegExp(nonSpaceRe, string); 1546 } 1547 1548 var entityMap = { 1549 '&': '&', 1550 '<': '<', 1551 '>': '>', 1552 '"': '"', 1553 "'": ''', 1554 '/': '/', 1555 '`': '`', 1556 '=': '=' 1557 }; 1558 1559 function escapeHtml (string) { 1560 return String(string).replace(/[&<>
vendor: 9,061 bytes, lines 1560-1868
1560"'`=\/]/g, function fromEntityMap (s) { 1561 return entityMap[s]; 1562 }); 1563 } 1564 1565 var whiteRe = /\s*/; 1566 var spaceRe = /\s+/; 1567 var equalsRe = /\s*=/; 1568 var curlyRe = /\s*\}/; 1569 var tagRe = /#|\^|\/|>|\{|&|=|!/; 1570 1571 /** 1572 * Breaks up the given `template` string into a tree of tokens. If the `tags` 1573 * argument is given here it must be an array with two string values: the 1574 * opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of 1575 * course, the default is to use mustaches (i.e. mustache.tags). 1576 * 1577 * A token is an array with at least 4 elements. The first element is the 1578 * mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag 1579 * did not contain a symbol (i.e. {{myValue}}) this element is "name". For 1580 * all text that appears outside a symbol this element is "text". 1581 * 1582 * The second element of a token is its "value". For mustache tags this is 1583 * whatever else was inside the tag besides the opening symbol. For text tokens 1584 * this is the text itself. 1585 * 1586 * The third and fourth elements of the token are the start and end indices, 1587 * respectively, of the token in the original template. 1588 * 1589 * Tokens that are the root node of a subtree contain two more elements: 1) an 1590 * array of tokens in the subtree and 2) the index in the original template at 1591 * which the closing tag for that section begins. 1592 */ 1593 function parseTemplate (template, tags) { 1594 if (!template) 1595 return []; 1596 1597 var sections = []; // Stack to hold section tokens 1598 var tokens = []; // Buffer to hold the tokens 1599 var spaces = []; // Indices of whitespace tokens on the current line 1600 var hasTag = false; // Is there a {{tag}} on the current line? 1601 var nonSpace = false; // Is there a non-space char on the current line? 1602 1603 // Strips all whitespace tokens array for the current line 1604 // if there was a {{#tag}} on it and otherwise only space. 1605 function stripSpace () { 1606 if (hasTag && !nonSpace) { 1607 while (spaces.length) 1608 delete tokens[spaces.pop()]; 1609 } else { 1610 spaces = []; 1611 } 1612 1613 hasTag = false; 1614 nonSpace = false; 1615 } 1616 1617 var openingTagRe, closingTagRe, closingCurlyRe; 1618 function compileTags (tagsToCompile) { 1619 if (typeof tagsToCompile === 'string') 1620 tagsToCompile = tagsToCompile.split(spaceRe, 2); 1621 1622 if (!isArray(tagsToCompile) || tagsToCompile.length !== 2) 1623 throw new Error('Invalid tags: ' + tagsToCompile); 1624 1625 openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + '\\s*'); 1626 closingTagRe = new RegExp('\\s*' + escapeRegExp(tagsToCompile[1])); 1627 closingCurlyRe = new RegExp('\\s*' + escapeRegExp('}' + tagsToCompile[1])); 1628 } 1629 1630 compileTags(tags || mustache.tags); 1631 1632 var scanner = new Scanner(template); 1633 1634 var start, type, value, chr, token, openSection; 1635 while (!scanner.eos()) { 1636 start = scanner.pos; 1637 1638 // Match any text between tags. 1639 value = scanner.scanUntil(openingTagRe); 1640 1641 if (value) { 1642 for (var i = 0, valueLength = value.length; i < valueLength; ++i) { 1643 chr = value.charAt(i); 1644 1645 if (isWhitespace(chr)) { 1646 spaces.push(tokens.length); 1647 } else { 1648 nonSpace = true; 1649 } 1650 1651 tokens.push([ 'text', chr, start, start + 1 ]); 1652 start += 1; 1653 1654 // Check for whitespace on the current line. 1655 if (chr === '\n') 1656 stripSpace(); 1657 } 1658 } 1659 1660 // Match the opening tag. 1661 if (!scanner.scan(openingTagRe)) 1662 break; 1663 1664 hasTag = true; 1665 1666 // Get the tag type. 1667 type = scanner.scan(tagRe) || 'name'; 1668 scanner.scan(whiteRe); 1669 1670 // Get the tag value. 1671 if (type === '=') { 1672 value = scanner.scanUntil(equalsRe); 1673 scanner.scan(equalsRe); 1674 scanner.scanUntil(closingTagRe); 1675 } else if (type === '{') { 1676 value = scanner.scanUntil(closingCurlyRe); 1677 scanner.scan(curlyRe); 1678 scanner.scanUntil(closingTagRe); 1679 type = '&'; 1680 } else { 1681 value = scanner.scanUntil(closingTagRe); 1682 } 1683 1684 // Match the closing tag. 1685 if (!scanner.scan(closingTagRe)) 1686 throw new Error('Unclosed tag at ' + scanner.pos); 1687 1688 token = [ type, value, start, scanner.pos ]; 1689 tokens.push(token); 1690 1691 if (type === '#' || type === '^') { 1692 sections.push(token); 1693 } else if (type === '/') { 1694 // Check section nesting. 1695 openSection = sections.pop(); 1696 1697 if (!openSection) 1698 throw new Error('Unopened section "' + value + '" at ' + start); 1699 1700 if (openSection[1] !== value) 1701 throw new Error('Unclosed section "' + openSection[1] + '" at ' + start); 1702 } else if (type === 'name' || type === '{' || type === '&') { 1703 nonSpace = true; 1704 } else if (type === '=') { 1705 // Set the tags for the next time around. 1706 compileTags(value); 1707 } 1708 } 1709 1710 // Make sure there are no open sections when we're done. 1711 openSection = sections.pop(); 1712 1713 if (openSection) 1714 throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos); 1715 1716 return nestTokens(squashTokens(tokens)); 1717 } 1718 1719 /** 1720 * Combines the values of consecutive text tokens in the given `tokens` array 1721 * to a single token. 1722 */ 1723 function squashTokens (tokens) { 1724 var squashedTokens = []; 1725 1726 var token, lastToken; 1727 for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) { 1728 token = tokens[i]; 1729 1730 if (token) { 1731 if (token[0] === 'text' && lastToken && lastToken[0] === 'text') { 1732 lastToken[1] += token[1]; 1733 lastToken[3] = token[3]; 1734 } else { 1735 squashedTokens.push(token); 1736 lastToken = token; 1737 } 1738 } 1739 } 1740 1741 return squashedTokens; 1742 } 1743 1744 /** 1745 * Forms the given array of `tokens` into a nested tree structure where 1746 * tokens that represent a section have two additional items: 1) an array of 1747 * all tokens that appear in that section and 2) the index in the original 1748 * template that represents the end of that section. 1749 */ 1750 function nestTokens (tokens) { 1751 var nestedTokens = []; 1752 var collector = nestedTokens; 1753 var sections = []; 1754 1755 var token, section; 1756 for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) { 1757 token = tokens[i]; 1758 1759 switch (token[0]) { 1760 case '#': 1761 case '^': 1762 collector.push(token); 1763 sections.push(token); 1764 collector = token[4] = []; 1765 break; 1766 case '/': 1767 section = sections.pop(); 1768 section[5] = token[2]; 1769 collector = sections.length > 0 ? sections[sections.length - 1][4] : nestedTokens; 1770 break; 1771 default: 1772 collector.push(token); 1773 } 1774 } 1775 1776 return nestedTokens; 1777 } 1778 1779 /** 1780 * A simple string scanner that is used by the template parser to find 1781 * tokens in template strings. 1782 */ 1783 function Scanner (string) { 1784 this.string = string; 1785 this.tail = string; 1786 this.pos = 0; 1787 } 1788 1789 /** 1790 * Returns `true` if the tail is empty (end of string). 1791 */ 1792 Scanner.prototype.eos = function eos () { 1793 return this.tail === ''; 1794 }; 1795 1796 /** 1797 * Tries to match the given regular expression at the current position. 1798 * Returns the matched text if it can match, the empty string otherwise. 1799 */ 1800 Scanner.prototype.scan = function scan (re) { 1801 var match = this.tail.match(re); 1802 1803 if (!match || match.index !== 0) 1804 return ''; 1805 1806 var string = match[0]; 1807 1808 this.tail = this.tail.substring(string.length); 1809 this.pos += string.length; 1810 1811 return string; 1812 }; 1813 1814 /** 1815 * Skips all text until the given regular expression can be matched. Returns 1816 * the skipped string, which is the entire tail if no match can be made. 1817 */ 1818 Scanner.prototype.scanUntil = function scanUntil (re) { 1819 var index = this.tail.search(re), match; 1820 1821 switch (index) { 1822 case -1: 1823 match = this.tail; 1824 this.tail = ''; 1825 break; 1826 case 0: 1827 match = ''; 1828 break; 1829 default: 1830 match = this.tail.substring(0, index); 1831 this.tail = this.tail.substring(index); 1832 } 1833 1834 this.pos += match.length; 1835 1836 return match; 1837 }; 1838 1839 /** 1840 * Represents a rendering context by wrapping a view object and 1841 * maintaining a reference to the parent context. 1842 */ 1843 function Context (view, parentContext) { 1844 this.view = view; 1845 this.cache = { '.': this.view }; 1846 this.parent = parentContext; 1847 } 1848 1849 /** 1850 * Creates a new context using the given view with this context 1851 * as the parent. 1852 */ 1853 Context.prototype.push = function push (view) { 1854 return new Context(view, this); 1855 }; 1856 1857 /** 1858 * Returns the value of the given name in this context, traversing 1859 * up the context hierarchy if the value is absent in this context's view. 1860 */ 1861 Context.prototype.lookup = function lookup (name) { 1862 var cache = this.cache; 1863 1864 var value; 1865 if (cache.hasOwnProperty(name)) { 1866 value = cache[name]; 1867 } else { 1868 var context = this, names, index, lookupHit = false;
1869 1870 while (context) { 1871 if (name.indexOf('.') > 0) { 1872 value = context.view; 1873 names = name.split('.'); 1874 index = 0; 1875 1876 /** 1877 * Using the dot notion path in `name`, we descend through the 1878 * nested objects. 1879 * 1880 * To be certain that the lookup has been successful, we have to 1881 * check if the last object in the path actually has the property 1882 * we are looking for. We store the result in `lookupHit`. 1883 * 1884 * This is specially necessary for when the value has been set to 1885 * `undefined` and we want to avoid looking up parent contexts. 1886 **/ 1887 while (value != null && index < names.length) { 1888 if (index === names.length - 1) 1889 lookupHit = hasProperty(value, names[index]); 1890 1891 value = value[names[index++]]; 1892 } 1893 } else { 1894 value = context.view[name]; 1895 lookupHit = hasProperty(context.view, name); 1896 } 1897 1898 if (lookupHit) 1899 break; 1900 1901 context = context.parent; 1902 } 1903 1904 cache[name] = value; 1905 } 1906 1907 if (isFunction(value)) 1908 value = value.call(this.view); 1909 1910 return value; 1911 }; 1912 1913 /** 1914 * A Writer knows how to take a stream of tokens and render them to a 1915 * string, given a context. It also maintains a cache of templates to 1916 * avoid the need to parse the same template twice. 1917 */ 1918 function Writer () { 1919 this.cache = {}; 1920 } 1921 1922 /** 1923 * Clears all cached templates in this writer. 1924 */ 1925 Writer.prototype.clearCache = function clearCache () { 1926 this.cache = {}; 1927 }; 1928 1929 /** 1930 * Parses and caches the given `template` and returns the array of tokens 1931 * that is generated from the parse. 1932 */ 1933 Writer.prototype.parse = function parse (template, tags) { 1934 var cache = this.cache; 1935 var tokens = cache[template]; 1936 1937 if (tokens == null) 1938 tokens = cache[template + ':' + (tags || mustache.tags).join(':')] = parseTemplate(template, tags); 1939 1940 return tokens; 1941 }; 1942 1943 /** 1944 * High-level method that is used to render the given `template` with 1945 * the given `view`. 1946 * 1947 * The optional `partials` argument may be an object that contains the 1948 * names and templates of partials that are used in the template. It may 1949 * also be a function that is used to load partial templates on the fly 1950 * that takes a single argument: the name of the partial. 1951 */ 1952 Writer.prototype.render = function render (template, view, partials) { 1953 1954 var tokens = this.parse(template); 1955 1956 1957 var context = (view instanceof Context) ? view : new Context(view); 1958 1959 return this.renderTokens(tokens, context, partials, template); 1960 }; 1961 1962 /** 1963 * Low-level method that renders the given array of `tokens` using 1964 * the given `context` and `partials`. 1965 * 1966 * Note: The `originalTemplate` is only ever used to extract the portion 1967 * of the original template that was contained in a higher-order section. 1968 * If the template doesn't use higher-order sections, this argument may 1969 * be omitted. 1970 */ 1971 Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate) { 1972 var buffer = ''; 1973 1974 1975 var token, symbol, value; 1976 for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) { 1977 value = undefined; 1978 token = tokens[i]; 1979 symbol = token[0]; 1980 1981 1982 if (symbol === '#') value = this.renderSection(token, context, partials, originalTemplate); 1983 else if (symbol === '^') value = this.renderInverted(token, context, partials, originalTemplate); 1984 else if (symbol === '>') value = this.renderPartial(token, context, partials, originalTemplate); 1985 else if (symbol === '&') value = this.unescapedValue(token, context); 1986 else if (symbol === 'name') value = this.escapedValue(token, context); 1987 else if (symbol === 'text') value = this.rawValue(token); 1988 1989 if ('ITEMS_CROSSEL' == token[1]){ 1990 1991 if (value !== undefined){ 1992 BX.ajax({ 1993 method: 'POST', 1994 data: {value}, 1995 async: false, 1996 url: '/include/new_ajax/basket/crossel.php', 1997 onsuccess: function (data){ 1998 if (data !== undefined) 1999 buffer += data; 2000 }, 2001 onerror : function (data){ 2002 console.log( 'Error' ); 2003 } 2004 }); 2005 } 2006 2007 continue; 2008 } 2009 2010 if (value !== undefined) 2011 buffer += value; 2012 } 2013 2014 return buffer; 2015 }; 2016
vendor: 4,981 bytes, lines 2017-2159
2017 Writer.prototype.renderSection = function renderSection (token, context, partials, originalTemplate) { 2018 var self = this; 2019 var buffer = ''; 2020 var value = context.lookup(token[1]); 2021 2022 // This function is used to render an arbitrary template 2023 // in the current context by higher-order sections. 2024 function subRender (template) { 2025 return self.render(template, context, partials); 2026 } 2027 2028 if (!value) return; 2029 2030 if (isArray(value)) { 2031 for (var j = 0, valueLength = value.length; j < valueLength; ++j) { 2032 buffer += this.renderTokens(token[4], context.push(value[j]), partials, originalTemplate); 2033 } 2034 } else if (typeof value === 'object' || typeof value === 'string' || typeof value === 'number') { 2035 buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate); 2036 } else if (isFunction(value)) { 2037 if (typeof originalTemplate !== 'string') 2038 throw new Error('Cannot use higher-order sections without the original template'); 2039 2040 // Extract the portion of the original template that the section contains. 2041 value = value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender); 2042 2043 if (value != null) 2044 buffer += value; 2045 } else { 2046 buffer += this.renderTokens(token[4], context, partials, originalTemplate); 2047 } 2048 return buffer; 2049 }; 2050 2051 Writer.prototype.renderInverted = function renderInverted (token, context, partials, originalTemplate) { 2052 var value = context.lookup(token[1]); 2053 2054 // Use JavaScript's definition of falsy. Include empty arrays. 2055 // See https://github.com/janl/mustache.js/issues/186 2056 if (!value || (isArray(value) && value.length === 0)) 2057 return this.renderTokens(token[4], context, partials, originalTemplate); 2058 }; 2059 2060 Writer.prototype.renderPartial = function renderPartial (token, context, partials) { 2061 if (!partials) return; 2062 2063 var value = isFunction(partials) ? partials(token[1]) : partials[token[1]]; 2064 if (value != null) 2065 return this.renderTokens(this.parse(value), context, partials, value); 2066 }; 2067 2068 Writer.prototype.unescapedValue = function unescapedValue (token, context) { 2069 var value = context.lookup(token[1]); 2070 if (value != null) 2071 return value; 2072 }; 2073 2074 Writer.prototype.escapedValue = function escapedValue (token, context) { 2075 var value = context.lookup(token[1]); 2076 if (value != null) 2077 return mustache.escape(value); 2078 }; 2079 2080 Writer.prototype.rawValue = function rawValue (token) { 2081 return token[1]; 2082 }; 2083 2084 mustache.name = 'mustache.js'; 2085 mustache.version = '2.3.0'; 2086 mustache.tags = [ '{{', '}}' ]; 2087 2088 // All high-level mustache.* functions use this writer. 2089 var defaultWriter = new Writer(); 2090 2091 /** 2092 * Clears all cached templates in the default writer. 2093 */ 2094 mustache.clearCache = function clearCache () { 2095 return defaultWriter.clearCache(); 2096 }; 2097 2098 /** 2099 * Parses and caches the given template in the default writer and returns the 2100 * array of tokens it contains. Doing this ahead of time avoids the need to 2101 * parse templates on the fly as they are rendered. 2102 */ 2103 mustache.parse = function parse (template, tags) { 2104 return defaultWriter.parse(template, tags); 2105 }; 2106 2107 /** 2108 * Renders the `template` with the given `view` and `partials` using the 2109 * default writer. 2110 */ 2111 mustache.render = function render (template, view, partials) { 2112 if (typeof template !== 'string') { 2113 throw new TypeError('Invalid template! Template should be a "string" ' + 2114 'but "' + typeStr(template) + '" was given as the first ' + 2115 'argument for mustache#render(template, view, partials)'); 2116 } 2117 2118 return defaultWriter.render(template, view, partials); 2119 }; 2120 2121 // This is here for backwards compatibility with 0.4.x., 2122 /*eslint-disable */ // eslint wants camel cased function name 2123 mustache.to_html = function to_html (template, view, partials, send) { 2124 /*eslint-enable*/ 2125 2126 var result = mustache.render(template, view, partials); 2127 2128 if (isFunction(send)) { 2129 send(result); 2130 } else { 2131 return result; 2132 } 2133 }; 2134 2135 // Export the escaping function so that the user may override it. 2136 // See https://github.com/janl/mustache.js/issues/244 2137 mustache.escape = escapeHtml; 2138 2139 // Export these mainly for testing, but also for advanced usage. 2140 mustache.Scanner = Scanner; 2141 mustache.Context = Context; 2142 mustache.Writer = Writer; 2143 2144 return mustache; 2145})); 2146 2147/* End */ 2148; 2149; /* Start:"a:4:{s:4:"full";s:122:"/local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/action-pool.js?17818750005918";s:6:"source";s:107:"/local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/action-pool.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/ 2150;(function(){ 2151 'use strict'; 2152 2153 BX.namespace('BX.Sale.BasketActionPool'); 2154 2155 BX.Sale.BasketActionPool = function(component) 2156 { 2157 this.component = component; 2158 2159 this.requestProcessing = false;
2160 this.updateTimer = null; 2161 2162 this.isBasketRefreshed = this.component.params.DEFERRED_REFRESH !== 'Y'; 2163 this.needFullRecalculation = this.component.params.DEFERRED_REFRESH === 'Y'; 2164 2165 this.pool = {}; 2166 this.lastActualPool = {}; 2167 2168 this.approvedAction = ['QUANTITY', 'DELETE', 'RESTORE', 'DELAY', 'OFFER', 'MERGE_OFFER']; 2169 2170 this.switchTimer(); 2171 }; 2172 2173 BX.Sale.BasketActionPool.prototype.setRefreshStatus = function(status) 2174 { 2175 this.isBasketRefreshed = !!status; 2176 }; 2177 2178 BX.Sale.BasketActionPool.prototype.getRefreshStatus = function() 2179 { 2180 return this.isBasketRefreshed; 2181 }; 2182 2183 BX.Sale.BasketActionPool.prototype.isItemInPool = function(itemId) 2184 { 2185 return !!this.pool[itemId]; 2186 }; 2187 2188 BX.Sale.BasketActionPool.prototype.clearLastActualQuantityPool = function(itemId) 2189 { 2190 this.lastActualPool[itemId] && delete this.lastActualPool[itemId].QUANTITY; 2191 }; 2192 2193 BX.Sale.BasketActionPool.prototype.checkItemPoolBefore = function(itemId) 2194 { 2195 if (!itemId) 2196 return; 2197 2198 this.pool[itemId] = this.pool[itemId] || {}; 2199 }; 2200 2201 BX.Sale.BasketActionPool.prototype.checkItemPoolAfter = function(itemId) 2202 { 2203 if (!itemId || !this.pool[itemId]) 2204 return; 2205 2206 if (Object.keys(this.pool[itemId]).length === 0) 2207 { 2208 delete this.pool[itemId]; 2209 } 2210 }; 2211 2212 BX.Sale.BasketActionPool.prototype.addCoupon = function(coupon) 2213 { 2214 this.pool.COUPON = coupon; 2215 2216 this.switchTimer(); 2217 }; 2218 2219 BX.Sale.BasketActionPool.prototype.removeCoupon = function(coupon) 2220 { 2221 this.checkItemPoolBefore('REMOVE_COUPON'); 2222 2223 this.pool.REMOVE_COUPON[coupon] = coupon; 2224 2225 this.switchTimer(); 2226 }; 2227 2228 BX.Sale.BasketActionPool.prototype.changeQuantity = function(itemId, quantity, oldQuantity) 2229 { 2230 this.checkItemPoolBefore(itemId); 2231 2232 if ( 2233 (this.lastActualPool[itemId] && this.lastActualPool[itemId].QUANTITY !== quantity) 2234 || (!this.lastActualPool[itemId] && quantity !== oldQuantity) 2235 ) 2236 { 2237 this.pool[itemId].QUANTITY = quantity; 2238 } 2239 else 2240 { 2241 this.pool[itemId] && delete this.pool[itemId].QUANTITY; 2242 } 2243 2244 this.checkItemPoolAfter(itemId); 2245 this.switchTimer(); 2246 }; 2247 2248 BX.Sale.BasketActionPool.prototype.deleteItem = function(itemId) 2249 { 2250 this.checkItemPoolBefore(itemId); 2251 2252 if (this.pool[itemId].RESTORE) 2253 { 2254 delete this.pool[itemId].RESTORE; 2255 } 2256 else 2257 { 2258 this.pool[itemId].DELETE = 'Y'; 2259 } 2260 2261 this.checkItemPoolAfter(itemId); 2262 this.switchTimer(); 2263 }; 2264 2265 BX.Sale.BasketActionPool.prototype.restoreItem = function(itemId, itemData) 2266 { 2267 this.checkItemPoolBefore(itemId); 2268 2269 if (this.pool[itemId].DELETE === 'Y') 2270 { 2271 delete this.pool[itemId].DELETE; 2272 } 2273 else 2274 { 2275 this.pool[itemId].RESTORE = itemData; 2276 } 2277 2278 this.checkItemPoolAfter(itemId); 2279 this.switchTimer(); 2280 }; 2281 2282 BX.Sale.BasketActionPool.prototype.addDelayed = function(itemId) 2283 { 2284 this.checkItemPoolBefore(itemId); 2285 2286 this.pool[itemId].DELAY = 'Y'; 2287 2288 this.checkItemPoolAfter(itemId); 2289 this.switchTimer(); 2290 }; 2291 2292 BX.Sale.BasketActionPool.prototype.removeDelayed = function(itemId) 2293 { 2294 this.checkItemPoolBefore(itemId); 2295 2296 this.pool[itemId].DELAY = 'N'; 2297 2298 this.checkItemPoolAfter(itemId); 2299 this.switchTimer(); 2300 }; 2301 2302 BX.Sale.BasketActionPool.prototype.changeSku = function(itemId, props, oldProps) 2303 { 2304 if (JSON.stringify(props) !== JSON.stringify(oldProps)) 2305 { 2306 this.checkItemPoolBefore(itemId); 2307 this.pool[itemId].OFFER = props; 2308 } 2309 else 2310 { 2311 this.pool[itemId] && delete this.pool[itemId].OFFER; 2312 this.checkItemPoolAfter(itemId); 2313 } 2314 2315 this.switchTimer(); 2316 }; 2317 2318 BX.Sale.BasketActionPool.prototype.mergeSku = function(itemId) 2319 { 2320 this.checkItemPoolBefore(itemId); 2321 this.pool[itemId].MERGE_OFFER = 'Y'; 2322 2323 this.switchTimer(); 2324 }; 2325 2326 BX.Sale.BasketActionPool.prototype.switchTimer = function() 2327 { 2328 clearTimeout(this.updateTimer); 2329 2330 if (this.isProcessing()) 2331 { 2332 return; 2333 } 2334 2335 if (this.isPoolEmpty()) 2336 { 2337 this.component.editPostponedBasketItems(); 2338 this.component.fireCustomEvents(); 2339 } 2340 2341 if (!this.isPoolEmpty()) 2342 { 2343 this.updateTimer = setTimeout(BX.proxy(this.trySendPool, this), 300); 2344 } 2345 else if (!this.getRefreshStatus()) 2346 { 2347 this.trySendPool(); 2348 } 2349 }; 2350 2351 BX.Sale.BasketActionPool.prototype.trySendPool = function() 2352 { 2353 if (this.isPoolEmpty() && this.getRefreshStatus()) 2354 { 2355 return; 2356 } 2357 2358 this.doProcessing(true); 2359 2360 if (!this.isPoolEmpty()) 2361 { 2362 this.component.sendRequest('recalculateAjax', { 2363 basket: this.getPoolData() 2364 }); 2365 2366 this.lastActualPool = this.pool; 2367 this.pool = {}; 2368 } 2369 else if (!this.getRefreshStatus()) 2370 { 2371 this.component.sendRequest('refreshAjax', { 2372 fullRecalculation: this.needFullRecalculation ? 'Y' : 'N' 2373 }); 2374 this.needFullRecalculation = false;
2375 } 2376 }; 2377 2378 BX.Sale.BasketActionPool.prototype.getPoolData = function() 2379 { 2380 var poolData = {}, 2381 currentPool = this.pool; 2382 2383 if (currentPool.COUPON) 2384 { 2385 poolData.coupon = currentPool.COUPON; 2386 delete currentPool.COUPON; 2387 } 2388 2389 if (currentPool.REMOVE_COUPON) 2390 { 2391 poolData.delete_coupon = currentPool.REMOVE_COUPON; 2392 delete currentPool.REMOVE_COUPON; 2393 } 2394 2395 for (var id in currentPool) 2396 { 2397 if (currentPool.hasOwnProperty(id)) 2398 { 2399 for (var action in currentPool[id]) 2400 { 2401 if (currentPool[id].hasOwnProperty(action) && BX.util.in_array(action, this.approvedAction)) 2402 { 2403 poolData[action + '_' + id] = currentPool[id][action]; 2404 } 2405 } 2406 } 2407 } 2408 2409 return poolData; 2410 }; 2411 2412 BX.Sale.BasketActionPool.prototype.isPoolEmpty = function() 2413 { 2414 return Object.keys(this.pool).length === 0; 2415 }; 2416 2417 BX.Sale.BasketActionPool.prototype.doProcessing = function(state) 2418 { 2419 this.requestProcessing = state === true; 2420 2421 if (this.requestProcessing) 2422 { 2423 this.component.startLoader(); 2424 } 2425 else 2426 { 2427 this.component.endLoader(); 2428 } 2429 }; 2430 2431 BX.Sale.BasketActionPool.prototype.isProcessing = function() 2432 { 2433 return this.requestProcessing === true; 2434 }; 2435})(); 2436/* End */ 2437; 2438; /* Start:"a:4:{s:4:"full";s:118:"/local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/filter.js?178187500014800";s:6:"source";s:102:"/local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/filter.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/ 2439;(function(){ 2440 'use strict'; 2441 2442 BX.namespace('BX.Sale.BasketFilter'); 2443 2444 BX.Sale.BasketFilter = function(component) 2445 { 2446 this.component = component; 2447 2448 this.activeFilterMode = false; 2449 this.filterTimer = null; 2450 this.mouseOverClearFilter = false; 2451 2452 this.realShownItems = []; 2453 this.realSortedItems = []; 2454 this.realScrollTop = 0; 2455 2456 this.lastShownItemsHash = ''; 2457 this.currentFilter = { 2458 query: '', 2459 similarHash: '', 2460 warning: false, 2461 notAvailable: false, 2462 delayed: false 2463 }; 2464 2465 if (this.component.useItemsFilter) 2466 { 2467 this.bindEvents(); 2468 } 2469 }; 2470 2471 BX.Sale.BasketFilter.prototype.bindEvents = function() 2472 { 2473 var entity; 2474 var filterNode = this.component.getEntity( 2475 this.component.getCacheNode(this.component.ids.itemListWrapper), 2476 'basket-filter' 2477 ); 2478 2479 entity = this.component.getEntity(filterNode, 'basket-filter-input'); 2480 if (BX.type.isDomNode(entity)) 2481 { 2482 // BX.bind(entity, 'focus', function() { 2483 // filterNode.style.flex = 3; 2484 // }); 2485 // BX.bind(entity, 'blur', BX.delegate(function() { 2486 // if (!this.mouseOverClearFilter) 2487 // { 2488 // filterNode.style.flex = ''; 2489 // } 2490 // }, this)); 2491 2492 BX.bind(entity, 'keyup', BX.proxy(this.onFilterInput, this)); 2493 BX.bind(entity, 'cut', BX.proxy(this.onFilterInput, this)); 2494 BX.bind(entity, 'paste', BX.proxy(this.onFilterInput, this)); 2495 } 2496 2497 entity = this.component.getEntity(filterNode, 'basket-filter-clear-btn'); 2498 if (BX.type.isDomNode(entity)) 2499 { 2500 BX.bind(entity, 'mouseenter', BX.delegate(function() { 2501 this.mouseOverClearFilter = true; 2502 }, this)); 2503 BX.bind(entity, 'mouseout', BX.delegate(function() { 2504 this.mouseOverClearFilter = false; 2505 }, this)); 2506 BX.bind(entity, 'click', BX.delegate(function() { 2507 if (!this.filterInputEmpty()) 2508 { 2509 this.clearFilterInput(); 2510 this.onFilterChange(); 2511 } 2512 2513 filterNode.style.flex = ''; 2514 }, this)); 2515 } 2516 }; 2517 2518 BX.Sale.BasketFilter.prototype.isActive = function() 2519 { 2520 return this.activeFilterMode; 2521 }; 2522 2523 BX.Sale.BasketFilter.prototype.showFilterByName = function(name) 2524 { 2525 if (!name) 2526 return; 2527 2528 switch (name) 2529 { 2530 case 'not-available': 2531 this.showNotAvailableItemsFilter(); 2532 break; 2533 case 'orderable': 2534 this.showOrderableItemsFilter(); 2535 break; 2536 case 'delayed': 2537 this.showDelayItemsFilter(); 2538 break; 2539 case 'warning': 2540 this.showWarningItemsFilter(); 2541 break; 2542 case 'similar': 2543 this.showSimilarItemsFilter(); 2544 break; 2545 case 'all': 2546 default: 2547 this.clearAllFiltersExcept([]); 2548 this.onFilterChange(); 2549 } 2550 }; 2551 2552 BX.Sale.BasketFilter.prototype.onFilterInput = function() 2553 { 2554 var value = BX.type.isDomNode(BX.proxy_context) ? BX.util.trim(BX.proxy_context.value).toLowerCase() : ''; 2555 2556 if (this.currentFilter.query !== value) 2557 { 2558 this.currentFilter.query = value; 2559 2560 this.onFilterChange(); 2561 } 2562 }; 2563 2564 BX.Sale.BasketFilter.prototype.clearAllFiltersExcept = function(names) 2565 {
2566 if (!names || !BX.type.isArray(names)) 2567 return; 2568 2569 !BX.util.in_array('input', names) && this.clearFilterInput(); 2570 !BX.util.in_array('warning', names) && this.clearWarningItemsFilter(); 2571 !BX.util.in_array('delayed', names) && this.clearDelayItemsFilter(); 2572 !BX.util.in_array('orderable', names) && this.clearOrderableItemsFilter(); 2573 !BX.util.in_array('not-available', names) && this.clearNotAvailableItemsFilter(); 2574 2575 if (!BX.util.in_array('similar', names)) 2576 { 2577 this.clearSimilarItemsFilter(); 2578 this.component.showSimilarCount(false); 2579 } 2580 }; 2581 2582 BX.Sale.BasketFilter.prototype.filterInputEmpty = function() 2583 { 2584 return this.currentFilter.query.length === 0; 2585 }; 2586 2587 BX.Sale.BasketFilter.prototype.clearFilterInput = function() 2588 { 2589 this.currentFilter.query = ''; 2590 2591 var input = this.component.getEntity( 2592 this.component.getCacheNode(this.component.ids.itemListWrapper), 2593 'basket-filter-input' 2594 ); 2595 if (BX.type.isDomNode(input)) 2596 { 2597 input.value = ''; 2598 } 2599 }; 2600 2601 BX.Sale.BasketFilter.prototype.addWarningItemsFilter = function() 2602 { 2603 this.currentFilter.warning = true; 2604 }; 2605 2606 BX.Sale.BasketFilter.prototype.clearWarningItemsFilter = function() 2607 { 2608 this.currentFilter.warning = false; 2609 }; 2610 2611 BX.Sale.BasketFilter.prototype.showWarningItemsFilter = function() 2612 { 2613 if (!this.currentFilter.warning) 2614 { 2615 this.clearAllFiltersExcept(['warning']); 2616 this.addWarningItemsFilter(); 2617 this.onFilterChange(); 2618 } 2619 }; 2620 2621 BX.Sale.BasketFilter.prototype.addDelayItemsFilter = function() 2622 { 2623 this.currentFilter.delayed = true; 2624 }; 2625 2626 BX.Sale.BasketFilter.prototype.clearDelayItemsFilter = function() 2627 { 2628 this.currentFilter.delayed = false; 2629 }; 2630 2631 BX.Sale.BasketFilter.prototype.clearOrderableItemsFilter = function() 2632 { 2633 this.currentFilter.orderable = false; 2634 }; 2635 2636 BX.Sale.BasketFilter.prototype.showDelayItemsFilter = function() 2637 { 2638 if (!this.currentFilter.delayed) 2639 { 2640 this.clearAllFiltersExcept(['delayed']); 2641 this.addDelayItemsFilter(); 2642 this.onFilterChange(); 2643 } 2644 }; 2645 2646 BX.Sale.BasketFilter.prototype.addNotAvailableItemsFilter = function() 2647 { 2648 this.currentFilter.notAvailable = true; 2649 }; 2650 2651 BX.Sale.BasketFilter.prototype.addOrderableItemsFilter = function() 2652 { 2653 this.currentFilter.orderable = true; 2654 }; 2655 2656 BX.Sale.BasketFilter.prototype.clearNotAvailableItemsFilter = function() 2657 { 2658 this.currentFilter.notAvailable = false; 2659 }; 2660 2661 BX.Sale.BasketFilter.prototype.showNotAvailableItemsFilter = function() 2662 { 2663 if (!this.currentFilter.notAvailable) 2664 { 2665 this.clearAllFiltersExcept(['not-available']); 2666 this.addNotAvailableItemsFilter(); 2667 this.onFilterChange(); 2668 } 2669 }; 2670 2671 BX.Sale.BasketFilter.prototype.showOrderableItemsFilter = function() 2672 { 2673 if (!this.currentFilter.orderable) 2674 { 2675 this.clearAllFiltersExcept(['orderable']); 2676 this.addOrderableItemsFilter(); 2677 this.onFilterChange(); 2678 } 2679 }; 2680 2681 BX.Sale.BasketFilter.prototype.addSimilarItemsFilter = function(item) 2682 { 2683 this.currentFilter.similarHash = item.HASH; 2684 }; 2685 2686 BX.Sale.BasketFilter.prototype.clearSimilarItemsFilter = function() 2687 { 2688 this.currentFilter.similarHash = ''; 2689 }; 2690 2691 BX.Sale.BasketFilter.prototype.showSimilarItemsFilter = function() 2692 { 2693 var item = this.component.getItemDataByTarget(BX.proxy_context); 2694 2695 if (this.currentFilter.similarHash !== item.HASH) 2696 { 2697 this.clearAllFiltersExcept(['similar']); 2698 this.addSimilarItemsFilter(item); 2699 this.onFilterChange(); 2700 } 2701 }; 2702 2703 BX.Sale.BasketFilter.prototype.getTimeoutDuration = function() 2704 { 2705 return this.component.duration.filterTimer; 2706 }; 2707 2708 BX.Sale.BasketFilter.prototype.onFilterChange = function() 2709 { 2710 this.component.showItemsOverlay(); 2711 if ( 2712 this.currentFilter.query.length 2713 || this.currentFilter.similarHash.length 2714 || this.currentFilter.warning 2715 || this.currentFilter.notAvailable 2716 || this.currentFilter.orderable 2717 || this.currentFilter.delayed 2718 ) 2719 { 2720 clearTimeout(this.filterTimer); 2721 this.filterTimer = setTimeout(BX.proxy(this.enableFilterMode, this), this.getTimeoutDuration()); 2722 } 2723 else 2724 { 2725 this.disableFilterMode(); 2726 } 2727 }; 2728 2729 BX.Sale.BasketFilter.prototype.enableFilterMode = function() 2730 { 2731 var foundItemsHash; 2732 2733 if (!this.activeFilterMode) 2734 { 2735 this.activeFilterMode = true; 2736 this.realShownItems = BX.util.array_values(this.component.shownItems); 2737 this.realSortedItems = BX.util.array_values(this.component.sortedItems); 2738 this.realScrollTop = this.component.getDocumentScrollTop(); 2739 } 2740 2741 this.component.scrollToFirstItem(); 2742 2743 this.component.sortedItems = this.searchItems(); 2744 2745 foundItemsHash = JSON.stringify(this.component.sortedItems); 2746
2747 if (this.lastShownItemsHash !== foundItemsHash) 2748 { 2749 this.lastShownItemsHash = foundItemsHash; 2750 2751 this.component.deleteBasketItems(BX.util.array_values(this.component.shownItems), false); 2752 2753 if (this.component.sortedItems.length) 2754 { 2755 this.component.initializeBasketItems(); 2756 this.hideEmptyFilterResult(); 2757 } 2758 else 2759 { 2760 this.showEmptyFilterResult(); 2761 } 2762 2763 if (this.currentFilter.similarHash.length) 2764 { 2765 this.component.showSimilarCount(true); 2766 } 2767 } 2768 else 2769 { 2770 this.highlightFoundItems(); 2771 } 2772 2773 this.component.hideItemsOverlay(); 2774 }; 2775 2776 BX.Sale.BasketFilter.prototype.disableFilterMode = function() 2777 { 2778 clearTimeout(this.filterTimer); 2779 this.lastShownItemsHash = ''; 2780 2781 if (this.activeFilterMode) 2782 { 2783 this.activeFilterMode = false; 2784 this.component.sortedItems = BX.util.array_values(this.realSortedItems); 2785 2786 this.component.deleteBasketItems(BX.util.array_values(this.component.shownItems), false); 2787 this.hideEmptyFilterResult(); 2788 2789 this.component.editBasketItems(BX.util.array_values(this.realShownItems)); 2790 window.scrollTo(0, this.realScrollTop); 2791 } 2792 2793 this.component.hideItemsOverlay(); 2794 }; 2795 2796 BX.Sale.BasketFilter.prototype.searchItems = function() 2797 { 2798 var items = []; 2799 2800 for (var i = 0; i < this.realSortedItems.length; i++) 2801 { 2802 var item = this.component.items[this.realSortedItems[i]]; 2803 2804 if (item && this.searchItemMatch(item)) 2805 { 2806 items.push(item.ID); 2807 } 2808 } 2809 2810 return items; 2811 }; 2812 2813 BX.Sale.BasketFilter.prototype.highlightFoundItems = function() 2814 { 2815 if (!this.activeFilterMode) 2816 return; 2817 2818 for (var i in this.component.shownItems) 2819 { 2820 if (this.component.shownItems.hasOwnProperty(i)) 2821 { 2822 this.highlightSearchMatch(this.component.items[this.component.shownItems[i]]); 2823 } 2824 } 2825 }; 2826 2827 BX.Sale.BasketFilter.prototype.searchItemMatch = function(item) 2828 { 2829 var match = false, 2830 found = false; 2831 2832 if (this.currentFilter.notAvailable) 2833 { 2834 found = !!item.NOT_AVAILABLE; 2835 if (!found) 2836 { 2837 return match; 2838 } 2839 } 2840 else if (this.currentFilter.delayed) 2841 { 2842 found = !!item.DELAYED; 2843 if (!found) 2844 { 2845 return match; 2846 } 2847 } 2848 else if (this.currentFilter.warning) 2849 { 2850 found = BX.util.in_array(item.ID, this.component.warningItems); 2851 if (!found) 2852 { 2853 return match; 2854 } 2855 } 2856 else if (BX.type.isNotEmptyString(this.currentFilter.similarHash)) 2857 { 2858 found = this.currentFilter.similarHash === item.HASH; 2859 if (!found) 2860 { 2861 return match; 2862 } 2863 } 2864 else if (this.currentFilter.orderable && !this.currentFilter.query) 2865 { 2866 if(!item.NOT_AVAILABLE && !item.DELAYED && !BX.util.in_array(item.ID, this.component.warningItems) && !(this.currentFilter.similarHash === item.HASH)){ 2867 return true; 2868 } 2869 else{ 2870 return false; 2871 } 2872 } 2873 2874 if (BX.type.isNotEmptyString(this.currentFilter.query)) 2875 { 2876 if (item.NAME.toLowerCase().indexOf(this.currentFilter.query) !== -1) 2877 { 2878 match = 'NAME'; 2879 } 2880 2881 if (!match) 2882 { 2883 var floatValue = parseFloat(this.currentFilter.query); 2884 if (!isNaN(floatValue)) 2885 { 2886 if (parseFloat(item.PRICE) === floatValue) 2887 { 2888 match = 'PRICE'; 2889 } 2890 else if (parseFloat(item.SUM_PRICE) === floatValue) 2891 { 2892 match = 'SUM_PRICE'; 2893 } 2894 } 2895 } 2896 2897 if (!match && this.currentFilter.query.length >= 3) 2898 { 2899 if (item.PRICE_FORMATED.toLowerCase().indexOf(this.currentFilter.query) !== -1) 2900 { 2901 match = 'PRICE'; 2902 } 2903 else if (item.SUM_PRICE_FORMATED.toLowerCase().indexOf(this.currentFilter.query) !== -1) 2904 { 2905 match = 'SUM_PRICE'; 2906 } 2907 } 2908 2909 var k, lcValue; 2910 2911 if (!match && item.PROPS.length) 2912 { 2913 for (k in item.PROPS) 2914 { 2915 if (item.PROPS.hasOwnProperty(k) && BX.type.isNotEmptyString(item.PROPS[k].VALUE)) 2916 { 2917 lcValue = item.PROPS[k].VALUE.toLowerCase(); 2918 2919 if ( 2920 lcValue === this.currentFilter.query 2921 || (this.currentFilter.query.length >= 3 && lcValue.indexOf(this.currentFilter.query) !== -1) 2922 ) 2923 { 2924 match = 'PROPS'; 2925 break; 2926 } 2927 } 2928 } 2929 } 2930 2931 if (!match && item.COLUMN_LIST.length) 2932 { 2933 for (k in item.COLUMN_LIST) 2934 { 2935 if (item.COLUMN_LIST.hasOwnProperty(k) && BX.type.isNotEmptyString(item.COLUMN_LIST[k].VALUE)) 2936 { 2937 lcValue = item.COLUMN_LIST[k].VALUE.toLowerCase(); 2938 2939 if ( 2940 lcValue === this.currentFilter.query 2941 || (this.currentFilter.query.length >= 3 && lcValue.indexOf(this.currentFilter.query) !== -1) 2942 ) 2943 { 2944 match = 'COLUMNS'; 2945 break; 2946 } 2947 } 2948 } 2949 } 2950 } 2951 else if (found) 2952 { 2953 match = true; 2954 } 2955 2956 return match; 2957 }; 2958 2959 BX.Sale.BasketFilter.prototype.highlightSearchMatch = function(itemData) 2960 { 2961 var searchMatch = this.searchItemMatch(itemData); 2962 2963 if (searchMatch) 2964 { 2965 var entity, i, k, code; 2966 2967 switch (searchMatch) 2968 { 2969 case 'NAME': 2970 entity = this.component.getEntity(BX(this.component.ids.item + itemData.ID), 'basket-item-name'); 2971 if (BX.type.isDomNode(entity)) 2972 { 2973 entity.innerHTML = itemData.NAME.replace( 2974 new RegExp('(' + this.currentFilter.query + ')', 'gi'), 2975 '<span class="basket-item-highlighted">$1</span>' 2976 ); 2977 } 2978 break; 2979 case 'PRICE': 2980 entity = BX(this.component.ids.price + itemData.ID); 2981 BX.addClass(entity, 'basket-item-highlighted'); 2982 break; 2983 case 'SUM_PRICE': 2984 entity = BX(this.component.ids.sumPrice + itemData.ID); 2985 BX.addClass(entity, 'basket-item-highlighted'); 2986 break; 2987 case 'PROPS': 2988 entity = this.component.getEntities(BX(this.component.ids.item + itemData.ID), 'basket-item-property-value'); 2989 2990 for (i = 0; i < entity.length; i++) 2991 { 2992 code = entity[i].getAttribute('data-property-code'); 2993 2994 for (k in itemData.PROPS) 2995 { 2996 if (itemData.PROPS.hasOwnProperty(k) && itemData.PROPS[k].CODE === code) 2997 { 2998 entity[i].innerHTML = itemData.PROPS[k].VALUE.replace( 2999 new RegExp('(' + this.currentFilter.query + ')', 'gi'), 3000 '<span class="basket-item-highlighted">$1</span>' 3001 ); 3002 } 3003 } 3004 } 3005 break; 3006 case 'COLUMNS': 3007 entity = this.component.getEntities(BX(this.component.ids.item + itemData.ID), 'basket-item-property-column-value'); 3008 3009 for (i = 0; i < entity.length; i++) 3010 { 3011 code = entity[i].getAttribute('data-column-property-code'); 3012 3013 for (k in itemData.COLUMN_LIST) 3014 { 3015 if (itemData.COLUMN_LIST.hasOwnProperty(k) && itemData.COLUMN_LIST[k].CODE === code) 3016 { 3017 entity[i].innerHTML = itemData.COLUMN_LIST[k].VALUE.replace( 3018 new RegExp('(' + this.currentFilter.query + ')', 'gi'), 3019 '<span class="basket-item-highlighted">$1</span>' 3020 ); 3021 } 3022 } 3023 } 3024 break; 3025 } 3026 } 3027 }; 3028 3029 BX.Sale.BasketFilter.prototype.showEmptyFilterResult = function() 3030 { 3031 var itemListNode = this.component.getCacheNode(this.component.ids.itemList); 3032 3033 if (BX.type.isDomNode(itemListNode) && itemListNode.clientHeight >= 500) 3034 { 3035 var emptyResultNode = this.component.getCacheNode(this.component.ids.itemListEmptyResult); 3036 3037 if (BX.type.isDomNode(emptyResultNode)) 3038 { 3039 emptyResultNode.style.display = ''; 3040 } 3041 } 3042 }; 3043 3044 BX.Sale.BasketFilter.prototype.hideEmptyFilterResult = function() 3045 { 3046 var emptyResultNode = this.component.getCacheNode(this.component.ids.itemListEmptyResult); 3047 3048 if (BX.type.isDomNode(emptyResultNode)) 3049 { 3050 emptyResultNode.style.display = 'none'; 3051 } 3052 }; 3053})(); 3054/* End */ 3055; 3056; /* Start:"a:4:{s:4:"full";s:121:"/local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/component.js?178187500069943";s:6:"source";s:105:"/local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/component.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/ 3057;(function() { 3058 'use strict'; 3059 3060 BX.namespace('BX.Sale.BasketComponent'); 3061 3062 BX.Sale.BasketComponent = { 3063 maxItemsShowCount: 30, 3064 precisionFactor: Math.pow(10, 6), 3065 stickyHeaderOffset: 0, 3066 3067 duration: { 3068 priceAnimation: 300, 3069 filterTimer: 300 3070 }, 3071 3072 ids: { 3073 item: 'basket-item-', 3074 quantity: 'basket-item-quantity-', 3075 price: 'basket-item-price-', 3076 sumPrice: 'basket-item-sum-price-', 3077 sumPriceOld: 'basket-item-sum-price-old-', 3078 sumPriceDiff: 'basket-item-sum-price-difference-', 3079 itemHeightAligner: 'basket-item-height-aligner-', 3080 total: 'basket-total-price', 3081 basketRoot: 'basket-root', 3082 itemListWrapper: 'basket-items-list-wrapper', 3083 itemListContainer: 'basket-items-list-container', 3084 itemList: 'basket-item-list',
3085 itemListTable: 'basket-item-table', 3086 itemListEmptyResult: 'basket-item-list-empty-result', 3087 itemListOverlay: 'basket-items-list-overlay', 3088 warning: 'basket-warning' 3089 }, 3090 3091 initializePrimaryFields: function() 3092 { 3093 this.templates = {}; 3094 this.nodes = {}; 3095 3096 /** Object of all basket items (itemId => itemArray) */ 3097 this.items = {}; 3098 3099 /** Array of all basket items to show sorted by field SORT */ 3100 this.sortedItems = []; 3101 3102 /** Array of basket items showed on screen */ 3103 this.shownItems = []; 3104 3105 /** Array of basket items changed since last request */ 3106 this.changedItems = []; 3107 3108 /** Array of basket items postponed by pool to edit */ 3109 this.postponedItems = []; 3110 3111 /** Array of basket items with warnings */ 3112 this.warningItems = []; 3113 3114 this.isMobile = BX.browser.IsMobile(); 3115 this.isTouch = BX.hasClass(document.documentElement, 'bx-touch'); 3116 3117 this.lastAction = 'initialLoad'; 3118 this.coupons = null; 3119 3120 this.imagePopup = null; 3121 this.loadingScreen = null; 3122 3123 this.quantityDelay = null; 3124 this.quantityTimer = null; 3125 }, 3126 3127 init: function(parameters) 3128 { 3129 this.initializePrimaryFields(); 3130 3131 this.params = parameters.params || {}; 3132 this.template = parameters.template || ''; 3133 this.signedParamsString = parameters.signedParamsString || ''; 3134 this.siteId = parameters.siteId || ''; 3135 this.siteTemplateId = parameters.siteTemplateId || ''; 3136 this.ajaxUrl = this.params.AJAX_PATH || ''; 3137 this.templateFolder = parameters.templateFolder || ''; 3138 3139 this.useDynamicScroll = this.params.USE_DYNAMIC_SCROLL === 'Y'; 3140 this.useItemsFilter = this.params.SHOW_FILTER === 'Y' && !this.isMobile; 3141 3142 this.initializeFilter(); 3143 this.applyBasketResult(parameters.result); 3144 this.initializeActionPool(); 3145 3146 this.isAuthorized = parameters.isAuthorized || ''; 3147 3148 if (this.useItemsFilter) 3149 { 3150 this.checkHeaderDisplay(); 3151 this.bindHeaderEvents(); 3152 3153 if (this.params.EXCLUDE_DELAY === 'Y') { 3154 this.toggleFilter('orderable'); 3155 } 3156 } 3157 3158 setTimeout(() => { 3159 this.initializeBasketItems(); 3160 this.editTotal(); 3161 }, 3000) 3162 this.editWarnings(); 3163 3164 this.getCacheNode(this.ids.basketRoot).style.opacity = 1; 3165 3166 this.bindInitialEvents(); 3167 }, 3168 3169 getTemplate: function(templateName) 3170 { 3171 if (!this.templates.hasOwnProperty(templateName)) 3172 { 3173 var template = BX(templateName); 3174 this.templates[templateName] = BX.type.isDomNode(template) ? template.innerHTML : ''; 3175 } 3176 3177 return this.templates[templateName]; 3178 }, 3179 3180 getCacheNode: function(id) 3181 { 3182 if (!this.nodes.hasOwnProperty(id)) 3183 { 3184 this.nodes[id] = BX(id); 3185 } 3186 3187 return this.nodes[id]; 3188 }, 3189 3190 getEntity: function(parent, entity, additionalFilter) 3191 { 3192 if (!parent || !entity) 3193 return null; 3194 3195 additionalFilter = additionalFilter || ''; 3196 3197 return parent.querySelector(additionalFilter + '[data-entity="' + entity + '"]'); 3198 }, 3199 3200 getEntities: function(parent, entity, additionalFilter) 3201 { 3202 if (!parent || !entity) 3203 return {length: 0}; 3204 3205 additionalFilter = additionalFilter || ''; 3206 3207 return parent.querySelectorAll(additionalFilter + '[data-entity="' + entity + '"]'); 3208 }, 3209 3210 bindInitialEvents: function() 3211 { 3212 this.bindWarningEvents(); 3213 3214 BX.bind(window, 'scroll', BX.proxy(this.checkStickyHeaders, this)); 3215 BX.bind(window, 'scroll', BX.proxy(this.lazyLoad, this)); 3216 3217 BX.bind(window, 'resize', BX.throttle(this.checkStickyHeaders, 20, this)); 3218 }, 3219 3220 bindWarningEvents: function() 3221 { 3222 var showItemsNode = this.getEntity(BX(this.ids.warning), 'basket-items-warning-count'); 3223 3224 if (BX.type.isDomNode(showItemsNode)) 3225 { 3226 showItemsNode.style.display = ''; 3227 BX.bind(showItemsNode, 'click', BX.delegate(function() {this.toggleFilter('warning');}, this)); 3228 } 3229 3230 BX.bind( 3231 this.getEntity(BX(this.ids.warning), 'basket-items-warning-notification-close'), 3232 'click', 3233 BX.proxy(this.removeAllWarnings, this) 3234 ); 3235 }, 3236 3237 toggleFilter: function(event) 3238 { 3239 var target = BX.type.isNotEmptyString(event) ? 3240 this.getEntity( 3241 this.getCacheNode(this.ids.itemListWrapper), 3242 'basket-items-count', 3243 '[data-filter="' + event + '"]' 3244 ) 3245 : BX.getEventTarget(event); 3246 3247 if (!BX.type.isDomNode(target) || BX.hasClass(target, 'active')) 3248 return; 3249 3250 var entityName = target.getAttribute('data-filter'); 3251 var entities = target.parentNode.querySelectorAll('[data-filter]'); 3252 3253 for (var i = 0; i < entities.length; i++) 3254 { 3255 if (entities[i].getAttribute('data-filter') === entityName) 3256 { 3257 BX.addClass(entities[i], 'active'); 3258 } 3259 else if (BX.hasClass(entities[i], 'active')) 3260 { 3261 BX.removeClass(entities[i], 'active'); 3262 } 3263 } 3264 3265 this.prepareCheckoutBlock(entityName); 3266 this.filter.showFilterByName(entityName); 3267 }, 3268 prepareCheckoutBlock: function prepareCheckoutBlock(entityName) { 3269 const panelBtn = document.querySelector('.basket-checkout-block.basket-checkout-block-btn'); 3270 if(panelBtn) {
3271 this.toggleViewCheckoutBlock(document, 'none'); 3272 if (entityName === 'orderable' && this.hasProductInCart()) { 3273 this.toggleViewCheckoutBlock(document, 'flex'); 3274 } 3275 } 3276 }, 3277 hasProductInCart: function hasProductInCart() { 3278 let result = false; 3279 for (let item in this.items) { 3280 if (!this.items[item].DELAYED && !this.items[item].SHOW_RESTORE && !result) { 3281 result = true 3282 break; 3283 } 3284 } 3285 return result; 3286 }, 3287 toggleViewCheckoutBlock: function toggleViewCheckoutBlock(parentItem, visibleStyle) { 3288 //parentItem.querySelector('.basket-checkout-block.basket-checkout-block-btn').style = 'display: ' + visibleStyle + ';'; 3289 }, 3290 scrollToFirstItem: function() 3291 { 3292 var headerNode = this.getEntity(this.getCacheNode(this.ids.itemListWrapper), 'basket-items-list-header'); 3293 3294 if (BX.type.isDomNode(headerNode)) 3295 { 3296 var itemListTopPosition = BX.pos(this.getCacheNode(this.ids.itemListContainer)).top; 3297 var headerBottomPosition = BX.pos(headerNode).bottom; 3298 3299 if (itemListTopPosition < headerBottomPosition) 3300 { 3301 window.scrollTo(0, itemListTopPosition - this.stickyHeaderOffset); 3302 } 3303 } 3304 }, 3305 3306 showItemsOverlay: function() 3307 { 3308 var overlay = this.getCacheNode(this.ids.itemListOverlay); 3309 3310 if (BX.type.isDomNode(overlay)) 3311 { 3312 overlay.style.display = ''; 3313 } 3314 }, 3315 3316 hideItemsOverlay: function() 3317 { 3318 var overlay = this.getCacheNode(this.ids.itemListOverlay); 3319 3320 if (BX.type.isDomNode(overlay)) 3321 { 3322 overlay.style.display = 'none'; 3323 } 3324 }, 3325 3326 checkHeaderDisplay: function() 3327 { 3328 var header = this.getCacheNode(this.ids.itemListWrapper); 3329 3330 if (BX.type.isDomNode(header)) 3331 { 3332 BX.removeClass(header, 'basket-items-list-wrapper-light'); 3333 } 3334 }, 3335 3336 bindHeaderEvents: function() 3337 { 3338 var entities = this.getEntities(this.getCacheNode(this.ids.itemListWrapper), 'basket-items-count'); 3339 3340 for (var i = 0; i < entities.length; i++) 3341 { 3342 BX.bind(entities[i], 'click', BX.proxy(this.toggleFilter, this)); 3343 } 3344 }, 3345 3346 checkStickyHeaders: function() 3347 { 3348 if (this.isMobile) 3349 return; 3350 3351 var node, position; 3352 var border = 2, offset = 0; 3353 var scrollTop = this.getDocumentScrollTop(); 3354 var basketPosition = BX.pos(this.getCacheNode(this.ids.basketRoot)); 3355 var basketScrolledToEnd = scrollTop + 200 >= basketPosition.bottom; 3356 3357 if (BX.util.in_array('top', this.params.TOTAL_BLOCK_DISPLAY)) 3358 { 3359 var totalBlockNode = this.getEntity(this.getCacheNode(this.ids.basketRoot), 'basket-total-block'); 3360 if (BX.type.isDomNode(totalBlockNode)) 3361 { 3362 node = this.getEntity(totalBlockNode, 'basket-checkout-aligner'); 3363 if (BX.type.isDomNode(node)) 3364 { 3365 position = BX.pos(totalBlockNode); 3366 3367 if (scrollTop >= position.top) 3368 { 3369 offset += node.clientHeight; 3370 3371 if (!BX.hasClass(node, 'basket-checkout-container-fixed')) 3372 { 3373 totalBlockNode.style.height = position.height + 'px'; 3374 3375 node.style.width = node.clientWidth + border + 'px'; 3376 BX.addClass(node, 'basket-checkout-container-fixed'); 3377 } 3378 } 3379 else if (BX.hasClass(node, 'basket-checkout-container-fixed')) 3380 { 3381 totalBlockNode.style.height = ''; 3382 3383 node.style.width = ''; 3384 BX.removeClass(node, 'basket-checkout-container-fixed'); 3385 } 3386 3387 if (basketScrolledToEnd) 3388 { 3389 if (!BX.hasClass(node, 'basket-checkout-container-fixed-hide')) 3390 { 3391 BX.addClass(node, 'basket-checkout-container-fixed-hide'); 3392 } 3393 } 3394 else if (BX.hasClass(node, 'basket-checkout-container-fixed-hide')) 3395 { 3396 BX.removeClass(node, 'basket-checkout-container-fixed-hide'); 3397 } 3398 } 3399 } 3400 } 3401 3402 if (this.useItemsFilter) 3403 { 3404 var itemWrapperNode = this.getCacheNode(this.ids.itemListWrapper); 3405 3406 node = this.getEntity(itemWrapperNode, 'basket-items-list-header'); 3407 if (BX.type.isDomNode(node)) 3408 { 3409 position = BX.pos(itemWrapperNode); 3410 3411 if ((scrollTop + offset >= position.top) && !basketScrolledToEnd) 3412 { 3413 if (!BX.hasClass(node, 'basket-items-list-header-fixed')) 3414 { 3415 node.style.width = node.clientWidth + border + 'px'; 3416 3417 itemWrapperNode.style.paddingTop = node.clientHeight + 'px'; 3418 3419 BX.addClass(node, 'basket-items-list-header-fixed'); 3420 } 3421 3422 if (offset) 3423 { 3424 node.style.top = offset + 'px'; 3425 } 3426 3427 offset += node.clientHeight; 3428 } 3429 else if (BX.hasClass(node, 'basket-items-list-header-fixed')) 3430 { 3431 itemWrapperNode.style.paddingTop = ''; 3432 3433 node.style.width = ''; 3434 node.style.top = ''; 3435 3436 BX.removeClass(node, 'basket-items-list-header-fixed'); 3437 } 3438 } 3439 } 3440 3441 this.stickyHeaderOffset = offset; 3442 }, 3443 3444 getDocumentScrollTop: function() 3445 { 3446 return window.scrollY 3447 || window.pageYOffset 3448 || document.body.scrollTop + (document.documentElement && document.documentElement.scrollTop || 0); 3449 }, 3450 3451 lazyLoad: function() 3452 { 3453 var itemsNodePosition = BX.pos(this.getCacheNode(this.ids.itemListContainer));
3454 3455 if (this.getDocumentScrollTop() + window.innerHeight >= itemsNodePosition.bottom - 400) 3456 { 3457 var itemIds = this.getItemsAfter(); 3458 if (itemIds.length) 3459 { 3460 setTimeout(() => { 3461 this.editBasketItems(itemIds); 3462 }, 300) 3463 } 3464 } 3465 }, 3466 3467 fireCustomEvents: function() 3468 { 3469 if (this.result.EVENT_ONCHANGE_ON_START === 'Y') 3470 { 3471 BX.onCustomEvent('OnBasketChange'); 3472 } 3473 3474 if (this.params.HIDE_COUPON !== 'Y') 3475 { 3476 if (this.coupons !== null && this.coupons !== this.result.COUPON_LIST) 3477 { 3478 BX.onCustomEvent('OnCouponApply'); 3479 } 3480 3481 this.coupons = this.result.COUPON_LIST; 3482 } 3483 }, 3484 3485 editTotal: function() 3486 { 3487 this.fillTotalBlocks(); 3488 this.showItemsCount(); 3489 //this.showOrderableItemsCount(); 3490 this.showWarningItemsCount(); 3491 this.showNotAvailableItemsCount(); 3492 this.showDelayedItemsCount(); 3493 }, 3494 3495 fillTotalBlocks: function() 3496 { 3497 var totalNodes = this.getEntities(this.getCacheNode(this.ids.basketRoot), 'basket-total-block'); 3498 3499 if (totalNodes && totalNodes.length) 3500 { 3501 var totalTemplate = this.getTemplate('basket-total-template'); 3502 if (totalTemplate) 3503 { 3504 var totalRender = this.render(totalTemplate, this.result.TOTAL_RENDER_DATA); 3505 for (var i in totalNodes) { 3506 if (totalNodes.hasOwnProperty(i) && BX.type.isDomNode(totalNodes[i])) { 3507 totalNodes[i].innerHTML = totalRender; 3508 3509 if(this.result.TOTAL_RENDER_DATA.DISABLE_CHECKOUT) { 3510 totalNodes[i].style.visibility = "hidden"; 3511 } else { 3512 totalNodes[i].style.visibility = "visible"; 3513 } 3514 this.toggleViewCheckoutBlock(totalNodes[i], 'none') 3515 if(this.hasProductInCart()) { 3516 this.toggleViewCheckoutBlock(totalNodes[i], 'flex'); 3517 } 3518 this.bindTotalEvents(totalNodes[i]); 3519 } 3520 } 3521 } 3522 } 3523 3524 this.checkStickyHeaders(); 3525 }, 3526 3527 showItemsCount: function() 3528 { 3529 var itemCountNode = this.getEntity( 3530 this.getCacheNode(this.ids.itemListWrapper), 3531 'basket-items-count', 3532 '[data-filter="all"]' 3533 ); 3534 3535 if (BX.type.isDomNode(itemCountNode)) 3536 { 3537 itemCountNode.innerHTML = BX.message('SBB_IN_BASKET') + ' ' + this.result.BASKET_ITEMS_COUNT + ' ' + this.getGoodsMessage(this.result.BASKET_ITEMS_COUNT); 3538 itemCountNode.style.display = ''; 3539 } 3540 }, 3541 3542 showOrderableItemsCount: function() 3543 { 3544 var itemCountNode = this.getEntity( 3545 this.getCacheNode(this.ids.itemListWrapper), 3546 'basket-items-count', 3547 '[data-filter="orderable"]' 3548 ); 3549 3550 if(this.result.ORDERABLE_BASKET_ITEMS_COUNT === null){ 3551 this.result.ORDERABLE_BASKET_ITEMS_COUNT = 0; 3552 } 3553 if (BX.type.isDomNode(itemCountNode)) 3554 { 3555 itemCountNode.innerHTML = BX.message('SBB_IN_BASKET2') + ' (' + this.result.ORDERABLE_BASKET_ITEMS_COUNT + ')'; 3556 itemCountNode.style.display = ''; 3557 } 3558 else 3559 { 3560 itemCountNode.style.display = 'none'; 3561 } 3562 }, 3563 3564 showSimilarCount: function(state) 3565 { 3566 var itemCountNode = this.getEntity( 3567 this.getCacheNode(this.ids.itemListWrapper), 3568 'basket-items-count', 3569 '[data-filter="similar"]' 3570 ); 3571 3572 if (BX.type.isDomNode(itemCountNode)) 3573 { 3574 if (state) 3575 { 3576 itemCountNode.innerHTML = this.sortedItems.length + ' ' 3577 + this.getGoodsMessage(this.result.BASKET_ITEMS_COUNT, 'SBB_SIMILAR_ITEM'); 3578 itemCountNode.style.display = ''; 3579 } 3580 else 3581 { 3582 itemCountNode.style.display = 'none'; 3583 } 3584 } 3585 }, 3586 3587 showWarningItemsCount: function() 3588 { 3589 var itemCountNode = this.getEntity( 3590 this.getCacheNode(this.ids.itemListWrapper), 3591 'basket-items-count', 3592 '[data-filter="warning"]' 3593 ); 3594
3595 if (BX.type.isDomNode(itemCountNode)) 3596 { 3597 if (this.warningItems.length) 3598 { 3599 itemCountNode.innerHTML = this.warningItems.length + ' ' + BX.message('SBB_BASKET_ITEMS_WARNING'); 3600 itemCountNode.style.display = ''; 3601 } 3602 else 3603 { 3604 itemCountNode.style.display = 'none'; 3605 } 3606 } 3607 }, 3608 3609 showNotAvailableItemsCount: function() 3610 { 3611 var itemCountNode = this.getEntity( 3612 this.getCacheNode(this.ids.itemListWrapper), 3613 'basket-items-count', 3614 '[data-filter="not-available"]' 3615 ); 3616 3617 if (BX.type.isDomNode(itemCountNode)) 3618 { 3619 if (parseInt(this.result.NOT_AVAILABLE_BASKET_ITEMS_COUNT)) 3620 { 3621 itemCountNode.innerHTML = this.result.NOT_AVAILABLE_BASKET_ITEMS_COUNT + ' ' 3622 + this.getGoodsMessage(this.result.NOT_AVAILABLE_BASKET_ITEMS_COUNT, 'SBB_NOT_AVAILABLE_ITEM'); 3623 itemCountNode.style.display = ''; 3624 } 3625 else 3626 { 3627 itemCountNode.style.display = 'none'; 3628 } 3629 } 3630 }, 3631 3632 showDelayedItemsCount: function() 3633 { 3634 var itemCountNode = this.getEntity( 3635 this.getCacheNode(this.ids.itemListWrapper), 3636 'basket-items-count', 3637 '[data-filter="delayed"]' 3638 ); 3639 if(this.result.DELAYED_BASKET_ITEMS_COUNT === null){ 3640 this.result.DELAYED_BASKET_ITEMS_COUNT = 0; 3641 } 3642 if (BX.type.isDomNode(itemCountNode)) 3643 { 3644 if (parseInt(this.result.DELAYED_BASKET_ITEMS_COUNT)) 3645 { 3646 itemCountNode.innerHTML = BX.message('SBB_DELAYED') + ' (' + this.result.DELAYED_BASKET_ITEMS_COUNT + ')'; 3647 itemCountNode.style.display = ''; 3648 } 3649 else 3650 { 3651 itemCountNode.innerHTML = BX.message('SBB_DELAYED') + ' (' + this.result.DELAYED_BASKET_ITEMS_COUNT + ')'; 3652 itemCountNode.style.display = 'none'; 3653 } 3654 } 3655 }, 3656 3657 getGoodsMessage: function(count, customMessage) 3658 { 3659 var mesCode; 3660 var countReminder = (count > 10 && count < 20) ? 0 : count % 10; 3661 3662 if (countReminder === 1) 3663 { 3664 mesCode = customMessage || 'SBB_GOOD'; 3665 } 3666 else if (countReminder >= 2 && countReminder <= 4) 3667 { 3668 mesCode = customMessage ? customMessage + '_2' : 'SBB_GOOD_2'; 3669 } 3670 else 3671 { 3672 mesCode = customMessage ? customMessage + 'S' : 'SBB_GOODS'; 3673 } 3674 3675 return BX.message(mesCode); 3676 }, 3677 3678 bindTotalEvents: function(node) 3679 { 3680 if (!this.result.TOTAL_RENDER_DATA.DISABLE_CHECKOUT) 3681 { 3682 BX.bind(this.getEntity(node, 'basket-checkout-button'), 'click', BX.proxy(this.checkOutAction, this)); 3683 } 3684 3685 BX.bind(this.getEntity(node, 'basket-coupon-input'), 'change', BX.proxy(this.addCouponAction, this)); 3686 BX.bind(this.getEntity(node, 'basket-coupon-input'), 'paste', BX.proxy(this.pasteCouponAction, this)); 3687 3688 var couponNodes = this.getEntities(node, 'basket-coupon-delete'); 3689 for (var i = 0, l = couponNodes.length; i < l; i++) 3690 { 3691 BX.bind(couponNodes[i], 'click', BX.proxy(this.removeCouponAction, this)); 3692 } 3693 3694 }, 3695 3696 checkOutAction: function() 3697 { 3698 if (this.isAuthorized === 'Y') { 3699 document.location.href = this.params.PATH_TO_ORDER; 3700 } else { 3701 window.showBXMakerFormLogin(); 3702 } 3703 }, 3704 3705 addCouponAction: function(event) 3706 { 3707 var target = BX.getEventTarget(event); 3708 if (target && target.value) 3709 { 3710 this.actionPool.addCoupon(target.value); 3711 target.disabled = true; 3712 } 3713 }, 3714 3715 pasteCouponAction: function(event) 3716 { 3717 setTimeout(BX.delegate(function() { 3718 this.addCouponAction(event); 3719 }, this), 10); 3720 }, 3721 3722 removeCouponAction: function() 3723 { 3724 var value = BX.proxy_context && BX.util.trim(BX.proxy_context.getAttribute('data-coupon')); 3725 if (value) 3726 { 3727 this.actionPool.removeCoupon(value); 3728 } 3729 }, 3730 3731 initializeActionPool: function() 3732 { 3733 this.actionPool = new BX.Sale.BasketActionPool(this); 3734 }, 3735 3736 initializeFilter: function() 3737 { 3738 this.filter = new BX.Sale.BasketFilter(this); 3739 }, 3740 3741 /** 3742 * Send ajax request with basket data and executes callback by action 3743 */ 3744 sendRequest: function(action, data) 3745 { 3746 this.lastAction = action; 3747 3748 if (this.lastAction === 'recalculateAjax') 3749 { 3750 // we use it to reload all items if applied discounts changed 3751 data.lastAppliedDiscounts = BX.util.array_keys(this.result.FULL_DISCOUNT_LIST).join(','); 3752 3753 if (this.params.USE_ENHANCED_ECOMMERCE === 'Y') 3754 { 3755 this.checkAnalytics(data); 3756 } 3757 } 3758 3759 BX.ajax({ 3760 method: 'POST', 3761 dataType: 'json', 3762 url: this.ajaxUrl, 3763 data: this.getData(data), 3764 onsuccess: BX.delegate(function(result) { 3765 BX.ajax.runAction('intaro:retailcrm.api.loyalty.basket.addLoyaltyToBasket', 3766 { 3767 method: 'POST', 3768 data: { 3769 sessid: BX.bitrix_sessid(), 3770 basketData: result.BASKET_DATA 3771 }, 3772 } 3773 ) 3774 .then((response) => { 3775 //���� ��� ������ TOTAL 3776 if (response.data.TOTAL_RENDER_DATA.WILL_BE_CREDITED !== undefined) { 3777 $('#BONUSES_TOTAL').text(response.data.TOTAL_RENDER_DATA.WILL_BE_CREDITED
3777); 3778 } 3779 3780 //���� ��� ������ TOTAL 3781 if (response.data.TOTAL_RENDER_DATA.LOYALTY_DISCOUNT_FORMATED !== undefined) { 3782 $('#LOYALTY_DISCOUNT_TOTAL') 3783 .text(response.data.TOTAL_RENDER_DATA.LOYALTY_DISCOUNT_FORMATED); 3784 3785 $('.basket-coupon-block-total-price-current') 3786 .text(response.data.TOTAL_RENDER_DATA.PRICE_FORMATED); 3787 3788 $('.basket-coupon-block-total-price-difference').find('span:first-child') 3789 .text(response.data.TOTAL_RENDER_DATA.DISCOUNT_PRICE_FORMATED); 3790 3791 $('.basket-coupon-block-total-price-old') 3792 .html(response.data.TOTAL_RENDER_DATA.PRICE_WITHOUT_DISCOUNT_FORMATED); 3793 3794 $('#LOYALTY_DISCOUNT_DEFAULT') 3795 .text(response.data.TOTAL_RENDER_DATA.LOYALTY_DISCOUNT_DEFAULT); 3796 } 3797 3798 if (response.data.BASKET_ITEM_RENDER_DATA !== undefined) { 3799 response.data.BASKET_ITEM_RENDER_DATA.forEach( 3800 function (item, i, arr) { 3801 const itemId = '#basket-bonus-item-sum-price-' + item.ID; 3802 3803 if (response.data.TOTAL_RENDER_DATA.LOYALTY_DISCOUNT_FORMATED !== undefined) { 3804 let itemPriceDifference = '#basket-item-sum-price-difference-' + item.ID; 3805 let basketItemHeightAligner = '#basket-item-height-aligner-' + item.ID; 3806 let discountWithMinus = '-' + item.DISCOUNT_PRICE_PERCENT_FORMATED; 3807 3808 $(itemPriceDifference).text(item.SUM_DISCOUNT_PRICE_FORMATED); 3809 3810 $(basketItemHeightAligner).find('div[data-column-property-code=DISCOUNT]') 3811 .text(item.DISCOUNT_PRICE_PERCENT_FORMATED); 3812 $(basketItemHeightAligner).find('.basket-item-label-ring').text(discountWithMinus); 3813 } 3814 3815 if (item.WILL_BE_CREDITED_BONUS !== undefined 3816 && item.WILL_BE_CREDITED_BONUS > 0 3817 ) { 3818 $(itemId).text(item.WILL_BE_CREDITED_BONUS); 3819 } 3820 } 3821 ); 3822 } 3823 }).catch(err => console.log(err) ) 3824 this.actionPool.doProcessing(false); 3825 3826 if (!BX.type.isPlainObject(result)) 3827 return; 3828 3829 this.actionPool.setRefreshStatus(result.BASKET_REFRESHED); 3830 3831 if (result.RESTORED_BASKET_ITEMS) { 3832 this.restoreBasketItems(result.RESTORED_BASKET_ITEMS); 3833 } 3834 3835 if (result.DELETED_BASKET_ITEMS) { 3836 this.deleteBasketItems(result.DELETED_BASKET_ITEMS, this.params.SHOW_RESTORE === 'Y'); 3837 } 3838 3839 if (result.MERGED_BASKET_ITEMS) { 3840 this.deleteBasketItems(result.MERGED_BASKET_ITEMS, false, true); 3841 } 3842 3843 this.applyBasketResult(result.BASKET_DATA); 3844 setTimeout(() => { 3845 this.editBasketItems(this.getItemsToEdit()); 3846 this.editTotal(); 3847 }, 300) 3848 3849 this.applyPriceAnimation(); 3850 this.editWarnings(); 3851 3852 this.actionPool.switchTimer(); 3853 3854 if (this.isBasketIntegrated() && this.isBasketChanged()) { 3855 BX.Sale.OrderAjaxComponent.sendRequest(); 3856 } 3857 }, this), 3858 onfailure: BX.delegate(function() { 3859 this.actionPool.doProcessing(false); 3860 }, this) 3861 }); 3862 }, 3863 3864 isBasketIntegrated: function() 3865 { 3866 return this.params.BASKET_WITH_ORDER_INTEGRATION === 'Y'; 3867 }, 3868 3869 isBasketChanged: function() 3870 { 3871 return this.changedItems.length; 3872 }, 3873 3874 addPriceAnimationData: function(nodeId, start, finish, currency) 3875 { 3876 if (!BX.type.isPlainObject(this.priceAnimationData)) 3877 { 3878 this.clearPriceAnimationData(); 3879 } 3880 3881 this.priceAnimationData.start[nodeId] = parseFloat(start); 3882 this.priceAnimationData.finish[nodeId] = parseFloat(finish); 3883 this.priceAnimationData.currency[nodeId] = currency; 3884 this.priceAnimationData.int[nodeId] = (parseFloat(start) === parseInt(start)) && (parseFloat(finish) === parseInt(finish)); 3885 }, 3886 3887 clearPriceAnimationData: function() 3888 { 3889 this.priceAnimationData = { 3890 start: {}, 3891 finish: {}, 3892 currency: {}, 3893 int: {} 3894 }; 3895 }, 3896 3897 applyBasketResult: function(result) 3898 { 3899 3900 this.changedItems = []; 3901 this.clearPriceAnimationData(); 3902 3903 if (!BX.type.isPlainObject(result)) 3904 { 3905 return; 3906 } 3907 3908 if (result.BASKET_ITEM_RENDER_DATA) 3909 { 3910 var i, newData; 3911 3912 for (i in result.BASKET_ITEM_RENDER_DATA) 3913 { 3914 if (result.BASKET_ITEM_RENDER_DATA.hasOwnProperty(i)) 3915 { 3916 newData = result.BASKET_ITEM_RENDER_DATA[i]; 3917 newData.WARNINGS = this.checkBasketItemWarnings(newData, result.WARNING_MESSAGE_WITH_CODE);
3918 3919 if (this.items[newData.ID]) 3920 { 3921 if (JSON.stringify(this.items[newData.ID]) === JSON.stringify(newData)) 3922 { 3923 continue; 3924 } 3925 } 3926 else 3927 { 3928 this.addSortedItem(newData.ID, true); 3929 } 3930 3931 this.changedItems.push(newData.ID); 3932 3933 newData = this.checkBasketItemsAnimation(newData); 3934 this.items[newData.ID] = newData; 3935 } 3936 } 3937 3938 this.changedItems = BX.util.array_unique(this.changedItems.concat(this.getChangedSimilarOffers())); 3939 3940 if (this.isBasketChanged()) 3941 { 3942 this.sortSortedItems(true); 3943 } 3944 } 3945 3946 if (result.TOTAL_RENDER_DATA) 3947 { 3948 result.TOTAL_RENDER_DATA = this.checkTotalAnimation(result.TOTAL_RENDER_DATA); 3949 } 3950 console.log(result) 3951 this.result = result; 3952 }, 3953 3954 itemSortFunction: function(a, b) 3955 { 3956 if (!this.items.hasOwnProperty(a) || !this.items.hasOwnProperty(b)) 3957 { 3958 return 0; 3959 } 3960 3961 return parseFloat(this.items[a].SORT) - parseFloat(this.items[b].SORT); 3962 }, 3963 3964 getChangedSimilarOffers: function() 3965 { 3966 var changedSimilarOffers = []; 3967 3968 var otherSimilarItemsQuantity, totalSimilarItemsQuantity; 3969 var hashMap = this.getHashMap(); 3970 3971 for (var hash in hashMap) 3972 { 3973 if (hashMap.hasOwnProperty(hash)) 3974 { 3975 if (hashMap[hash].length > 1) 3976 { 3977 for (var i = 0; i < hashMap[hash].length; i++) 3978 { 3979 otherSimilarItemsQuantity = 0; 3980 totalSimilarItemsQuantity = 0; 3981 3982 for (var k = 0; k < hashMap[hash].length; k ++) 3983 { 3984 if (hashMap[hash][k] != hashMap[hash][i]) 3985 { 3986 otherSimilarItemsQuantity += parseFloat(this.items[hashMap[hash][k]].QUANTITY); 3987 } 3988 3989 totalSimilarItemsQuantity += parseFloat(this.items[hashMap[hash][k]].QUANTITY); 3990 } 3991 3992 if ( 3993 !this.items[hashMap[hash][i]].HAS_SIMILAR_ITEMS 3994 || this.items[hashMap[hash][i]].SIMILAR_ITEMS_QUANTITY != otherSimilarItemsQuantity 3995 || this.items[hashMap[hash][i]].TOTAL_SIMILAR_ITEMS_QUANTITY != totalSimilarItemsQuantity 3996 ) 3997 { 3998 changedSimilarOffers.push(hashMap[hash][i]); 3999 4000 this.items[hashMap[hash][i]].HAS_SIMILAR_ITEMS = true; 4001 this.items[hashMap[hash][i]].SIMILAR_ITEMS_QUANTITY = otherSimilarItemsQuantity; 4002 this.items[hashMap[hash][i]].TOTAL_SIMILAR_ITEMS_QUANTITY = totalSimilarItemsQuantity; 4003 4004 this.items[hashMap[hash][i]].ALL_AVAILABLE_QUANTITY = this.items[hashMap[hash][i]].AVAILABLE_QUANTITY; 4005 this.items[hashMap[hash][i]].AVAILABLE_QUANTITY = this.items[hashMap[hash][i]].ALL_AVAILABLE_QUANTITY - otherSimilarItemsQuantity; 4006 } 4007 } 4008 } 4009 else if (hashMap[hash][0] && this.items[hashMap[hash][0]].HAS_SIMILAR_ITEMS) 4010 { 4011 changedSimilarOffers.push(hashMap[hash][0]); 4012 4013 delete this.items[hashMap[hash][0]].HAS_SIMILAR_ITEMS; 4014 delete this.items[hashMap[hash][0]].SIMILAR_ITEMS_QUANTITY; 4015 delete this.items[hashMap[hash][0]].TOTAL_SIMILAR_ITEMS_QUANTITY; 4016 4017 this.items[hashMap[hash][0]].AVAILABLE_QUANTITY = this.items[hashMap[hash][0]].ALL_AVAILABLE_QUANTITY; 4018 delete this.items[hashMap[hash][0]].ALL_AVAILABLE_QUANTITY; 4019 } 4020 } 4021 } 4022 4023 return changedSimilarOffers; 4024 }, 4025 4026 getHashMap: function() 4027 { 4028 var hashMap = {}; 4029 4030 for (var id in this.items) 4031 { 4032 if (this.items.hasOwnProperty(id) && this.isItemAvailable(id)) 4033 { 4034 if (!hashMap.hasOwnProperty(this.items[id].HASH)) 4035 { 4036 hashMap[this.items[id].HASH] = []; 4037 } 4038 4039 hashMap[this.items[id].HASH].push(id); 4040 } 4041 } 4042 4043 return hashMap; 4044 }, 4045 4046 isItemAvailable: function(itemId) 4047 { 4048 var sortedItems = this.filter.isActive() ? this.filter.realSortedItems : this.sortedItems; 4049 4050 return !this.items[itemId].NOT_AVAILABLE 4051 && !this.items[itemId].SHOW_RESTORE 4052 && BX.util.in_array(itemId, sortedItems); 4053 }, 4054 4055 checkTotalAnimation: function(totalData) 4056 { 4057 if (this.result && this.result.TOTAL_RENDER_DATA && parseFloat(this.result.TOTAL_RENDER_DATA.PRICE) > parseFloat(totalData.PRICE)) 4058 { 4059 totalData.PRICE_NEW = totalData.PRICE; 4060 totalData.PRICE = this.result.TOTAL_RENDER_DATA.PRICE; 4061 4062 totalData.PRICE_FORMATED_NEW = totalData.PRICE_FORMATED; 4063 totalData.PRICE_FORMATED = this.result.TOTAL_RENDER_DATA.PRICE_FORMATED; 4064 4065 this.addPriceAnimationData(this.ids.total, totalData.PRICE, totalData.PRICE_NEW, totalData.CURRENCY); 4066 } 4067 4068 return totalData; 4069 }, 4070 4071 checkBasketItemsAnimation: function(itemData) 4072 { 4073 var itemId = itemData.ID; 4074 4075 if (this.items[itemId]) 4076 { 4077 var quantityNode = BX(this.ids.quantity + itemId); 4078 if ( 4079 BX.type.isDomNode(quantityNode) 4080 && !this.actionPool.isItemInPool(itemId) 4081 && parseFloat(quantityNode.value) !== parseFloat(itemData.QUANTITY) 4082 ) 4083 { 4084 itemData.QUANTITY_ANIMATION = true; 4085 this.actionPool.clearLastActualQuantityPool(itemId); 4086 } 4087 4088 if (parseFloat(this.items[itemId].PRICE) > parseFloat(itemData.PRICE)) 4089 { 4090 itemData.PRICE_NEW = itemData.PRICE; 4091 itemData.PRICE = this.items[itemId].PRICE; 4092 4093 itemData.PRICE_FORMATED_NEW = itemData.PRICE_FORMATED; 4094 itemData.PRICE_FORMATED = this.items[itemId].PRICE_FORMATED; 4095 4096 this.addPriceAnimationData(this.ids.price + itemId, itemData.PRICE, itemData.PRICE_NEW, itemData.CURRENCY); 4097 } 4098 4099 if ( 4100 BX.util.in_array('SUM', this.params.COLUMNS_LIST) 4101 && parseFloat(this.items[itemId].SUM_PRICE) > parseFloat(itemData.SUM_PRICE) 4102 && parseFloat(this.items[itemId].QUANTITY) === parseFloat(itemData.QUANTITY) 4103 ) 4104 { 4105 itemData.SUM_PRICE_NEW = itemData.SUM_PRICE;
4106 itemData.SUM_PRICE = this.items[itemId].SUM_PRICE; 4107 4108 itemData.SUM_PRICE_FORMATED_NEW = itemData.SUM_PRICE_FORMATED; 4109 itemData.SUM_PRICE_FORMATED = this.items[itemId].SUM_PRICE_FORMATED; 4110 4111 this.addPriceAnimationData(this.ids.sumPrice + itemId, itemData.SUM_PRICE, itemData.SUM_PRICE_NEW, itemData.CURRENCY); 4112 } 4113 } 4114 4115 return itemData; 4116 }, 4117 4118 getData: function(data) 4119 { 4120 data = data || {}; 4121 4122 data[this.params.ACTION_VARIABLE] = this.lastAction; 4123 data.via_ajax = 'Y'; 4124 data.site_id = this.siteId; 4125 data.site_template_id = this.siteTemplateId; 4126 data.sessid = BX.bitrix_sessid(); 4127 data.template = this.template; 4128 data.signedParamsString = this.signedParamsString; 4129 4130 return data; 4131 }, 4132 4133 startLoader: function() 4134 { 4135 // if (!this.loadingScreen) 4136 // { 4137 // this.loadingScreen = new BX.PopupWindow('loading_screen', null, { 4138 // events: { 4139 // onAfterPopupShow: BX.delegate(function() { 4140 // BX.cleanNode(this.loadingScreen.popupContainer); 4141 // BX.removeClass(this.loadingScreen.popupContainer, 'popup-window'); 4142 // this.loadingScreen.popupContainer.appendChild( 4143 // BX.create('IMG', {props: {src: this.templateFolder + '/images/loader.gif'}}) 4144 // ); 4145 // this.loadingScreen.popupContainer.removeAttribute('style'); 4146 // this.loadingScreen.popupContainer.style.display = 'block'; 4147 // }, this) 4148 // } 4149 // }); 4150 // BX.addClass(this.loadingScreen.popupContainer, 'bx-step-opacity'); 4151 // } 4152 // 4153 // this.loadingScreen.show(); 4154 }, 4155 4156 /** 4157 * Hiding loader image with overlay. 4158 */ 4159 endLoader: function() 4160 { 4161 // if (this.loadingScreen && this.loadingScreen.isShown()) 4162 // { 4163 // this.loadingScreen.close(); 4164 // } 4165 }, 4166 4167 editWarnings: function() 4168 { 4169 this.editGeneralWarnings(); 4170 this.editBasketItemWarnings(); 4171 this.toggleWarningBlock(); 4172 this.showWarningItemsCount(); 4173 }, 4174 4175 editGeneralWarnings: function() 4176 { 4177 var warningsNode = this.getEntity(this.getCacheNode(this.ids.warning), 'basket-general-warnings'); 4178 4179 if (BX.type.isDomNode(warningsNode)) 4180 { 4181 var generalWarningText = warningsNode.innerHTML; 4182 4183 if (this.result.WARNING_MESSAGE_WITH_CODE) 4184 { 4185 for (var code in this.result.WARNING_MESSAGE_WITH_CODE) 4186 { 4187 if (this.result.WARNING_MESSAGE_WITH_CODE.hasOwnProperty(code)) 4188 { 4189 if ( 4190 !this.items[code] 4191 && generalWarningText.indexOf(this.result.WARNING_MESSAGE_WITH_CODE[code]) === -1 4192 ) 4193 { 4194 generalWarningText += this.result.WARNING_MESSAGE_WITH_CODE[code] + '<br/>'; 4195 } 4196 } 4197 } 4198 } 4199 4200 if (generalWarningText) 4201 { 4202 warningsNode.innerHTML = generalWarningText; 4203 warningsNode.style.display = ''; 4204 } 4205 else 4206 { 4207 warningsNode.style.display = 'none'; 4208 warningsNode.innerHTML = ''; 4209 } 4210 } 4211 }, 4212 4213 editBasketItemWarnings: function() 4214 { 4215 var itemsWarningsNode = this.getEntity(this.getCacheNode(this.ids.warning), 'basket-item-warnings'); 4216 4217 if (BX.type.isDomNode(itemsWarningsNode)) 4218 { 4219 if (this.warningItems.length) 4220 { 4221 var warningCount = this.getEntity(itemsWarningsNode, 'basket-items-warning-count'); 4222 if (BX.type.isDomNode(warningCount)) 4223 { 4224 warningCount.innerHTML = this.warningItems.length + ' ' + this.getGoodsMessage(this.warningItems.length); 4225 } 4226 4227 itemsWarningsNode.style.display = ''; 4228 } 4229 else if (itemsWarningsNode.style.display !== 'none') 4230 { 4231 itemsWarningsNode.style.display = 'none'; 4232 4233 if (this.filter.isActive()) 4234 { 4235 this.toggleFilter('all'); 4236 } 4237 } 4238 } 4239 }, 4240 4241 toggleWarningBlock: function() 4242 { 4243 var warningNode = this.getCacheNode(this.ids.warning); 4244 4245 if (BX.type.isDomNode(warningNode)) 4246 { 4247 var generalWarningNode = this.getEntity(warningNode, 'basket-general-warnings'); 4248 var itemsWarningsNode = this.getEntity(warningNode, 'basket-item-warnings'); 4249 4250 if ( 4251 (!BX.type.isDomNode(generalWarningNode) || generalWarningNode.style.display === 'none') 4252 && (!BX.type.isDomNode(itemsWarningsNode) || itemsWarningsNode.style.display === 'none') 4253 ) 4254 { 4255 warningNode.style.display = 'none'; 4256 } 4257 else 4258 { 4259 warningNode.style.display = ''; 4260 } 4261 } 4262 }, 4263 4264 checkBasketItemWarnings: function(itemData, warnings) 4265 { 4266 if (!itemData) 4267 return; 4268 4269 var itemWarnings;
4270 4271 if (this.items[itemData.ID] && this.lastAction === 'refreshAjax') 4272 { 4273 itemWarnings = this.items[itemData.ID].WARNINGS; 4274 } 4275 else 4276 { 4277 itemWarnings = []; 4278 } 4279 4280 if (BX.type.isArray(warnings[itemData.ID]) && warnings[itemData.ID].length) 4281 { 4282 for (var i in warnings[itemData.ID]) 4283 { 4284 if (warnings[itemData.ID].hasOwnProperty(i) && !BX.util.in_array(warnings[itemData.ID][i], itemWarnings)) 4285 { 4286 itemWarnings.push(warnings[itemData.ID][i]); 4287 } 4288 } 4289 } 4290 4291 if (itemWarnings.length) 4292 { 4293 if (!BX.util.in_array(itemData.ID, this.warningItems)) 4294 { 4295 this.warningItems.push(itemData.ID); 4296 } 4297 } 4298 else if (BX.util.in_array(itemData.ID, this.warningItems)) 4299 { 4300 this.warningItems.splice(BX.util.array_search(itemData.ID, this.warningItems), 1); 4301 } 4302 4303 return itemWarnings; 4304 }, 4305 4306 removeAllWarnings: function(event) 4307 { 4308 this.clearGeneralWarnings(); 4309 this.clearBasketItemsWarnings(); 4310 4311 this.editWarnings(); 4312 4313 event && event.preventDefault(); 4314 }, 4315 4316 clearGeneralWarnings: function() 4317 { 4318 this.result.WARNING_MESSAGE_WITH_CODE = {}; 4319 4320 var generalWarningNode = this.getEntity(this.getCacheNode(this.ids.warning), 'basket-general-warnings'); 4321 4322 if (BX.type.isDomNode(generalWarningNode)) 4323 { 4324 generalWarningNode.innerHTML = ''; 4325 } 4326 }, 4327 4328 clearBasketItemsWarnings: function() 4329 { 4330 var itemsToEdit = []; 4331 4332 for (var i in this.warningItems) 4333 { 4334 if (this.warningItems.hasOwnProperty(i)) 4335 { 4336 this.items[this.warningItems[i]].WARNINGS = []; 4337 4338 if (this.isItemShown(this.warningItems[i])) 4339 { 4340 itemsToEdit.push(this.warningItems[i]); 4341 } 4342 } 4343 } 4344 4345 this.warningItems = []; 4346 setTimeout(() => { 4347 this.editBasketItems(itemsToEdit); 4348 }, 300) 4349 }, 4350 4351 isItemShown: function(itemId) 4352 { 4353 return BX.util.in_array(itemId, this.shownItems); 4354 }, 4355 4356 initializeBasketItems: function() 4357 { 4358 if (Object.keys(this.items).length === 0) 4359 return; 4360 4361 for (var i = 0; i < this.sortedItems.length; i++) 4362 { 4363 if (this.useDynamicScroll && this.shownItems.length >= this.maxItemsShowCount) 4364 { 4365 break; 4366 } 4367 4368 this.createBasketItem(this.sortedItems[i]); 4369 } 4370 }, 4371 4372 createBasketItem: function(itemId) 4373 { 4374 if (!this.items[itemId]) 4375 { 4376 return; 4377 } 4378 4379 var basketItemTemplate = this.getTemplate('basket-item-template'); 4380 if (basketItemTemplate) 4381 { 4382 var basketItemHtml = this.renderBasketItem(basketItemTemplate, this.items[itemId]); 4383 var sortIndex = BX.util.array_search(itemId, this.sortedItems); 4384 4385 if (this.shownItems.length && sortIndex >= 0) 4386 { 4387 if (sortIndex < BX.util.array_search(this.shownItems[0], this.sortedItems)) 4388 { 4389 // insert before 4390 BX(this.ids.item + this.shownItems[0]).insertAdjacentHTML('beforebegin', basketItemHtml); 4391 this.shownItems.unshift(itemId); 4392 } 4393 else if (sortIndex > BX.util.array_search(this.shownItems[this.shownItems.length - 1], this.sortedItems)) 4394 { 4395 // insert after 4396 console.log(this.ids.item + this.shownItems[this.shownItems.length - 1]) 4397 BX(this.ids.item + this.shownItems[this.shownItems.length - 1]).insertAdjacentHTML('afterend', basketItemHtml); 4398 this.shownItems.push(itemId); 4399 } 4400 else 4401 { 4402 // insert between 4403 BX(this.ids.item + this.sortedItems[sortIndex + 1]).insertAdjacentHTML('beforebegin', basketItemHtml); 4404 this.shownItems.splice(sortIndex + 1, 0, itemId); 4405 } 4406 } 4407 else 4408 { 4409 this.getCacheNode(this.ids.itemListTable).insertAdjacentHTML('beforeend', basketItemHtml); 4410 this.shownItems.push(itemId); 4411 } 4412 4413 this.bindBasketItemEvents(this.items[itemId]); 4414 4415 if (this.filter.isActive()) 4416 { 4417 this.filter.highlightSearchMatch(this.items[itemId]); 4418 } 4419 } 4420 }, 4421 4422 getItemsToEdit: function() 4423 { 4424 var itemIds = []; 4425 4426 if (this.isBasketChanged()) 4427 { 4428 for (var i in this.changedItems) 4429 { 4430 if (this.changedItems.hasOwnProperty(i) && this.isItemShown(this.changedItems[i])) 4431 { 4432 itemIds.push(this.changedItems[i]); 4433 } 4434 } 4435 } 4436 4437 return itemIds; 4438 }, 4439 4440 getItemsAfter: function() 4441 { 4442 var itemIdsAfter = []; 4443 4444 if (this.useDynamicScroll) 4445 { 4446 var lastShownItemId = this.shownItems[this.shownItems.length - 1] || false; 4447 4448 if (lastShownItemId) 4449 { 4450 var i = 0; 4451 var index = BX.util.array_search(lastShownItemId, this.sortedItems); 4452 4453 while (this.sortedItems[++index] && i++ < this.maxItemsShowCount) 4454 { 4455 itemIdsAfter.push(this.sortedItems[index]); 4456 } 4457 } 4458 } 4459 4460 return itemIdsAfter; 4461 }, 4462 4463 editBasketItems: function(itemIds) 4464 { 4465 if (!itemIds || itemIds.length === 0) 4466 { 4467 return; 4468 } 4469 4470 var i, item; 4471 4472 for (i in itemIds) 4473 {
4474 if (!itemIds.hasOwnProperty(i) || !BX.type.isPlainObject(this.items[itemIds[i]])) 4475 { 4476 continue; 4477 } 4478 4479 item = this.items[itemIds[i]]; 4480 4481 if (this.actionPool.isItemInPool(item.ID)) 4482 { 4483 if (!BX.util.in_array(item.ID, this.postponedItems)) 4484 { 4485 this.postponedItems.push(item.ID); 4486 } 4487 4488 continue; 4489 } 4490 4491 if (BX.type.isDomNode(BX(this.ids.item + item.ID))) 4492 { 4493 this.redrawBasketItemNode(item.ID); 4494 this.applyQuantityAnimation(item.ID); 4495 } 4496 else 4497 { 4498 this.createBasketItem(item.ID); 4499 } 4500 } 4501 }, 4502 4503 editPostponedBasketItems: function() 4504 { 4505 if (!this.postponedItems.length) 4506 return; 4507 4508 var itemsToEdit = []; 4509 4510 for (var i in this.postponedItems) 4511 { 4512 if (this.postponedItems.hasOwnProperty(i) && this.isItemShown(this.postponedItems[i])) 4513 { 4514 itemsToEdit.push(this.postponedItems[i]); 4515 } 4516 } 4517 4518 this.postponedItems = []; 4519 setTimeout(() => { 4520 this.editBasketItems(itemsToEdit); 4521 }, 300) 4522 }, 4523 4524 applyQuantityAnimation: function(itemId) 4525 { 4526 var basketItemNode = BX(this.ids.item + itemId); 4527 4528 if (BX.type.isDomNode(basketItemNode) && this.items[itemId]) 4529 { 4530 if (this.items[itemId].QUANTITY_ANIMATION) 4531 { 4532 BX.addClass(BX(this.ids.quantity + itemId), 'basket-updated'); 4533 } 4534 } 4535 }, 4536 4537 applyPriceAnimation: function() 4538 { 4539 if (!this.priceAnimationData || Object.keys(this.priceAnimationData.start).length === 0) 4540 return; 4541 4542 var animationData = this.priceAnimationData, 4543 nodeCache = {}; 4544 4545 new BX.easing({ 4546 duration: this.params.USE_PRICE_ANIMATION === 'Y' ? this.duration.priceAnimation : 1, 4547 start: animationData.start, 4548 finish: animationData.finish, 4549 transition: BX.easing.makeEaseOut(BX.easing.transitions.quad), 4550 step: BX.delegate(function(state){ 4551 for (var nodeId in animationData.start) 4552 { 4553 if (animationData.start.hasOwnProperty(nodeId)) 4554 { 4555 if (!nodeCache[nodeId]) 4556 { 4557 if (nodeId === this.ids.total) 4558 { 4559 nodeCache[nodeId] = this.getEntities(this.getCacheNode(this.ids.basketRoot), this.ids.total); 4560 } 4561 else 4562 { 4563 var node = BX(nodeId); 4564 nodeCache[nodeId] = node ? [node] : []; 4565 } 4566 } 4567 4568 if (!animationData.int[nodeId]) 4569 { 4570 // fix price blinking 4571 state[nodeId] = (state[nodeId] + (state[nodeId] % 1000) / 1000).toFixed(5); 4572 } 4573 4574 for (var i = 0; i < nodeCache[nodeId].length; i++) 4575 { 4576 nodeCache[nodeId][i].innerHTML = this.getFormatPrice(state[nodeId], animationData.currency[nodeId]); 4577 } 4578 } 4579 } 4580 }, this), 4581 complete: BX.delegate(function() { 4582 var nodeId, formattedPrice, itemId, type; 4583 4584 for (nodeId in animationData.start) 4585 { 4586 if (animationData.start.hasOwnProperty(nodeId)) 4587 { 4588 formattedPrice = this.getFormatPrice(animationData.finish[nodeId], animationData.currency[nodeId]); 4589 4590 for (var i = 0; i < nodeCache[nodeId].length; i++) 4591 { 4592 nodeCache[nodeId][i].innerHTML = formattedPrice; 4593 } 4594 4595 if (nodeId.indexOf(this.ids.sumPrice) !== -1) 4596 { 4597 type = 'SUM_PRICE'; 4598 itemId = nodeId.substr(this.ids.sumPrice.length); 4599 } 4600 else if (nodeId.indexOf(this.ids.price) !== -1) 4601 { 4602 type = 'PRICE'; 4603 itemId = nodeId.substr(this.ids.price.length); 4604 } 4605 else if (nodeId.indexOf(this.ids.total) !== -1) 4606 { 4607 type = 'TOTAL'; 4608 itemId = ''; 4609 } 4610 else 4611 { 4612 itemId = ''; 4613 type = ''; 4614 } 4615 4616 if (BX.type.isNotEmptyString(type)) 4617 { 4618 if (itemId) 4619 { 4620 this.items[itemId][type] = animationData.finish[nodeId]; 4621 delete this.items[itemId][type + '_NEW']; 4622 this.items[itemId][type + '_FORMATED'] = formattedPrice; 4623 delete this.items[itemId][type + '_FORMATED_NEW']; 4624 } 4625 else if (type === 'TOTAL') 4626 { 4627 this.result.TOTAL_RENDER_DATA.PRICE = animationData.finish[nodeId]; 4628 delete this.result.TOTAL_RENDER_DATA.PRICE_NEW; 4629 this.result.TOTAL_RENDER_DATA.PRICE_FORMATED = formattedPrice; 4630 delete this.result.TOTAL_RENDER_DATA.PRICE_FORMATED_NEW; 4631 } 4632 } 4633 } 4634 } 4635 4636 this.filter.highlightFoundItems();
4637 }, this) 4638 }).animate(); 4639 }, 4640 4641 getFormatPrice: function(price, currency) 4642 { 4643 return BX.Currency.currencyFormat(price, currency, true); 4644 }, 4645 4646 deleteBasketItems: function(items, restore, final) 4647 { 4648 if (!items || !items.length) 4649 { 4650 return; 4651 } 4652 4653 for (var i in items) 4654 { 4655 if (items.hasOwnProperty(i)) 4656 { 4657 this.deleteBasketItem(items[i], restore, final); 4658 } 4659 } 4660 }, 4661 4662 deleteBasketItem: function(itemId, restore, final) 4663 { 4664 // delete not available item with no chance to restore 4665 if (this.items[itemId].NOT_AVAILABLE && restore) 4666 { 4667 restore = false; 4668 final = true; 4669 } 4670 4671 if (restore) 4672 { 4673 this.items[itemId].SHOW_RESTORE = true; 4674 this.items[itemId].SHOW_LOADING = false; 4675 this.redrawBasketItemNode(itemId); 4676 } 4677 else 4678 { 4679 this.changeShownItem(itemId); 4680 BX.remove(BX(this.ids.item + itemId)); 4681 } 4682 4683 if (final) 4684 { 4685 this.changeSortedItem(itemId, false, true); 4686 this.changeShownItem(itemId, false, true); 4687 } 4688 }, 4689 4690 addSortedItem: function(itemId, all) 4691 { 4692 this.sortedItems.push(itemId.toString()); 4693 4694 if (all && this.filter.isActive()) 4695 { 4696 this.filter.realSortedItems.push(itemId.toString()); 4697 } 4698 }, 4699 4700 changeSortedItem: function(itemId, newItemId, all) 4701 { 4702 var index = BX.util.array_search(itemId, this.sortedItems); 4703 4704 if (index >= 0) 4705 { 4706 if (newItemId) 4707 { 4708 this.sortedItems.splice(index, 1, newItemId.toString()); 4709 } 4710 else 4711 { 4712 this.sortedItems.splice(index, 1); 4713 } 4714 } 4715 4716 if (all && this.filter.isActive()) 4717 { 4718 index = BX.util.array_search(itemId, this.filter.realSortedItems); 4719 4720 if (index >= 0) 4721 { 4722 if (newItemId) 4723 { 4724 this.filter.realSortedItems.splice(index, 1, newItemId.toString()); 4725 } 4726 else 4727 { 4728 this.filter.realSortedItems.splice(index, 1); 4729 } 4730 } 4731 } 4732 }, 4733 4734 sortSortedItems: function(all) 4735 { 4736 this.sortedItems.sort(BX.proxy(this.itemSortFunction, this)); 4737 4738 if (all && this.filter.isActive()) 4739 { 4740 this.filter.realSortedItems.sort(BX.proxy(this.itemSortFunction, this)); 4741 } 4742 }, 4743 4744 changeShownItem: function(itemId, newItemId, all) 4745 { 4746 var index = BX.util.array_search(itemId, this.shownItems); 4747 4748 if (index >= 0) 4749 { 4750 if (newItemId) 4751 { 4752 this.shownItems.splice(index, 1, newItemId.toString()); 4753 } 4754 else 4755 { 4756 this.shownItems.splice(index, 1); 4757 } 4758 } 4759 4760 if (all && this.filter.isActive()) 4761 { 4762 index = BX.util.array_search(itemId, this.filter.realShownItems); 4763 4764 if (index >= 0) 4765 { 4766 if (newItemId) 4767 { 4768 this.filter.realShownItems.splice(index, 1, newItemId.toString()); 4769 } 4770 else 4771 { 4772 this.filter.realShownItems.splice(index, 1); 4773 } 4774 } 4775 } 4776 }, 4777 4778 redrawBasketItemNode: function(itemId) 4779 { 4780 var basketItemNode = BX(this.ids.item + itemId); 4781 4782 if (!this.items[itemId] || !BX.type.isDomNode(basketItemNode)) 4783 return; 4784 4785 var basketItemTemplate = this.getTemplate('basket-item-template'); 4786 if (basketItemTemplate) 4787 { 4788 var nodeAligner = BX(this.ids.itemHeightAligner + itemId), 4789 oldHeight; 4790 4791 if (BX.type.isDomNode(nodeAligner)) 4792 { 4793 oldHeight = nodeAligner.clientHeight; 4794 } 4795 4796 var basketItemHtml = this.renderBasketItem(basketItemTemplate, this.items[itemId]); 4797 basketItemNode.insertAdjacentHTML('beforebegin', basketItemHtml); 4798 BX.remove(basketItemNode); 4799 4800 if (oldHeight) 4801 { 4802 nodeAligner = BX(this.ids.itemHeightAligner + itemId); 4803 4804 if (BX.type.isDomNode(nodeAligner) && nodeAligner.clientHeight < oldHeight) 4805 { 4806 nodeAligner.style.minHeight = oldHeight + 'px'; 4807 setTimeout(function(){nodeAligner.style.minHeight = '0px';}, 1); 4808 } 4809 } 4810 4811 this.bindBasketItemEvents(this.items[itemId]); 4812 4813 if (this.filter.isActive()) 4814 { 4815 this.filter.highlightSearchMatch(this.items[itemId]); 4816 } 4817 } 4818 }, 4819 4820 restoreBasketItems: function(items) 4821 { 4822 if (!items || Object.keys(items).length === 0) 4823 { 4824 return; 4825 } 4826 4827 var oldItemId, newItemId, basketItemNode; 4828 4829 for (oldItemId in items) 4830 { 4831 if (items.hasOwnProperty(oldItemId)) 4832 { 4833 newItemId = items[oldItemId]; 4834 4835 if (this.isItemShown(oldItemId)) 4836 { 4837 this.changeShownItem(oldItemId, newItemId, true); 4838 4839 basketItemNode = BX(this.ids.item + oldItemId); 4840 if (BX.type.isDomNode(basketItemNode)) 4841 { 4842 basketItemNode.id = this.ids.item + newItemId; 4843 basketItemNode.setAttribute('data-id', newItemId); 4844 } 4845 } 4846 4847 this.changeSortedItem(oldItemId, false, true); 4848 } 4849 } 4850 }, 4851 4852 bindBasketItemEvents: function(itemData) 4853 { 4854 if (!itemData) 4855 return; 4856 4857 var itemNode = BX(this.ids.item + itemData.ID); 4858 if (BX.type.isDomNode(itemNode)) 4859 { 4860 this.bindQuantityEvents(itemNode, itemData); 4861 this.bindSkuEvents(itemNode, itemData); 4862 this.bindImageEvents(itemNode, itemData); 4863 this.bindActionEvents(itemNode, itemData); 4864 this.bindRestoreAction(itemNode, itemData); 4865 this.bindItemWarningEvents(itemNode, itemData); 4866 } 4867 }, 4868 4869 bindQuantityEvents: function(node, data) 4870 { 4871 if (!node || !data || !this.isItemAvailable(data.ID)) 4872 return; 4873 4874 var entity; 4875 4876 var block = this.getEntity(node, 'basket-item-quantity-block'); 4877 if (block) 4878 { 4879 var startEventName = this.isTouch ? 'touchstart' : 'mousedown'; 4880 var endEventName = this.isTouch ? 'touchend' : 'mouseup'; 4881 4882 entity = this.getEntity(block, 'basket-item-quantity-minus'); 4883 BX.bind(entity, startEventName, BX.proxy(this.startQuantityInterval, this)); 4884 BX.bind(entity, endEventName, BX.proxy(this.clearQuantityInterval, this)); 4885 BX.bind(entity, 'mouseout', BX.proxy(this.clearQuantityInterval, this)); 4886 BX.bind(entity, 'click', BX.proxy(this.quantityMinus, this)); 4887 4888 entity = this.getEntity(block, 'basket-item-quantity-plus'); 4889 BX.bind(entity, startEventName, BX.proxy(this.startQuantityInterval, this)); 4890 BX.bind(entity, endEventName, BX.proxy(this.clearQuantityInterval, this)); 4891 BX.bind(entity, 'mouseout', BX.proxy(this.clearQuantityInterval, this)); 4892 BX.bind(entity, 'click', BX.proxy(this.quantityPlus, this)); 4893 4894 entity = this.getEntity(block, 'basket-item-quantity-field'); 4895 BX.bind(entity, 'change', BX.proxy(this.quantityChange, this)); 4896 } 4897 }, 4898 4899 startQuantityInterval: function() 4900 { 4901 var target = BX.proxy_context; 4902 var func = target.getAttribute('data-entity') === 'basket-item-quantity-minus' 4903 ? BX.proxy(this.quantityMinus, this) 4904 : BX.proxy(this.quantityPlus, this); 4905 4906 this.quantityDelay = setTimeout( 4907 BX.delegate(function() { 4908 this.quantityTimer = setInterval(function(){func(target);}, 150); 4909 }, this), 4910 300 4911 ); 4912 }, 4913 4914 clearQuantityInterval: function() 4915 { 4916 clearTimeout(this.quantityDelay); 4917 clearInterval(this.quantityTimer); 4918 }, 4919 4920 quantityPlus: function(target) 4921 { 4922 if (!BX.type.isDomNode(target)) 4923 { 4924 target = BX.proxy_context; 4925 this.clearQuantityInterval(); 4926 } 4927 4928 var itemData = this.getItemDataByTarget(target); 4929 if (itemData) 4930 { 4931 var quantityField = BX(this.ids.quantity + itemData.ID); 4932 var isQuantityFloat = this.isQuantityFloat(itemData); 4933 4934 var currentQuantity = isQuantityFloat ? parseFloat(quantityField.value) : Math.round(quantityField.value); 4935 var measureRatio = isQuantityFloat ? parseFloat(itemData.MEASURE_RATIO) : parseInt(itemData.MEASURE_RATIO); 4936 4937 var quantity = parseFloat((currentQuantity + measureRatio).toFixed(5)); 4938 quantity = this.getCorrectQuantity(itemData, quantity); 4939 4940 this.setQuantity(itemData, quantity); 4941 } 4942 }, 4943 4944 quantityMinus: function(target) 4945 { 4946 target = BX.type.isDomNode(target) ? target : BX.proxy_context; 4947 4948 var itemData = this.getItemDataByTarget(target); 4949 if (itemData) 4950 { 4951 var quantityField = BX(this.ids.quantity + itemData.ID); 4952 var isQuantityFloat = this.isQuantityFloat(itemData); 4953 4954 var currentQuantity = isQuantityFloat ? parseFloat(quantityField.value) : Math.round(quantityField.value); 4955 var measureRatio = isQuantityFloat ? parseFloat(itemData.MEASURE_RATIO) : parseInt(itemData.MEASURE_RATIO); 4956 4957 var quantity = parseFloat((currentQuantity - measureRatio).toFixed(5)); 4958 quantity = this.getCorrectQuantity(itemData, quantity); 4959 4960 this.setQuantity(itemData, quantity); 4961 } 4962 }, 4963 4964 quantityChange: function() 4965 { 4966 var itemData = this.getItemDataByTarget(BX.proxy_context); 4967 if (itemData) 4968 { 4969 var quantityField, quantity; 4970 4971 quantityField = BX(this.ids.quantity + itemData.ID); 4972 quantity = this.getCorrectQuantity(itemData, quantityField.value); 4973 4974 this.setQuantity(itemData, quantity); 4975 } 4976 }, 4977 4978 isQuantityFloat: function(item) 4979 { 4980 return this.params.QUANTITY_FLOAT === 'Y' || (parseInt(item.MEASURE_RATIO) !== parseFloat(item.MEASURE_RATIO)); 4981 }, 4982 4983 getCorrectQuantity: function(itemData, quantity) 4984 { 4985 var isQuantityFloat = this.isQuantityFloat(itemData), 4986 measureRatio = isQuantityFloat ? parseFloat(itemData.MEASURE_RATIO) : parseInt(itemData.MEASURE_RATIO), 4987 availableQuantity = 0; 4988 4989 quantity = (isQuantityFloat ? parseFloat(quantity) : parseInt(quantity, 10)) || 0; 4990 if (quantity < 0) 4991 { 4992 quantity = 0; 4993 } 4994 4995 if (measureRatio > 0 && quantity < measureRatio) 4996 { 4997 quantity = measureRatio; 4998 } 4999 5000 if (itemData.CHECK_MAX_QUANTITY === 'Y') 5001 { 5002 availableQuantity = isQuantityFloat ? parseFloat(itemData.AVAILABLE_QUANTITY) : parseInt(itemData.AVAILABLE_QUANTITY); 5003 if (availableQuantity > 0 && quantity > availableQuantity) 5004 { 5005 quantity = availableQuantity; 5006 } 5007 } 5008 5009 var reminder = (quantity / measureRatio - ((quantity / measureRatio).toFixed(0))).toFixed(5), 5010 remain; 5011 5012 if (parseFloat(reminder) === 0) 5013 { 5014 return quantity; 5015 } 5016 5017 if (measureRatio !== 0 && measureRatio !== 1) 5018 { 5019 remain = (quantity * this.precisionFactor) % (measureRatio * this.precisionFactor) / this.precisionFactor; 5020 5021 if (measureRatio > 0 && remain > 0) 5022 { 5023 if ( 5024 remain >= measureRatio / 2 5025 && ( 5026 availableQuantity === 0 5027 || (quantity + measureRatio - remain) <= availableQuantity 5028 ) 5029 ) 5030 { 5031 quantity += (measureRatio - remain); 5032 } 5033 else 5034 { 5035 quantity -= remain; 5036 } 5037 } 5038 } 5039 5040 quantity = isQuantityFloat ? parseFloat(quantity) : parseInt(quantity, 10); 5041 5042 return quantity; 5043 }, 5044 5045 setQuantity: function(itemData, quantity) 5046 { 5047 var quantityField = BX(this.ids.quantity + itemData.ID), 5048 currentQuantity; 5049 5050 if (quantityField) 5051 { 5052 quantity = parseFloat(quantity); 5053 currentQuantity = parseFloat(quantityField.getAttribute('data-value')); 5054 5055 quantityField.value = quantity; 5056 5057 if (parseFloat(itemData.QUANTITY) !== parseFloat(quantity)) 5058 { 5059 this.animatePriceByQuantity(itemData, quantity); 5060 this.actionPool.changeQuantity(itemData.ID, quantity, currentQuantity); 5061 } 5062 } 5063 }, 5064 5065 animatePriceByQuantity: function(itemData, quantity) 5066 { 5067 var priceNode = BX(this.ids.sumPrice + itemData.ID); 5068 if (!BX.type.isDomNode(priceNode)) 5069 return; 5070 5071 var quantityMultiplier = quantity / parseFloat(itemData.MEASURE_RATIO); 5072 5073 var startPrice = parseFloat(itemData.SUM_PRICE), 5074 finalPrice = parseFloat(itemData.PRICE) * quantityMultiplier, 5075 isInt = parseInt(startPrice) === parseFloat(startPrice) 5076 && parseInt(finalPrice) === parseFloat(finalPrice); 5077 5078 if (startPrice !== finalPrice) 5079 { 5080 this.items[itemData.ID].QUANTITY = quantity;
5081 this.items[itemData.ID].SUM_PRICE = finalPrice; 5082 5083 new BX.easing({ 5084 duration: this.params.USE_PRICE_ANIMATION === 'Y' ? this.duration.priceAnimation : 1, 5085 start: {price: startPrice}, 5086 finish: {price: finalPrice}, 5087 transition: BX.easing.makeEaseOut(BX.easing.transitions.quad), 5088 step: BX.delegate(function(state){ 5089 if (!isInt) 5090 { 5091 // fix price blinking 5092 state.price = (state.price + (state.price % 1000) / 1000).toFixed(5); 5093 } 5094 5095 priceNode.innerHTML = this.getFormatPrice(state.price, itemData.CURRENCY); 5096 }, this), 5097 complete: BX.delegate(function() { 5098 var node, price; 5099 5100 priceNode.innerHTML = this.getFormatPrice(finalPrice, itemData.CURRENCY); 5101 5102 node = BX(this.ids.sumPriceOld + itemData.ID); 5103 if (BX.type.isDomNode(node)) 5104 { 5105 price = parseFloat(itemData.FULL_PRICE) * quantityMultiplier; 5106 node.innerHTML = this.getFormatPrice(price, itemData.CURRENCY); 5107 } 5108 5109 node = BX(this.ids.sumPriceDiff + itemData.ID); 5110 if (BX.type.isDomNode(node)) 5111 { 5112 price = parseFloat(itemData.DISCOUNT_PRICE) * quantityMultiplier; 5113 node.innerHTML = this.getFormatPrice(price, itemData.CURRENCY); 5114 } 5115 }, this) 5116 }).animate(); 5117 } 5118 }, 5119 5120 getItemDataByTarget: function(target) 5121 { 5122 var data = false; 5123 var id; 5124 5125 var itemNode = BX.findParent(target, {attrs: {'data-entity': 'basket-item'}}); 5126 if (itemNode) 5127 { 5128 id = itemNode.getAttribute('data-id'); 5129 data = this.items[id]; 5130 } 5131 5132 return data; 5133 }, 5134 5135 bindSkuEvents: function(node, data) 5136 { 5137 if (!node || !data) 5138 return; 5139 5140 var blocks = this.getEntities(node, 'basket-item-sku-block'); 5141 var blockEntities, i, l, ii, ll; 5142 5143 for (i = 0, l = blocks.length; i < l; i++) 5144 { 5145 blockEntities = this.getEntities(blocks[i], 'basket-item-sku-field'); 5146 5147 for (ii = 0, ll = blockEntities.length; ii < ll; ii++) 5148 { 5149 BX.bind(blockEntities[ii], 'click', BX.proxy(this.changeSku, this)); 5150 } 5151 } 5152 }, 5153 5154 changeSku: function() 5155 { 5156 var i, l; 5157 5158 var target = BX.proxy_context; 5159 5160 if (BX.hasClass(target, 'selected')) 5161 return; 5162 5163 var itemData = this.getItemDataByTarget(target); 5164 if (itemData) 5165 { 5166 var basketItemNode = BX(this.ids.item + itemData.ID); 5167 if (basketItemNode) 5168 { 5169 var currentSkuListNodes = this.getEntities(target.parentNode, 'basket-item-sku-field'); 5170 for (i = 0, l = currentSkuListNodes.length; i < l; i++) 5171 { 5172 if (currentSkuListNodes[i].isEqualNode(target)) 5173 { 5174 BX.addClass(currentSkuListNodes[i], 'selected'); 5175 } 5176 else 5177 { 5178 BX.removeClass(currentSkuListNodes[i], 'selected'); 5179 } 5180 } 5181 5182 this.actionPool.changeSku( 5183 itemData.ID, 5184 this.getSkuPropertyValues(basketItemNode), 5185 this.getInitialSkuPropertyValues(basketItemNode) 5186 ); 5187 } 5188 } 5189 }, 5190 5191 getSkuPropertyValues: function(basketItemNode) 5192 { 5193 var propertyValues = {}; 5194 5195 var propNodes = this.getEntities(basketItemNode, 'basket-item-sku-field', '.selected'); 5196 for (var i = 0, l = propNodes.length; i < l; i++) 5197 { 5198 propertyValues[propNodes[i].getAttribute('data-property')] = BX.util.htmlspecialcharsback(propNodes[i].getAttribute('data-value-id')); 5199 } 5200 5201 return propertyValues; 5202 }, 5203 5204 getInitialSkuPropertyValues: function(basketItemNode) 5205 { 5206 var propertyValues = {}; 5207 5208 var propNodes = this.getEntities(basketItemNode, 'basket-item-sku-field', '[data-initial="true"]'); 5209 for (var i = 0, l = propNodes.length; i < l; i++) 5210 { 5211 propertyValues[propNodes[i].getAttribute('data-property')] = BX.util.htmlspecialcharsback(propNodes[i].getAttribute('data-value-id')); 5212 } 5213 5214 return propertyValues; 5215 }, 5216 5217 bindImageEvents: function(node, data) 5218 { 5219 if (!node || !data) 5220 return; 5221 5222 var images = node.querySelectorAll('.basket-item-custom-block-photo-item'); 5223 for (var i = 0, l = images.length; i < l; i++) 5224 { 5225 BX.bind(images[i], 'click', BX.proxy(this.showPropertyImagePopup, this)); 5226 } 5227 }, 5228 5229 showPropertyImagePopup: function() 5230 { 5231 var target, propertyCode, imageIndex, item, imageSrc, i; 5232 5233 target = BX.proxy_context; 5234 item = this.getItemDataByTarget(target); 5235 5236 propertyCode = target.getAttribute('data-column-property-code'); 5237 imageIndex = target.getAttribute('data-image-index'); 5238 5239 if (item && item.COLUMN_LIST) 5240 { 5241 for (i in item.COLUMN_LIST) 5242 { 5243 if ( 5244 item.COLUMN_LIST.hasOwnProperty(i) 5245 && item.COLUMN_LIST[i].CODE === propertyCode 5246 && item.COLUMN_LIST[i].VALUE[imageIndex] 5247 ) 5248 { 5249 imageSrc = item.COLUMN_LIST[i].VALUE[imageIndex].IMAGE_SRC_ORIGINAL; 5250 break; 5251 } 5252 } 5253 } 5254 5255 if (!imageSrc) 5256 { 5257 return; 5258 } 5259 5260 if (this.imagePopup) 5261 { 5262 this.imagePopup.destroy(); 5263 } 5264 5265 var imageId = 'bx-soa-image-popup-content'; 5266 var that = this; 5267 5268 this.imagePopup = new BX.PopupWindow('bx-soa-image-popup', null, { 5269 lightShadow: true, 5270 offsetTop: 0, 5271 offsetLeft: 0, 5272 closeIcon: {top: '3px', right: '10px'}, 5273 autoHide: true, 5274 bindOptions: {position: 'bottom'}, 5275 closeByEsc: true, 5276 zIndex: 100, 5277 events: { 5278 onPopupShow: function() { 5279 BX.create('IMG', { 5280 props: {src: imageSrc}, 5281 events: { 5282 load: function() { 5283 var content = BX(imageId); 5284 if (content) 5285 { 5286 var windowSize = BX.GetWindowInnerSize(), 5287 ratio = that.isMobile ? 0.5 : 0.9, 5288 contentHeight, contentWidth; 5289 5290 BX.cleanNode(content); 5291 content.appendChild(this); 5292 5293 contentHeight = content.offsetHeight; 5294 contentWidth = content.offsetWidth; 5295 5296 if (contentHeight >
5296 windowSize.innerHeight * ratio) 5297 { 5298 content.style.height = windowSize.innerHeight * ratio + 'px'; 5299 content.style.width = contentWidth * (windowSize.innerHeight * ratio / contentHeight) + 'px'; 5300 contentHeight = content.offsetHeight; 5301 contentWidth = content.offsetWidth; 5302 } 5303 5304 if (contentWidth > windowSize.innerWidth * ratio) 5305 { 5306 content.style.width = windowSize.innerWidth * ratio + 'px'; 5307 content.style.height = contentHeight * (windowSize.innerWidth * ratio / contentWidth) + 'px'; 5308 } 5309 5310 content.style.height = content.offsetHeight + 'px'; 5311 content.style.width = content.offsetWidth + 'px'; 5312 5313 that.imagePopup.adjustPosition(); 5314 } 5315 } 5316 } 5317 }); 5318 }, 5319 onPopupClose: function() { 5320 this.destroy(); 5321 } 5322 }, 5323 content: BX.create('DIV', {props: {id: imageId}}) 5324 }); 5325 this.imagePopup.show(); 5326 }, 5327 5328 bindActionEvents: function(node, data) 5329 { 5330 if (!node || !data) 5331 return; 5332 5333 var entity; 5334 5335 if (BX.util.in_array('DELETE', this.params.COLUMNS_LIST)) 5336 { 5337 entity = this.getEntities(node, 'basket-item-delete'); 5338 for (var i = 0, l = entity.length; i < l; i++) 5339 { 5340 BX.bind(entity[i], 'click', BX.proxy(this.deleteAction, this)); 5341 } 5342 } 5343 5344 if (BX.util.in_array('DELAY', this.params.COLUMNS_LIST)) 5345 { 5346 entity = this.getEntity(node, 'basket-item-add-delayed'); 5347 BX.bind(entity, 'click', BX.proxy(this.addDelayedAction, this)); 5348 } 5349 5350 entity = this.getEntity(node, 'basket-item-remove-delayed'); 5351 BX.bind(entity, 'click', BX.proxy(this.removeDelayedAction, this)); 5352 5353 entity = this.getEntity(node, 'basket-item-merge-sku-link'); 5354 BX.bind(entity, 'click', BX.proxy(this.mergeAction, this)); 5355 5356 entity = this.getEntity(node, 'basket-item-show-similar-link'); 5357 BX.bind(entity, 'click', BX.delegate(function() {this.toggleFilter('similar');}, this)); 5358 }, 5359 5360 deleteAction: function() 5361 { 5362 var itemData = this.getItemDataByTarget(BX.proxy_context); 5363 if (itemData) 5364 { 5365 this.actionPool.deleteItem(itemData.ID); 5366 5367 this.items[itemData.ID].SHOW_LOADING = true; 5368 5369 if (this.params.SHOW_RESTORE === 'Y' && this.isItemAvailable(itemData.ID)) 5370 { 5371 this.items[itemData.ID].SHOW_RESTORE = true; 5372 } 5373 5374 this.redrawBasketItemNode(itemData.ID); 5375 } 5376 }, 5377 5378 addDelayedAction: function() 5379 { 5380 var itemData = this.getItemDataByTarget(BX.proxy_context); 5381 if (itemData) 5382 { 5383 this.actionPool.addDelayed(itemData.ID); 5384 5385 this.items[itemData.ID].SHOW_LOADING = true; 5386 this.redrawBasketItemNode(itemData.ID); 5387 } 5388 }, 5389 5390 removeDelayedAction: function() 5391 { 5392 var itemData = this.getItemDataByTarget(BX.proxy_context); 5393 if (itemData) 5394 { 5395 this.actionPool.removeDelayed(itemData.ID); 5396 5397 this.items[itemData.ID].SHOW_LOADING = true; 5398 this.redrawBasketItemNode(itemData.ID); 5399 } 5400 }, 5401 5402 mergeAction: function() 5403 { 5404 var itemData = this.getItemDataByTarget(BX.proxy_context); 5405 if (itemData) 5406 { 5407 this.actionPool.mergeSku(itemData.ID); 5408 } 5409 }, 5410 5411 bindRestoreAction: function(node, itemData) 5412 { 5413 if (!node || !itemData || this.params.SHOW_RESTORE !== 'Y') 5414 return; 5415 5416 BX.bind( 5417 this.getEntity(node, 'basket-item-restore-button'), 5418 'click', 5419 BX.delegate(function() { 5420 this.actionPool.restoreItem(itemData.ID, { 5421 PRODUCT_ID: itemData.PRODUCT_ID, 5422 QUANTITY: itemData.QUANTITY, 5423 PROPS: itemData.PROPS_ALL, 5424 SORT: itemData.SORT, 5425 MODULE: itemData.MODULE, 5426 PRODUCT_PROVIDER_CLASS: itemData.PRODUCT_PROVIDER_CLASS 5427 }); 5428 5429 this.items[itemData.ID].SHOW_RESTORE = false; 5430 this.items[itemData.ID].SHOW_LOADING = true; 5431 this.redrawBasketItemNode(itemData.ID); 5432 }, this) 5433 ); 5434 BX.bind( 5435 this.getEntity(node, 'basket-item-close-restore-button'), 5436 'click', 5437 BX.delegate(function() { 5438 this.deleteBasketItem(itemData.ID, false, true); 5439 }, this) 5440 ); 5441 }, 5442 5443 bindItemWarningEvents: function(node, data) 5444 { 5445 if (!node || !data) 5446 return; 5447 5448 BX.bind( 5449 this.getEntity(BX(this.ids.item + data.ID), 'basket-item-warning-close'), 5450 'click', 5451 BX.proxy(this.closeItemWarnings, this) 5452 ); 5453 }, 5454 5455 closeItemWarnings: function() 5456 { 5457 var target = BX.proxy_context; 5458 5459 if (BX.type.isDomNode(target)) 5460 { 5461 var itemData = this.getItemDataByTarget(target); 5462 5463 this.items[itemData.ID].WARNINGS = []; 5464 this.warningItems.splice(BX.util.array_search(itemData.ID, this.warningItems), 1); 5465 5466 this.redrawBasketItemNode(itemData.ID); 5467 this.editWarnings(); 5468 } 5469 }, 5470 5471 renderBasketItem: function(template, data) 5472 { 5473 var clonedData = BX.clone(data); 5474 5475 if (BX.type.isPlainObject(clonedData)) 5476 { 5477 clonedData.USE_FILTER = this.useItemsFilter 5478 && !this.filter.currentFilter.similarHash.length; 5479 } 5480 5481 return Mustache.render(template, clonedData); 5482 }, 5483 5484 render: function(template, data) 5485 { 5486 return Mustache.render(template, data); 5487 }, 5488 5489 checkAnalytics: function(data) 5490 { 5491 if (!data || !data.basket) 5492 return; 5493 5494 var itemId, itemsDiff = {}; 5495 5496 for (var i in data.basket) 5497 { 5498 if (data.basket.hasOwnProperty(i)) 5499 { 5500 if (i.indexOf('QUANTITY_') >= 0) 5501 { 5502 itemId = i.substr(9); 5503 5504 if (this.items[itemId]) 5505 { 5506 itemsDiff[itemId] = parseFloat(data.basket[i]) - parseFloat(BX(this.ids.quantity + itemId).getAttribute('data-value')); 5507 } 5508 } 5509 else if (i.indexOf('DELETE_') >= 0) 5510 { 5511 itemId = i.substr(7); 5512 5513 if (this.items[itemId]) 5514 {
5515 itemsDiff[itemId] = -parseFloat(this.items[itemId].QUANTITY); 5516 } 5517 } 5518 else if (i.indexOf('RESTORE_') >= 0) 5519 { 5520 itemId = i.substr(8); 5521 5522 if (this.items[itemId]) 5523 { 5524 itemsDiff[itemId] = parseFloat(this.items[itemId].QUANTITY); 5525 } 5526 } 5527 } 5528 } 5529 5530 this.setAnalyticsDataLayer(itemsDiff); 5531 }, 5532 5533 setAnalyticsDataLayer: function(itemsDiff) 5534 { 5535 if (!itemsDiff || Object.keys(itemsDiff).length === 0) 5536 return; 5537 5538 window[this.params.DATA_LAYER_NAME] = window[this.params.DATA_LAYER_NAME] || []; 5539 5540 var plus = [], minus = []; 5541 5542 for (var itemId in itemsDiff) 5543 { 5544 if (itemsDiff.hasOwnProperty(itemId)) 5545 { 5546 if (itemsDiff[itemId] > 0) 5547 { 5548 plus.push(this.getItemAnalyticsInfo(itemId, itemsDiff[itemId])); 5549 } 5550 else if (itemsDiff[itemId] < 0) 5551 { 5552 minus.push(this.getItemAnalyticsInfo(itemId, itemsDiff[itemId])); 5553 } 5554 } 5555 } 5556 5557 if (plus.length) 5558 { 5559 window[this.params.DATA_LAYER_NAME].push({ 5560 event: 'addToCart', 5561 ecommerce: { 5562 currencyCode: this.items[itemId].CURRENCY || '', 5563 add: { 5564 products: plus 5565 } 5566 } 5567 }); 5568 } 5569 5570 if (minus.length) 5571 { 5572 window[this.params.DATA_LAYER_NAME].push({ 5573 event: 'removeFromCart', 5574 ecommerce: { 5575 currencyCode: this.items[itemId].CURRENCY || '', 5576 remove: { 5577 products: minus 5578 } 5579 } 5580 }); 5581 } 5582 }, 5583 5584 getItemAnalyticsInfo: function(itemId, diff) 5585 { 5586 if (!this.items[itemId]) 5587 return {}; 5588 5589 var brand = (this.items[itemId].BRAND || '').split(', ').join('/'); 5590 var variants = []; 5591 5592 var selectedSku = this.getEntities(BX(this.ids.item + itemId), 'basket-item-sku-field', '.selected'); 5593 for (var i = 0, l = selectedSku.length; i < l; i++) 5594 { 5595 variants.push(selectedSku[i].getAttribute('data-sku-name')); 5596 } 5597 5598 return { 5599 'name': this.items[itemId].NAME || '', 5600 'id': this.items[itemId].PRODUCT_ID || '', 5601 'price': this.items[itemId].PRICE || 0, 5602 'brand': brand, 5603 'variant': variants.join('/'), 5604 'quantity': Math.abs(diff) 5605 }; 5606 } 5607 }; 5608})(); 5609 5610/* End */ 5611;; /* /local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/script.js?178187500041568*/ 5612; /* /local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/mustache.js?178187500020177*/ 5613; /* /local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/action-pool.js?17818750005918*/ 5614; /* /local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/filter.js?178187500014800*/ 5615; /* /local/templates/sotbit_origami/components/bitrix/sale.basket.basket/mebelson_base_retail/js/component.js?178187500069943*/
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.