1$(document).ready(function () { 2 const $btnQuantityProduct = $(this).find(".btn-quantity-product"); 3 const $productInCartModal = $("#product-in-cart-modal"); 4 5 const minQuantity = 0, maxQuantity = 999; 6 const faSpinner = 'fa-spinner fa-spin'; 7 8 $(document).on("click", ".btn-quantity-product .btn-change-quantity", function (e) { 9 e.preventDefault(); 10 11 const $btnChangeQuantity = $(this); 12 const $parentQuantityProduct = $btnChangeQuantity.parents(".btn-quantity-product"); 13 const typeChange = $btnChangeQuantity.attr('data-type-change'); 14 const typeItem = $parentQuantityProduct.attr('data-type-item'); 15 const $input = $parentQuantityProduct.find("input.quantity-product-value"); 16 const currentVal = parseInt($input.val()); 17 18 if (isNaN(currentVal)) { 19 $input.val(0); 20 return fasle; 21 } 22 23 if (typeChange == 'minus') { 24 const variantId = $parentQuantityProduct.attr('data-variantid'); 25 const countItemInCart = $parentQuantityProduct.attr('data-count-item-in-cart'); 26 27 if (!variantId || variantId == '' || +countItemInCart > 1) { 28 const docId = $parentQuantityProduct.attr('data-docid'); 29 const productID = $parentQuantityProduct.attr('data-productid'); 30 reloadContentProductInCartModal(docId, productID, typeItem); 31 32 $btnChangeQuantity.find('i.fa').addClass(faSpinner); 33 34 setTimeout(function () { 35 $btnChangeQuantity.find('i.fa').removeClass(faSpinner); 36 $(`.box-add-product-${productID}`).find(".btn-change-quantity").css("pointer-events", "initial"); 37 }, 6000); 38 39 return false; 40 } 41 42 if (currentVal > minQuantity) { 43 $input.val(currentVal - 1); 44 } 45 else { 46 $input.val(minQuantity); 47 } 48 49 if (parseInt($input.val()) == minQuantity) { 50 $btnChangeQuantity.css("pointer-events", "none"); 51 } 52 53 const $btnChangeQuantityRef = $btnChangeQuantity; 54 55 delayTimer(function () { 56 $input.change(); 57 $btnChangeQuantityRef.css("pointer-events", "none").find('i.fa').addClass(faSpinner); 58 }, 400); 59 } 60 else if (typeChange == 'plus') { 61 const showProductDetail = $btnChangeQuantity.attr('data-show-product-detail'); 62 const docId = $parentQuantityProduct.attr('data-docid'); 63 const productID = $parentQuantityProduct.attr('data-productid'); 64 //console.log(productID); 65 if (showProductDetail && showProductDetail == "true") { 66 if (typeItem == '1' || typeItem == 1) { 67 showEVoucherDetailDiaLog(docId, productID); 68 } 69 else { 70 showProductDetailDiaLog(docId, productID); 71 } 72 73 $btnChangeQuantity.find('i.fa').addClass(faSpinner); 74 75 setTimeout(function () { 76 $btnChangeQuantity.find('i.fa').removeClass(faSpinner); 77 }, 6000); 78 79 return false; 80 } 81 82 const isInCartOnlyCurrentItem = $parentQuantityProduct.attr('data-only-current-item'); 83 84 if (isInCartOnlyCurrentItem && isInCartOnlyCurrentItem == "true") { 85 if (typeItem == '1' || typeItem == 1) { 86 AddEVoucherToCart(docId, productID); 87 } 88 else { 89 AddProductToCart(docId, productID); 90 } 91 92 $btnChangeQuantity.find('i.fa').addClass(faSpinner); 93 94 setTimeout(function () { 95 $btnChangeQuantity.find('i.fa').removeClass(faSpinner); 96 }, 6000); 97 98 return false; 99 } 100 let maxValue = $input.attr('max'); 101 if (maxValue <= 0) { 102 maxValue = maxQuantity; 103 } 104 var setValueMax = true; 105 const quantityPerPaxAttr = $(`.box-add-product-${productID}`) 106 .find(".btn-quantity-product") 107 .attr("data-quantity-per-pax"); 108 109 if (quantityPerPaxAttr) { // tá»± Äá»ng loại bá» undefined, null, '' 110 const parsed = parseInt(quantityPerPaxAttr, 10); 111 //console.log('quantityPerPaxAttr', parsed);
112 if (!isNaN(parsed) && parsed && parsed > 0 && allowOverLimit) { // Äảm bảo convert ra sá» hợp lá» 113 //console.log('quantityPerPax', parsed, 'quantity', quantity); 114 setValueMax = false; 115 } 116 } 117 if (currentVal < maxValue || !setValueMax) { 118 $input.val(currentVal + 1); 119 } 120 else { 121 $input.val(maxValue); 122 } 123 124 if (parseInt($input.val()) == maxValue && !setValueMax) { 125 $btnChangeQuantity.css("pointer-events", "none"); 126 } 127 128 const $btnChangeQuantityRef = $btnChangeQuantity; 129 130 delayTimer(function () { 131 $input.change(); 132 $btnChangeQuantityRef.css("pointer-events", "none").find('i.fa').addClass(faSpinner); 133 }, 400); 134 } 135 }); 136 137 $(document).on("change", ".btn-quantity-product .quantity-product-value", function (e) { 138 e.preventDefault(); 139 const textCheckOut = $('#textCheckOut').text(); 140 141 const $showProductInCartModal = $("#product-in-cart-modal"); 142 const $that = $(this); 143 const qty = $that.val(); 144 145 const variantId = $that.parent().attr('data-variantid'); 146 const id = $that.parent().attr('data-docid'); 147 const productId = $that.parent().attr('data-productid'); 148 const isTrackQuantity = $that.parent().attr('data-is-track-quantity'); 149 const typeItem = $that.parent().attr('data-type-item'); 150 const promotionId = ''; 151 152 if (qty == 0) { 153 removeVariant(variantId, id, productId, productId, isTrackQuantity, promotionId, qty); 154 155 return false; 156 } 157 else { 158 if (isChanged === true) { 159 return; 160 } 161 162 isChanged = true; 163 164 var formdata = { 165 variantId: variantId, 166 qty: qty, 167 authorization: siteId 168 } 169 170 $('#btnCheckOut').prop('disabled', true); 171 $.ajax({
172 type: "POST", 173 url: urlChangeQuantityVersion3, 174 data: formdata, 175 success: function (result) { 176 $(`.box-add-product-${productId}`).find(".btn-change-quantity").css("pointer-events", "initial").find('i.fa').removeClass(faSpinner); 177 178 //Re-build the new content of cart 179 $('#containmycart').html(result); 180 181 const isPopupShowed = $showProductInCartModal.hasClass('in'); 182 if (isPopupShowed) { 183 reloadContentProductInCartModal(id, productId, typeItem); 184 } 185 186 //Re-set up the height of cart 187 ResetCartHeight(); 188 189 isShowAnimate = true; 190 ShowAnimate(id, productId, true); 191 192 if (orderType == 0) { // Delivery 193 mobileProgressBarDilivery(); 194 } 195 196 //Display warning if product/modifier is out-of-stock 197 if (isTrackQuantity == "True") { 198 checkProductOutOfStock(id, productId); 199 } 200 201 //Update the count number of items in cart 202 updateCartCount(); 203 204 const quantityPerPaxAttr = $(`.box-add-product-${productId}`) 205 .find(".btn-quantity-product") 206 .attr("data-quantity-per-pax"); 207 208 if (quantityPerPaxAttr) { // tá»± Äá»ng loại bá» undefined, null, '' 209 const parsed = parseInt(quantityPerPaxAttr, 10); 210 console.log('quantityPerPaxAttr', parsed); 211 const quantity = parseInt(qty, 10); 212 if (!isNaN(parsed) && !isNaN(quantity) && parsed && parsed > 0) { // Äảm bảo convert ra sá» hợp lá» 213 console.log('quantityPerPax', parsed, 'quantity', quantity); 214 if (parsed <= quantity) { 215 if (!allowOverLimit) { 216 $(`.box-add-product-${productId}`).find(".btn-quantity-product").find('button[data-type-change="plus"]').attr("disabled", "disabled"); 217 } 218 } 219 else { 220 $(`.box-add-product-${productId}`).find(".btn-quantity-product").find('button[data-type-change="plus"]').removeAttr("disabled"); 221 } 222 } 223 } 224 }, 225 error: function (error) { 226 $(`.box-add-product-${productId}`).find(".btn-change-quantity").css("pointer-events", "initial").find('i.fa').removeClass(faSpinner); 227 228 $('#btnCheckOut').prop('disabled', false); 229 console.log(error); 230 $('#textCheckOut').text(textCheckOut); 231 }, 232 beforeSend: function () { 233 GetScrollTopMyCart(); 234 235 $('#textCheckOut').text(languageLabel["O_Processing"] + "..."); 236 }, 237 complete: function () { 238 if (ico == 'True') { 239 $('#textCheckOut').text(languageLabel["O_Next"]); 240 } 241 //else if (textCheckOut != null && textCheckOut.length > 0) { 242 // $('#textCheckOut').text(textCheckOut); 243 //} 244 //else if (labelCheckoutBtn != null && labelCheckoutBtn.length > 0) { 245 // $('#textCheckOut').text(labelCheckoutBtn); 246 //} 247 //else { 248 // $('#textCheckOut').text(languageLabel["O_Checkout"]); 249 //} 250 251 $(`.box-add-product-${productId}`).find(".btn-change-quantity").css("pointer-events", "initial").find('i.fa').removeClass(faSpinner); 252 //getQuantityInCart(id, productId, true); 253 } 254 }); 255 } 256 });
257 258 $productInCartModal.on("click", ".btn-number", function (e) { 259 e.preventDefault(); 260 let that = $(this); 261 262 fieldName = that.attr('data-field'); 263 type = that.attr('data-type'); 264 var input = that.parents(".input-group").find("input[name='" + fieldName + "']"); 265 var currentVal = parseInt(input.val()); 266 if (!isNaN(currentVal)) { 267 if (type == 'minus') { 268 if (currentVal > input.attr('min')) { 269 input.val(currentVal - 1); 270 } 271 if (parseInt(input.val()) == input.attr('min')) { 272 that.attr('disabled', true); 273 if (input.attr('max') > parseInt(input.val())) { 274 $("#btn-plus-" + fieldName).removeAttr('disabled'); 275 } 276 } 277 } else if (type == 'plus') { 278 if (currentVal < input.attr('max')) { 279 input.val(currentVal + 1); 280 } 281 if (parseInt(input.val()) == input.attr('max')) { 282 that.attr('disabled', true); 283 } 284 } 285 286 delayTimer(function () { 287 input.change(); 288 }, 400); 289 } else { 290 input.val(0); 291 } 292 }); 293 294 $productInCartModal.on('shown.bs.modal', function () { 295 resizeHeightProductInCartModal(); 296 297 $('#category-section').find('.item-products').removeAttr('style'); 298 }); 299 300 $productInCartModal.on('hide.bs.modal', function () { 301 $(".btn-quantity-product").find(".btn-change-quantity").removeAttr('style').find('i.fa').removeClass(faSpinner); 302 303 $('#category-section').find('.item-products').removeAttr('style'); 304 }); 305 306}); 307 308function resizeHeightProductInCartModal() { 309 const $showProductInCartModal = $("#product-in-cart-modal"); 310 311 if (window.innerHeight - 20 < $showProductInCartModal.find('.modal-content').outerHeight()) { 312 $showProductInCartModal.find(".modal-body").css("height", window.innerHeight - $showProductInCartModal.find('.modal-header').outerHeight() - $showProductInCartModal.find('.modal-footer').outerHeight() - 60); 313 } 314} 315 316function reloadContentProductInCartModal(id, productId, typeItem) { 317 const $showProductInCartModal = $("#product-in-cart-modal"); 318 const scrollTopModal = $showProductInCartModal.find('.modal-body').scrollTop(); 319 320 if (checkNotExistsSession()) { 321 return false; 322 } 323 324 $(".addToCart-" + productId).parents(".box-product-" + productId).css("pointer-events", "none"); 325 326 $.ajax({
327 type: "GET", 328 url: urlGetProductInfoInCart, 329 data: { 'docId': id, 'productId': productId, 'typeItem': typeItem }, 330 success: function (result) { 331 $showProductInCartModal.find(".modal-content").html(result); 332 333 const isPopupShowed = $showProductInCartModal.hasClass('in'); 334 if (!isPopupShowed) { 335 $showProductInCartModal.modal("show"); 336 } 337 338 resizeHeightProductInCartModal(); 339 $showProductInCartModal.find('.modal-body').scrollTop(scrollTopModal); 340 }, 341 error: function () { 342 $(".addToCart-" + productId).parents(".box-product-" + productId).css("pointer-events", "initial"); 343 }, 344 beforeSend: function () { 345 }, 346 complete: function () { 347 //$(".addToCart-" + productId).parents(".box-product-" + productId).css("pointer-events", "initial"); 348 waitForChangeAddProductToCart(true); 349 } 350 }); 351} 352 353function changeQuantityProduct(variantId, id, productId, isTrackQuantity, typeItem) { 354 const $showProductInCartModal = $("#product-in-cart-modal"); 355 356 const isPopupShowed = $showProductInCartModal.hasClass('in'); 357 if (isPopupShowed) { 358 waitForChangeAddProductToCart(false); 359 } 360 361 var qty = $showProductInCartModal.find("#quantity_of_variant_" + variantId).val(); 362 if (qty == '' || qty == undefined || isNaN(qty) || parseInt(qty) <= 0) { 363 $showProductInCartModal.find("#warning_qty_variant_" + variantId).css('display', 'block'); 364 } 365 else { 366 $showProductInCartModal.find("#warning_qty_variant_" + variantId).css('display', 'none'); 367 } 368 369 var formdata = { 370 variantId: variantId, 371 qty: qty, 372 authorization: siteId 373 } 374 375 $.ajax({
376 type: "POST", 377 url: urlChangeQuantityVersion3, 378 data: formdata, 379 success: function (result) { 380 //Re-build the new content of cart 381 $('#containmycart').html(result); 382 383 if (isPopupShowed) { 384 reloadContentProductInCartModal(id, productId, typeItem); 385 } 386 387 //Re-set up the height of cart 388 ResetCartHeight(); 389 390 isShowAnimate = true; 391 ShowAnimate(id, productId, true, true, variantId); 392 393 if (orderType == 0) { // Delivery 394 mobileProgressBarDilivery(); 395 } 396 397 //Display warning if product/modifier is out-of-stock 398 if (isTrackQuantity == "True") { 399 checkProductOutOfStock(id, productId); 400 } 401 402 //Update the count number of items in cart 403 updateCartCount(); 404 }, 405 error: function (error) { 406 console.log(error); 407 }, 408 beforeSend: function () { 409 GetScrollTopMyCart(); 410 }, 411 complete: function () { 412 //getQuantityInCart(id, productId, true); 413 } 414 }); 415} 416 417function waitForChangeAddProductToCart(completed = false) { 418 //console.log('completed', completed); 419 $("#product-in-cart-modal").find('.product-in-cart-modal-waiting').css("display", completed ? "none" : "flex"); 420}
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.