1; 2(function(BX, document, window) { 3 'use strict'; 4 5 if (!window.RS) { 6 window.RS = {}; 7 } 8 9 if (!!window.RS.Basket || !BX) { 10 return; 11 } 12 13 function Basket() { 14 this.ajaxUrl = '/bitrix/components/bitrix/sale.basket.basket/ajax.php'; 15 this.inBasketProducts = []; 16 } 17 18 Basket.prototype.inbasket = function(ids, isRewrite) { 19 20 isRewrite = isRewrite || false; 21 22 if (ids) 23 { 24 ids = $.isArray(ids) ? ids : [ids]; 25 26 ids = ids.map(function(val) { 27 return parseInt(val, 10); 28 }); 29 30 if (isRewrite) { 31 this.inBasketProducts = ids; 32 } else { 33 this.inBasketProducts = BX.util.array_merge(this.inBasketProducts, ids); 34 } 35 } 36 37 return this.inBasketProducts; 38 }; 39 40 Basket.prototype.frombasket = function (removeId) { 41 this.inBasketProducts.forEach(function (id, index) { 42 if (id == removeId) { 43 this.inBasketProducts = BX.util.deleteFromArray(this.inBasketProducts, index); 44 } 45 }.bind(this)); 46 } 47 48 Basket.prototype.add = function(productId, quantity) { 49 var params = {}; 50 51 params.action = 'add2basket'; 52 params.product_id = productId; 53 params.sessid = BX.bitrix_sessid();
54 55 if (quantity) { 56 params.quantity = quantity; 57 } 58 59 return BX.ajax.post(this.ajaxUrl, params, function(result) { 60 result = BX.parseJSON(result); 61 if (result) { 62 this.inbasket(productId, false); 63 BX.onCustomEvent('OnBasketChange'); 64 } 65 }.bind(this)); 66 67 return url; 68 }; 69 70 Basket.prototype.updateQuantity = function(itemId, newQuantity) { 71 var params = { 72 'action': 'recalculate', 73 'sessid': BX.bitrix_sessid(), 74 'site_id': BX.message('SITE_ID'), 75 'props': {}, 76 'action_var': 'action', 77 'select_props': 'QUANTITY', 78 'offers_props': '', 79 'quantity_float': 'N', 80 'count_discount_4_all_quantity': 'Y', 81 'price_vat_show_value': 'Y', 82 'hideCoupon': 'Y', 83 'use_prepayment': 'N' 84 }; 85 86 params['QUANTITY_' + itemId] = newQuantity; 87 88 89 return BX.ajax.post(this.ajaxUrl, params, function(result) { 90 result = BX.parseJSON(result); 91 92 if(result) { 93 BX.onCustomEvent('OnBasketChange', [result.BASKET_DATA]); 94 } 95 }); 96 }; 97 98 Basket.prototype.delete = function(itemId, productId) { 99 var params = { 100 'action': 'recalculate', 101 'sessid': BX.bitrix_sessid(), 102 'site_id': BX.message('SITE_ID'), 103 'props': {}, 104 'action_var': 'action', 105 'select_props': 'DELETE', 106 'offers_props': '', 107 'quantity_float': 'N', 108 'count_discount_4_all_quantity': 'Y', 109 'price_vat_show_value': 'Y', 110 'hideCoupon': 'Y', 111 'use_prepayment': 'N' 112 }; 113
114 params['DELETE_' + itemId] = 'Y'; 115 116 return BX.ajax.post(this.ajaxUrl, params, function(result) { 117 result = BX.parseJSON(result); 118 119 if(result) { 120 this.frombasket(productId); 121 BX.onCustomEvent('OnBasketChange', [result.BASKET_DATA]); 122 } 123 }.bind(this)); 124 }; 125 126 127 Basket.prototype.clear = function(ids) { 128 129 var promise = new BX.Promise(); 130 131 var params = { 132 'action': 'recalculate', 133 'sessid': BX.bitrix_sessid(), 134 'site_id': BX.message('SITE_ID'), 135 'props': {}, 136 'action_var': 'action', 137 'select_props': 'DELETE', 138 'offers_props': '', 139 'quantity_float': 'N', 140 'count_discount_4_all_quantity': 'Y', 141 'price_vat_show_value': 'Y', 142 'hideCoupon': 'Y', 143 'use_prepayment': 'N' 144 }; 145 146 147 ids.forEach(function (itemId) { 148 params['DELETE_' + itemId] = 'Y'; 149 }); 150 151 BX.ajax.post(this.ajaxUrl, params, function(result) { 152 result = BX.parseJSON(result); 153 154 if(result) { 155 this.inbasket([], true); 156 BX.onCustomEvent('OnBasketChange', [result.BASKET_DATA]); 157 promise.resolve(); 158 } 159 }.bind(this)); 160 161 return promise; 162 } 163 164 window.Basket = new Basket; 165 166}(BX, document, window));
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.