1/** 2 * @param basketItemId 3 * @param {{BASKET_ID : string, BASKET_DATA : { GRID : { ROWS : {} }}, COLUMNS: {}, PARAMS: {}, DELETE_ORIGINAL : string }} res 4 */ 5function updateBasketTable(basketItemId, res) 6{ 7 var table = BX("basket_items"), 8 rows, 9 newBasketItemId, 10 arItem, 11 lastRow, 12 newRow, 13 arColumns, 14 bShowDeleteColumn = false, 15 bShowDelayColumn = false, 16 bShowPropsColumn = false, 17 bShowPriceType = false, 18 bUseFloatQuantity, 19 origBasketItem, 20 oCellMargin, 21 i, 22 oCellName, 23 imageURL, 24 cellNameHTML, 25 oCellItem, 26 cellItemHTML, 27 bSkip, 28 j, 29 val, 30 propId, 31 arProp, 32 bIsImageProperty, 33 full, 34 arVal, 35 valId, 36 arSkuValue, 37 selected, 38 valueId, 39 k, 40 arItemProp, 41 oCellQuantity, 42 oCellQuantityHTML, 43 ratio, 44 max, 45 isUpdateQuantity, 46 oldQuantity, 47 oCellPrice, 48 fullPrice, 49 id, 50 oCellDiscount, 51 oCellWeight, 52 oCellCustom, 53 customColumnVal; 54 55 if (!table || typeof res !== 'object') 56 { 57 return; 58 } 59 60 rows = table.rows; 61 lastRow = rows[rows.length - 1]; 62 bUseFloatQuantity = (res.PARAMS.QUANTITY_FLOAT === 'Y'); 63 64 // insert new row instead of original basket item row 65 if (basketItemId !== null && !!res.BASKET_DATA) 66 { 67 newBasketItemId = res.BASKET_ID; 68 arItem = res.BASKET_DATA.GRID.ROWS[newBasketItemId]; 69 arColumns = res.COLUMNS.split(','); 70 newRow = document.createElement('tr'); 71 72 origBasketItem = BX(basketItemId); 73 74 newRow.setAttribute('id', res.BASKET_ID); 75 lastRow.parentNode.insertBefore(newRow, origBasketItem.nextSibling); 76 77 if (res.DELETE_ORIGINAL === 'Y') 78 { 79 origBasketItem.parentNode.removeChild(origBasketItem); 80 } 81 82 // fill row with fields' values 83 oCellMargin = newRow.insertCell(-1); 84 oCellMargin.setAttribute('class', 'margin'); 85 86 for (i = 0; i < arColumns.length; i++) 87 { 88 if (arColumns[i] === 'DELETE') 89 { 90 bShowDeleteColumn = true; 91 } 92 else if (arColumns[i] === 'DELAY') 93 { 94 bShowDelayColumn = true; 95 } 96 else if (arColumns[i] === 'PROPS') 97 { 98 bShowPropsColumn = true; 99 } 100 else if (arColumns[i] === 'TYPE') 101 { 102 bShowPriceType = true; 103 } 104 } 105 106 for (i = 0; i < arColumns.length; i++) 107 { 108 switch (arColumns[i]) 109 { 110 case 'PROPS': 111 case 'DELAY': 112 case 'DELETE': 113 case 'TYPE': 114 break; 115 case 'NAME': 116 // first <td> - image and brand 117 oCellName = newRow.insertCell(-1); 118 imageURL = ''; 119 cellNameHTML = ''; 120 121 oCellName.setAttribute('class', 'itemphoto'); 122 123 if (arItem.PREVIEW_PICTURE_SRC.length > 0) 124 { 125 imageURL = arItem.PREVIEW_PICTURE_SRC; 126 } 127 else if (arItem.DETAIL_PICTURE_SRC.length > 0) 128 { 129 imageURL = arItem.DETAIL_PICTURE_SRC; 130 } 131 else 132 { 133 imageURL = basketJSParams.TEMPLATE_FOLDER + '/images/no_photo.png'; 134 } 135 136 if (arItem.DETAIL_PAGE_URL.length > 0) 137 { 138 cellNameHTML = '<div class="bx_ordercart_photo_container">\ 139 <a href="' + arItem.DETAIL_PAGE_URL + '">\ 140 <div class="bx_ordercart_photo" style="background-image:url(\'' + imageURL + '\')"></div>\ 141 </a>\ 142 </div>'; 143 } 144 else 145 { 146 cellNameHTML = '<div class="bx_ordercart_photo_container">\ 147 <div class="bx_ordercart_photo" style="background-image:url(\'' + imageURL + '\')"></div>\ 148 </div>'; 149 } 150 151 if (arItem.BRAND && arItem.BRAND.length > 0) 152 { 153 cellNameHTML += '<div class="bx_ordercart_brand">\ 154 <img alt="" src="' + arItem.BRAND + '"/>\ 155 </div>'; 156 } 157 158 oCellName.innerHTML = cellNameHTML; 159 160 // second <td> - name, basket props, sku props 161 oCellItem = newRow.insertCell(-1); 162 cellItemHTML = ''; 163 oCellItem.setAttribute('class', 'item'); 164 165 if (arItem['DETAIL_PAGE_URL'].length > 0) 166 cellItemHTML += '<h2 class="bx_ordercart_itemtitle"><a href="' + arItem['DETAIL_PAGE_URL'] + '">' + arItem['NAME'] + '</a></h2>'; 167 else 168 cellItemHTML += '<h2 class="bx_ordercart_itemtitle">' + arItem['NAME'] + '</h2>'; 169 170 cellItemHTML += '<div class="bx_ordercart_itemart">'; 171 172 if (bShowPropsColumn) 173 { 174 for (j = 0; j < arItem['PROPS'].length; j++) 175 { 176 val = arItem['PROPS'][j]; 177 178 if (arItem.SKU_DATA) 179 { 180 bSkip = false;
181 for (propId in arItem.SKU_DATA) 182 { 183 if (arItem.SKU_DATA.hasOwnProperty(propId)) 184 { 185 arProp = arItem.SKU_DATA[propId]; 186 187 if (arProp['CODE'] === val['CODE']) 188 { 189 bSkip = true; 190 break; 191 } 192 } 193 } 194 if (bSkip) 195 continue; 196 } 197 198 cellItemHTML += val['NAME'] + ': <span>' + val['VALUE'] + '</span><br/>'; 199 } 200 } 201 cellItemHTML += '</div>'; 202 203 if (arItem.SKU_DATA) 204 { 205 for (propId in arItem.SKU_DATA) 206 { 207 if (arItem.SKU_DATA.hasOwnProperty(propId)) 208 { 209 arProp = arItem.SKU_DATA[propId]; 210 bIsImageProperty = false; 211 full = (BX.util.array_keys(arProp['VALUES']).length > 5) ? 'full' : ''; 212 213 for (valId in arProp['VALUES']) 214 { 215 arVal = arProp['VALUES'][valId]; 216 if (!!arVal && typeof arVal === 'object' && !!arVal['PICT']) 217 { 218 bIsImageProperty = true; 219 break; 220 } 221 } 222 223 // sku property can contain list of images or values 224 if (bIsImageProperty) 225 { 226 cellItemHTML += '<div class="bx_item_detail_scu_small_noadaptive ' + full + '">'; 227 cellItemHTML += '<span class="bx_item_section_name_gray">' + arProp['NAME'] + '</span>'; 228 cellItemHTML += '<div class="bx_scu_scroller_container">'; 229 cellItemHTML += '<div class="bx_scu">'; 230 231 cellItemHTML += '<ul id="prop_' + arProp['CODE'] + '_' + arItem['ID'] + '" style="width: 200%; margin-left:0%;" class="sku_prop_list">'; 232 233 for (valueId in arProp['VALUES']) 234 { 235 arSkuValue = arProp['VALUES'][valueId]; 236 selected = ''; 237 238 // get current selected item 239 for (k = 0; k < arItem['PROPS'].length; k++) 240 { 241 arItemProp = arItem['PROPS'][k]; 242 243 if (arItemProp['CODE'] === arProp['CODE']) 244 { 245 if (arItemProp['VALUE'] === arSkuValue['NAME'] || arItemProp['VALUE'] === arSkuValue['XML_ID']) 246 selected = 'bx_active'; 247 } 248 } 249 250 cellItemHTML += '<li style="width:10%;"\ 251 class="sku_prop ' + selected + '"\ 252 data-value-id="' + arSkuValue['XML_ID'] + '"\ 253 data-element="' + arItem['ID'] + '"\ 254 data-property="' + arProp['CODE'] + '"\ 255 >\ 256 <a href="javascript:void(0);">\ 257 <span style="background-image:url(' + arSkuValue['PICT']['SRC'] + ')"></span>\ 258 </a>\ 259 </li>'; 260 } 261 262 cellItemHTML += '</ul>'; 263 cellItemHTML += '</div>'; 264 265 cellItemHTML += '<div class="bx_slide_left" onclick="leftScroll(\'' + arProp['CODE'] + '\', ' + arItem['ID'] + ', '+ BX.util.array_keys(arProp['VALUES']).length + ');"></div>'; 266 cellItemHTML += '<div class="bx_slide_right" onclick="rightScroll(\'' + arProp['CODE'] + '\', ' + arItem['ID'] + ', '+ BX.util.array_keys(arProp['VALUES']).length + ');"></div>'; 267 268 cellItemHTML += '</div>'; 269 cellItemHTML += '</div>'; 270 } 271 else // not image 272 { 273 cellItemHTML += '<div class="bx_item_detail_size_small_noadaptive ' + full + '">'; 274 cellItemHTML += '<span class="bx_item_section_name_gray">' + arProp['NAME'] + '</span>'; 275 cellItemHTML += '<div class="bx_size_scroller_container">'; 276 cellItemHTML += '<div class="bx_size">'; 277 278 cellItemHTML += '<ul id="prop_' + arProp['CODE'] + '_' + arItem['ID'] + '" style="width: 200%; margin-left:0%;" class="sku_prop_list">'; 279 280 for (valueId in arProp['VALUES']) 281 { 282 arSkuValue = arProp['VALUES'][valueId]; 283 selected = ''; 284 285 // get current selected item 286 for (k = 0; k < arItem['PROPS'].length; k++) 287 { 288 arItemProp = arItem['PROPS'][k]; 289 290 if (arItemProp['CODE'] === arProp['CODE']) 291 { 292 if (arItemProp['VALUE'] === arSkuValue['NAME']) 293 selected = 'bx_active'; 294 } 295 } 296 297 cellItemHTML += '<li style="width:10%;"\ 298 class="sku_prop ' + selected + '"\ 299 data-value-id="' + arSkuValue['NAME'] + '"\ 300 data-element="' + arItem['ID'] + '"\ 301 data-property="' + arProp['CODE'] + '"\ 302 >\ 303 <a href="javascript:void(0);">' + arSkuValue['NAME'] + '</span></a>\ 304 </li>'; 305 } 306 307 cellItemHTML += '</ul>'; 308 cellItemHTML += '</div>'; 309 310 cellItemHTML += '<div class="bx_slide_left" onclick="leftScroll(\'' + arProp['CODE'] + '\', ' + arItem['ID'] + ', '+ BX.util.array_keys(arProp['VALUES']).length + ');"></div>'; 311 cellItemHTML += '<div class="bx_slide_right" onclick="rightScroll(\'' + arProp['CODE'] + '\', ' + arItem['ID'] + ', '+ BX.util.array_keys(arProp['VALUES']).length + ');"></div>'; 312 313 cellItemHTML += '</div>'; 314 cellItemHTML += '</div>'; 315 } 316 } 317 } 318 } 319 320 oCellItem.innerHTML = cellItemHTML; 321 break; 322 case 'QUANTITY': 323 oCellQuantity = newRow.insertCell(-1); 324 oCellQuantityHTML = ''; 325 ratio = (parseFloat(arItem['MEASURE_RATIO']) > 0) ? arItem['MEASURE_RATIO'] : 1; 326 max = (parseFloat(arItem['AVAILABLE_QUANTITY']) > 0) ? 'max="' + arItem['AVAILABLE_QUANTITY'] + '"' : ''; 327 328 isUpdateQuantity = false;
329 330 if (ratio != 0 && ratio != '') 331 { 332 oldQuantity = arItem['QUANTITY']; 333 arItem['QUANTITY'] = getCorrectRatioQuantity(arItem['QUANTITY'], ratio, bUseFloatQuantity); 334 335 if (oldQuantity != arItem['QUANTITY']) 336 { 337 isUpdateQuantity = true; 338 } 339 } 340 341 oCellQuantity.setAttribute('class', 'custom'); 342 oCellQuantityHTML += '<span>' + getColumnName(res, arColumns[i]) + ':</span>'; 343 344 oCellQuantityHTML += '<div class="centered">'; 345 oCellQuantityHTML += '<table cellspacing="0" cellpadding="0" class="counter">'; 346 oCellQuantityHTML += '<tr>'; 347 oCellQuantityHTML += '<td>'; 348 349 oCellQuantityHTML += '<input type="text" size="3" id="QUANTITY_INPUT_' + arItem['ID'] + '"\ 350 name="QUANTITY_INPUT_' + arItem['ID'] + '"\ 351 size="2" maxlength="18" min="0" ' + max + 'step=' + ratio + '\ 352 style="max-width: 50px"\ 353 value="' + arItem['QUANTITY'] + '"\ 354 onchange="updateQuantity(\'QUANTITY_INPUT_' + arItem['ID'] + '\',\'' + arItem['ID'] + '\', ' + ratio + ',' + bUseFloatQuantity + ')"\ 355 >'; 356 357 oCellQuantityHTML += '</td>'; 358 359 if (ratio != 0 360 && ratio != '' 361 ) // if not Set parent, show quantity control 362 { 363 oCellQuantityHTML += '<td id="basket_quantity_control">\ 364 <div class="basket_quantity_control">\ 365 <a href="javascript:void(0);" class="plus" onclick="setQuantity(' + arItem['ID'] + ', ' + ratio + ', \'up\', ' + bUseFloatQuantity + ');"></a>\ 366 <a href="javascript:void(0);" class="minus" onclick="setQuantity(' + arItem['ID'] + ', ' + ratio + ', \'down\', ' + bUseFloatQuantity + ');"></a>\ 367 </div>\ 368 </td>'; 369 } 370 371 if (arItem.hasOwnProperty('MEASURE_TEXT') && arItem['MEASURE_TEXT'].length > 0) 372 oCellQuantityHTML += '<td style="text-align: left">' + arItem['MEASURE_TEXT'] + '</td>'; 373 374 oCellQuantityHTML += '</tr>'; 375 oCellQuantityHTML += '</table>'; 376 oCellQuantityHTML += '</div>'; 377 378 oCellQuantityHTML += '<input type="hidden" id="QUANTITY_' + arItem['ID'] + '" name="QUANTITY_' + arItem['ID'] + '" value="' + arItem['QUANTITY'] + '" />'; 379 380 oCellQuantity.innerHTML = oCellQuantityHTML; 381 382 if (isUpdateQuantity) 383 { 384 updateQuantity('QUANTITY_INPUT_' + arItem['ID'], arItem['ID'], ratio, bUseFloatQuantity); 385 } 386 break; 387 case 'PRICE': 388 oCellPrice = newRow.insertCell(-1); 389 fullPrice = (arItem['FULL_PRICE_FORMATED'] != arItem['PRICE_FORMATED']) ? arItem['FULL_PRICE_FORMATED'] : ''; 390 391 oCellPrice.setAttribute('class', 'price'); 392 oCellPrice.innerHTML += '<div class="current_price" id="current_price_' + arItem['ID'] + '">' + arItem['PRICE_FORMATED'] + '</div>'; 393 oCellPrice.innerHTML += '<div class="old_price" id="old_price_' + arItem['ID'] + '">' + fullPrice + '</div>'; 394 395 if (bShowPriceType && arItem['NOTES'].length > 0) 396 { 397 oCellPrice.innerHTML += '<div class="type_price">' + basketJSParams['SALE_TYPE'] + '</div>'; 398 oCellPrice.innerHTML += '<div class="type_price_value">' + arItem['NOTES'] + '</div>'; 399 } 400 break; 401 case 'DISCOUNT': 402 oCellDiscount = newRow.insertCell(-1); 403 oCellDiscount.setAttribute('class', 'custom'); 404 oCellDiscount.innerHTML = '<span>' + getColumnName(res, arColumns[i]) + ':</span>'; 405 oCellDiscount.innerHTML += '<div id="discount_value_' + arItem['ID'] + '">' + arItem['DISCOUNT_PRICE_PERCENT_FORMATED'] + '</div>'; 406 break; 407 case 'WEIGHT': 408 oCellWeight = newRow.insertCell(-1); 409 oCellWeight.setAttribute('class', 'custom'); 410 oCellWeight.innerHTML = '<span>' + getColumnName(res, arColumns[i]) + ':</span>'; 411 oCellWeight.innerHTML += arItem['WEIGHT_FORMATED']; 412 break; 413 default: 414 oCellCustom = newRow.insertCell(-1); 415 customColumnVal = ''; 416 417 oCellCustom.setAttribute('class', 'custom'); 418 oCellCustom.innerHTML = '<span>' + getColumnName(res, arColumns[i]) + ':</span>'; 419 420 if (arColumns[i] == 'SUM') 421 customColumnVal += '<div id="sum_' + arItem['ID'] + '">'; 422 423 if (typeof(arItem[arColumns[i]]) != 'undefined' ) 424 { 425 customColumnVal += arItem[arColumns[i]]; 426 } 427 428 if (arColumns[i] == 'SUM') 429 customColumnVal += '</div>'; 430 431 oCellCustom.innerHTML += customColumnVal; 432 break; 433 } 434 } 435 436 if (bShowDeleteColumn || bShowDelayColumn) 437 { 438 var oCellControl = newRow.insertCell(-1); 439 oCellControl.setAttribute('class', 'control'); 440 441 if (bShowDeleteColumn) 442 oCellControl.innerHTML = '<a href="' + basketJSParams['DELET
442E_URL'].replace('#ID#', arItem['ID']) +'">' + basketJSParams['SALE_DELETE'] + '</a><br />'; 443 444 if (bShowDelayColumn) 445 oCellControl.innerHTML += '<a href="' + basketJSParams['DELAY_URL'].replace('#ID#', arItem['ID']) + '">' + basketJSParams['SALE_DELAY'] + '</a>'; 446 } 447 448 var oCellMargin2 = newRow.insertCell(-1); 449 oCellMargin2.setAttribute('class', 'margin'); 450 451 // set sku props click handler 452 var sku_props = BX.findChildren(BX(newBasketItemId), {tagName: 'li', className: 'sku_prop'}, true); 453 if (!!sku_props && sku_props.length > 0) 454 { 455 for (i = 0; sku_props.length > i; i++) 456 { 457 BX.bind(sku_props[i], 'click', BX.delegate(function(e){ skuPropClickHandler(e);}, this)); 458 } 459 } 460 } 461 462 // update product params after recalculation 463 if (!!res.BASKET_DATA) 464 { 465 for (id in res.BASKET_DATA.GRID.ROWS) 466 { 467 if (res.BASKET_DATA.GRID.ROWS.hasOwnProperty(id)) 468 { 469 var item = res.BASKET_DATA.GRID.ROWS[id]; 470 471 if (BX('discount_value_' + id)) 472 BX('discount_value_' + id).innerHTML = item.DISCOUNT_PRICE_PERCENT_FORMATED; 473 474 if (BX('current_price_' + id)) 475 BX('current_price_' + id).innerHTML = item.PRICE_FORMATED; 476 477 if (BX('old_price_' + id)) 478 BX('old_price_' + id).innerHTML = (item.FULL_PRICE_FORMATED != item.PRICE_FORMATED) ? item.FULL_PRICE_FORMATED : ''; 479 480 if (BX('sum_' + id)) 481 BX('sum_' + id).innerHTML = item.SUM; 482 483 // if the quantity was set by user to 0 or was too much, we need to show corrected quantity value from ajax response 484 if (BX('QUANTITY_' + id)) 485 { 486 BX('QUANTITY_INPUT_' + id).value = item.QUANTITY; 487 BX('QUANTITY_INPUT_' + id).defaultValue = item.QUANTITY; 488 489 BX('QUANTITY_' + id).value = item.QUANTITY; 490 } 491 } 492 } 493 } 494 495 // update coupon info 496 if (!!res.BASKET_DATA) 497 couponListUpdate(res.BASKET_DATA); 498 499 // update warnings if any 500 if (res.hasOwnProperty('WARNING_MESSAGE')) 501 { 502 var warningText = ''; 503 504 for (i = res['WARNING_MESSAGE'].length - 1; i >= 0; i--) 505 warningText += res['WARNING_MESSAGE'][i] + '<br/>'; 506 507 BX('warning_message').innerHTML = warningText; 508 } 509 510 // update total basket values 511 if (!!res.BASKET_DATA) 512 { 513 if (BX('allWeight_FORMATED')) 514 BX('allWeight_FORMATED').innerHTML = res['BASKET_DATA']['allWeight_FORMATED'].replace(/\s/g, ' '); 515 516 if (BX('allSum_wVAT_FORMATED')) 517 BX('allSum_wVAT_FORMATED').innerHTML = res['BASKET_DATA']['allSum_wVAT_FORMATED'].replace(/\s/g, ' '); 518 519 if (BX('allVATSum_FORMATED')) 520 BX('allVATSum_FORMATED').innerHTML = res['BASKET_DATA']['allVATSum_FORMATED'].replace(/\s/g, ' '); 521 522 if (BX('allSum_FORMATED')) 523 BX('allSum_FORMATED').innerHTML = res['BASKET_DATA']['allSum_FORMATED'].replace(/\s/g, ' '); 524 525 if (BX('PRICE_WITHOUT_DISCOUNT')) 526 BX('PRICE_WITHOUT_DISCOUNT').innerHTML = (res['BASKET_DATA']['PRICE_WITHOUT_DISCOUNT'] != res['BASKET_DATA']['allSum_FORMATED']) ? res['BASKET_DATA']['PRICE_WITHOUT_DISCOUNT'].replace(/\s/g, ' ') : ''; 527 528 BX.onCustomEvent('OnBasketChange'); 529 } 530} 531/** 532 * @param couponBlock 533 * @param {COUPON: string, JS_STATUS: string} oneCoupon - new coupon. 534 */ 535function couponCreate(couponBlock, oneCoupon) 536{ 537 var couponClass = 'disabled'; 538 539 if (!BX.type.isElementNode(couponBlock)) 540 return; 541 if (oneCoupon.JS_STATUS === 'BAD') 542 couponClass = 'bad'; 543 else if (oneCoupon.JS_STATUS === 'APPLYED') 544 couponClass = 'good'; 545 546 couponBlock.appendChild(BX.create( 547 'div', 548 { 549 props: { 550 className: 'bx_ordercart_coupon' 551 }, 552 children: [ 553 BX.create( 554 'input', 555 { 556 props: { 557 className: couponClass, 558 type: 'text', 559 value: oneCoupon.COUPON, 560 name: 'OLD_COUPON[]' 561 }, 562 attrs: { 563 disabled: true, 564 readonly: true 565 } 566 } 567 ), 568 BX.create( 569 'span', 570 { 571 props: { 572 className: couponClass 573 }, 574 attrs: { 575 'data-coupon': oneCoupon.COUPON 576 } 577 } 578 ), 579 BX.create( 580 'div', 581 { 582 props: { 583 className: 'bx_ordercart_coupon_notes' 584 }, 585 html: oneCoupon.JS_CHECK_CODE 586 } 587 ) 588 ] 589 } 590 )); 591} 592 593/** 594 * @param {COUPON_LIST : []} res 595 */ 596function couponListUpdate(res) 597{ 598 var couponBlock,
599 couponClass, 600 fieldCoupon, 601 couponsCollection, 602 couponFound, 603 i, 604 j, 605 key; 606 607 if (!!res && typeof res !== 'object') 608 { 609 return; 610 } 611 612 couponBlock = BX('coupons_block'); 613 if (!!couponBlock) 614 { 615 if (!!res.COUPON_LIST && BX.type.isArray(res.COUPON_LIST)) 616 { 617 fieldCoupon = BX('coupon'); 618 if (!!fieldCoupon) 619 { 620 fieldCoupon.value = ''; 621 } 622 couponsCollection = BX.findChildren(couponBlock, { tagName: 'input', property: { name: 'OLD_COUPON[]' } }, true); 623 624 if (!!couponsCollection) 625 { 626 if (BX.type.isElementNode(couponsCollection)) 627 { 628 couponsCollection = [couponsCollection]; 629 } 630 for (i = 0; i < res.COUPON_LIST.length; i++) 631 { 632 couponFound = false; 633 key = -1; 634 for (j = 0; j < couponsCollection.length; j++) 635 { 636 if (couponsCollection[j].value === res.COUPON_LIST[i].COUPON) 637 { 638 couponFound = true; 639 key = j; 640 couponsCollection[j].couponUpdate = true; 641 break; 642 } 643 } 644 if (couponFound) 645 { 646 couponClass = 'disabled'; 647 if (res.COUPON_LIST[i].JS_STATUS === 'BAD') 648 couponClass = 'bad'; 649 else if (res.COUPON_LIST[i].JS_STATUS === 'APPLYED') 650 couponClass = 'good'; 651 652 BX.adjust(couponsCollection[key], {props: {className: couponClass}}); 653 BX.adjust(couponsCollection[key].nextSibling, {props: {className: couponClass}}); 654 BX.adjust(couponsCollection[key].nextSibling.nextSibling, {html: res.COUPON_LIST[i].JS_CHECK_CODE}); 655 } 656 else 657 { 658 couponCreate(couponBlock, res.COUPON_LIST[i]); 659 } 660 } 661 for (j = 0; j < couponsCollection.length; j++) 662 { 663 if (typeof (couponsCollection[j].couponUpdate) === 'undefined' || !couponsCollection[j].couponUpdate) 664 { 665 BX.remove(couponsCollection[j].parentNode); 666 couponsCollection[j] = null; 667 } 668 else 669 { 670 couponsCollection[j].couponUpdate = null; 671 } 672 } 673 } 674 else 675 { 676 for (i = 0; i < res.COUPON_LIST.length; i++) 677 { 678 couponCreate(couponBlock, res.COUPON_LIST[i]); 679 } 680 } 681 } 682 } 683 couponBlock = null; 684} 685 686function skuPropClickHandler(e) 687{ 688 if (!e) 689 { 690 e = window.event; 691 } 692 var target = BX.proxy_context, 693 basketItemId, 694 property, 695 property_values = {}, 696 postData = {}, 697 action_var, 698 all_sku_props, 699 i, 700 sku_prop_value, 701 m; 702 703 if (!!target && target.hasAttribute('data-value-id')) 704 { 705 BX.showWait(); 706 707 basketItemId = target.getAttribute('data-element'); 708 property = target.getAttribute('data-property'); 709 action_var = BX('action_var').value; 710 711 property_values[property] = target.getAttribute('data-value-id'); 712 713 // if already selected element is clicked 714 if (BX.hasClass(target, 'bx_active')) 715 { 716 BX.closeWait(); 717 return; 718 } 719 720 // get other basket item props to get full unique set of props of the new product 721 all_sku_props = BX.findChildren(BX(basketItemId), {tagName: 'ul', className: 'sku_prop_list'}, true); 722 if (!!all_sku_props && all_sku_props.length > 0) 723 { 724 for (i = 0; all_sku_props.length > i; i++) 725 { 726 if (all_sku_props[i].id !== 'prop_' + property + '_' + basketItemId) 727 { 728 sku_prop_value = BX.findChildren(BX(all_sku_props[i].id), {tagName: 'li', className: 'bx_active'}, true); 729 if (!!sku_prop_value && sku_prop_value.length > 0) 730 { 731 for (m = 0; sku_prop_value.length > m; m++) 732 { 733 if (sku_prop_value[m].hasAttribute('data-value-id')) 734 { 735 property_values[sku_prop_value[m].getAttribute('data-property')] = sku_prop_value[m].getAttribute('data-value-id'); 736 } 737 } 738 } 739 } 740 } 741 } 742 743 postData = { 744 'basketItemId': basketItemId, 745 'sessid': BX.bitrix_sessid(), 746 'site_id': BX.message('SITE_ID'), 747 'props': property_values, 748 'action_var': action_var, 749 'select_props': BX('column_headers').value, 750 'offers_props': BX('offers_props').value, 751 'quantity_float': BX('quantity_float').value, 752 'count_discount_4_all_quantity': BX('count_discount_4_all_quantity').value, 753 'price_vat_show_value': BX('price_vat_show_value').value, 754 'hide_coupon': BX('hide_coupon').value, 755 'use_prepayment': BX('use_prepayment').value 756 }; 757 758 postData[action_var] = 'select_item'; 759 760 BX.ajax({ 761 url: '/bitrix/components/bitrix/sale.basket.basket/ajax.php', 762 method: 'POST', 763 data: postData, 764 dataType: 'json', 765 onsuccess: function(result) 766 { 767 BX.closeWait(); 768 updateBasketTable(basketItemId, result); 769 } 770 }); 771 } 772} 773 774function getColumnName(result, columnCode) 775{ 776 if (BX('col_' + columnCode)) 777 { 778 return BX.util.trim(BX('col_' + columnCode).innerHTML); 779 } 780 else 781 { 782 return ''; 783 } 784} 785 786function leftScroll(prop, id, count) 787{ 788 count = parseInt(count, 10); 789 var el = BX('prop_' + prop + '_' + id); 790 791 if (el) 792 { 793 var curVal = parseInt(el.style.marginLeft, 10); 794 if (curVal <= (6 - count)*20) 795 el.style.marginLeft = curVal + 20 + '%'; 796 } 797} 798 799function rightScroll(prop, id, count) 800{ 801 count = parseInt(count, 10); 802 var el = BX('prop_' + prop + '_' + id); 803 804 if (el) 805 { 806 var curVal = parseInt(el.style.marginLeft, 10); 807 if (curVal > (5 - count)*20) 808 el.style.marginLeft = curVal - 20 + '%'; 809 } 810} 811 812function checkOut() 813{ 814 if (!!BX('coupon')) 815 BX('coupon').disabled = true; 816 BX("basket_form").submit(); 817 return true; 818} 819 820function enterCoupon() 821{ 822 var newCoupon = BX('coupon'); 823 if (!!newCoupon && !!newCoupon.value) 824 recalcBasketAjax({'coupon' : newCoupon.value}); 825} 826 827// check if quantity is valid 828// and update values of both controls (text input field for PC and mobile quantity select) simultaneously 829function updateQuantity(controlId, basketId, ratio, bUseFloatQuantity) 830{ 831 var oldVal = BX(controlId).defaultValue, 832 newVal = parseFloat(BX(controlId).value) || 0, 833 bIsCorrectQuantityForRatio = false;
834 835 if (ratio === 0 || ratio == 1) 836 { 837 bIsCorrectQuantityForRatio = true; 838 } 839 else 840 { 841 842 var newValInt = newVal * 10000, 843 ratioInt = ratio * 10000, 844 reminder = newValInt % ratioInt, 845 newValRound = parseInt(newVal); 846 847 if (reminder === 0) 848 { 849 bIsCorrectQuantityForRatio = true; 850 } 851 } 852 853 var bIsQuantityFloat = false; 854 855 if (parseInt(newVal) != parseFloat(newVal)) 856 { 857 bIsQuantityFloat = true; 858 } 859 860 newVal = (bUseFloatQuantity === false && bIsQuantityFloat === false) ? parseInt(newVal) : parseFloat(newVal).toFixed(2); 861 862 if (bIsCorrectQuantityForRatio) 863 { 864 BX(controlId).defaultValue = newVal; 865 866 BX("QUANTITY_INPUT_" + basketId).value = newVal; 867 868 // set hidden real quantity value (will be used in actual calculation) 869 BX("QUANTITY_" + basketId).value = newVal; 870 871 recalcBasketAjax({}); 872 } 873 else 874 { 875 newVal = getCorrectRatioQuantity(newVal, ratio, bUseFloatQuantity); 876 877 if (newVal != oldVal) 878 { 879 BX("QUANTITY_INPUT_" + basketId).value = newVal; 880 BX("QUANTITY_" + basketId).value = newVal; 881 recalcBasketAjax({}); 882 }else 883 { 884 BX(controlId).value = oldVal; 885 } 886 } 887} 888 889// used when quantity is changed by clicking on arrows 890function setQuantity(basketId, ratio, sign, bUseFloatQuantity) 891{ 892 var curVal = parseFloat(BX("QUANTITY_INPUT_" + basketId).value), 893 newVal; 894 895 newVal = (sign == 'up') ? curVal + ratio : curVal - ratio; 896 897 if (newVal < 0) 898 newVal = 0; 899 900 if (bUseFloatQuantity) 901 { 902 newVal = newVal.toFixed(2); 903 } 904 905 if (ratio > 0 && newVal < ratio) 906 { 907 newVal = ratio; 908 } 909 910 if (!bUseFloatQuantity && newVal != newVal.toFixed(2)) 911 { 912 newVal = newVal.toFixed(2); 913 } 914 915 newVal = getCorrectRatioQuantity(newVal, ratio, bUseFloatQuantity); 916 917 BX("QUANTITY_INPUT_" + basketId).value = newVal; 918 BX("QUANTITY_INPUT_" + basketId).defaultValue = newVal; 919 920 updateQuantity('QUANTITY_INPUT_' + basketId, basketId, ratio, bUseFloatQuantity); 921} 922 923function getCorrectRatioQuantity(quantity, ratio, bUseFloatQuantity) 924{ 925 var newValInt = quantity * 10000, 926 ratioInt = ratio * 10000, 927 reminder = newValInt % ratioInt, 928 result = quantity, 929 bIsQuantityFloat = false, 930 i; 931 ratio = parseFloat(ratio); 932 933 if (reminder === 0) 934 { 935 return result; 936 } 937 938 if (ratio !== 0 && ratio != 1) 939 { 940 for (i = ratio, max = parseFloat(quantity) + parseFloat(ratio); i <= max; i = parseFloat(parseFloat(i) + parseFloat(ratio)).toFixed(2)) 941 { 942 result = i; 943 } 944 945 }else if (ratio === 1) 946 { 947 result = quantity | 0; 948 } 949 950 if (parseInt(result, 10) != parseFloat(result)) 951 { 952 bIsQuantityFloat = true; 953 } 954 955 result = (bUseFloatQuantity === false && bIsQuantityFloat === false) ? parseInt(result, 10) : parseFloat(result).toFixed(2); 956 957 return result; 958} 959/** 960 * 961 * @param {} params 962 */ 963function recalcBasketAjax(params) 964{ 965 BX.showWait(); 966 967 var property_values = {}, 968 action_var = BX('action_var').value, 969 items = BX('basket_items'), 970 delayedItems = BX('delayed_items'), 971 postData, 972 i; 973 974 postData = { 975 'sessid': BX.bitrix_sessid(), 976 'site_id': BX.message('SITE_ID'), 977 'props': property_values, 978 'action_var': action_var, 979 'select_props': BX('column_headers').value, 980 'offers_props': BX('offers_props').value, 981 'quantity_float': BX('quantity_float').value, 982 'count_discount_4_all_quantity': BX('count_discount_4_all_quantity').value, 983 'price_vat_show_value': BX('price_vat_show_value').value, 984 'hide_coupon': BX('hide_coupon').value, 985 'use_prepayment': BX('use_prepayment').value 986 }; 987 postData[action_var] = 'recalculate'; 988 if (!!params && typeof params === 'object') 989 { 990 for (i in params) 991 { 992 if (params.hasOwnProperty(i)) 993 postData[i] = params[i]; 994 } 995 } 996 997 if (!!items && items.rows.length > 0) 998 { 999 for (i = 1; items.rows.length > i; i++) 1000 postData['QUANTITY_' + items.rows[i].id] = BX('QUANTITY_' + items.rows[i].id).value; 1001 } 1002 1003 if (!!delayedItems && delayedItems.rows.length > 0) 1004 { 1005 for (i = 1; delayedItems.rows.length > i; i++) 1006 postData['DELAY_' + delayedItems.rows[i].id] = 'Y'; 1007 } 1008 1009 BX.ajax({ 1010 url: '/bitrix/components/bitrix/sale.basket.basket/ajax.php', 1011 method: 'POST', 1012 data: postData, 1013 dataType: 'json', 1014 onsuccess: function(result) 1015 { 1016 BX.closeWait(); 1017 updateBasketTable(null, result); 1018 } 1019 }); 1020} 1021 1022function showBasketItemsList(val) 1023{ 1024 BX.removeClass(BX("basket_toolbar_button"), "current"); 1025 BX.removeClass(BX("basket_toolbar_button_delayed"), "current"); 1026 BX.removeClass(BX("basket_toolbar_button_subscribed"), "current"); 1027 BX.removeClass(BX("basket_toolbar_button_not_available"), "current"); 1028 1029 BX("normal_count").style.display = 'inline-block'; 1030 BX("delay_count").style.display = 'inline-block'; 1031 BX("subscribe_count").style.display = 'inline-block'; 1032 BX("not_available_count").style.display = 'inline-block'; 1033 1034 if (val == 2) 1035 { 1036 if (BX("basket_items_list")) 1037 BX("basket_items_list").style.display = 'none'; 1038 if (BX("basket_items_delayed")) 1039 { 1040 BX("basket_items_delayed").style.display = 'block'; 1041 BX.addClass(BX("basket_toolbar_button_delayed"), "current"); 1042 BX("delay_count").style.display = 'none'; 1043 } 1044 if (BX("basket_items_subscribed")) 1045 BX("basket_items_subscribed").style.display = 'none'; 1046 if (BX("basket_items_not_available")) 1047 BX("basket_items_not_available").style.display = 'none'; 1048 } 1049 else if(val == 3) 1050 { 1051 if (BX("basket_items_list")) 1052 BX("basket_items_list").style.display = 'none'; 1053 if (BX("basket_items_delayed")) 1054 BX("basket_items_delayed").style.display = 'none'; 1055 if (BX("basket_items_subscribed")) 1056 { 1057 BX("basket_items_subscribed").style.display = 'block'; 1058 BX.addClass(BX("basket_toolbar_button_subscribed"), "current"); 1059 BX("subscribe_count").style.display = 'none'; 1060 } 1061 if (BX("basket_items_not_available")) 1062 BX("basket_items_not_available").style.display = 'none'; 1063 } 1064 else if (val == 4) 1065 { 1066 if (BX("basket_items_list")) 1067 BX("basket_items_list").style.display = 'none'; 1068 if (BX("basket_items_delayed")) 1069 BX("basket_items_delayed").style.display = 'none'; 1070 if (BX("basket_items_subscribed")) 1071 BX("basket_items_subscribed").style.display = 'none'; 1072 if (BX("basket_items_not_available")) 1073 { 1074 BX("basket_items_not_available").style.display = 'block'; 1075 BX.addClass(BX("basket_toolbar_button_not_available"), "current"); 1076 BX("not_available_count").style.display = 'none'; 1077 } 1078 } 1079 else 1080 { 1081 if (BX("basket_items_list")) 1082 { 1083 BX("basket_items_list").style.display = 'block'; 1084 BX.addClass(BX("basket_toolbar_button"), "current"); 1085 BX("normal_count").style.display = 'none'; 1086 } 1087 if (BX("basket_items_delayed")) 1088 BX("basket_items_delayed").style.display = 'none'; 1089 if (BX("basket_items_subscribed")) 1090 BX("basket_items_subscribed").style.display = 'none'; 1091 if (BX("basket_items_not_available")) 1092 BX("basket_items_not_available").style.display = 'none'; 1093 } 1094} 1095 1096function deleteCoupon(e) 1097{ 1098 var target = BX.proxy_context, 1099 value; 1100 1101 if (!!target && target.hasAttribute('data-coupon')) 1102 { 1103 value = target.getAttribute('data-coupon'); 1104 if (!!value && value.length > 0) 1105 { 1106 recalcBasketAjax({'delete_coupon' : value}); 1107 } 1108 } 1109} 1110 1111BX.ready(function() { 1112 var sku_props = BX.findChildren(BX('basket_items'), {tagName: 'li', className: 'sku_prop'}, true), 1113 i, 1114 couponBlock; 1115 if (!!sku_props && sku_props.length > 0) 1116 { 1117 for (i = 0; sku_props.length > i; i++) 1118 { 1119 BX.bind(sku_props[i], 'click', BX.delegate(function(e){ skuPropClickHandler(e);}, this)); 1120 } 1121 } 1122 couponBlock = BX('coupons_block'); 1123 if (!!couponBlock) 1124 BX.bindDelegate(couponBlock, 'click', { 'attribute': 'data-coupon' }, BX.delegate(function(e){deleteCoupon(e); }, this)); 1125});
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.