MM MEGA MARKET CMS DIGITAL
Username
Password

LDAP

//1. store.admin.10010
//2. test.ho.mng
// pass:User@123456$

//Vô hiệu hóa Enter document.addEventListener("keydown", function (event) { if (event.key === "Enter" && event.target && event.target.id === "qtyinput") { event.preventDefault(); } }); //Thêm vào giỏ hàng function AddtoCart(productElement) { var list_order = $.parseJSON(localStorage.getItem("ORDER_LIST")); if (list_order == null) { list_order = []; } var product = $.parseJSON(productElement.getAttribute('data-product')); var existingProduct = list_order.find(function (item) { return item.artNo === product.artNo; }) if (existingProduct) { existingProduct.quantity++; existingProduct.total = existingProduct.orgprice * existingProduct.quantity; } else { product.quantity = 1; product.total = product.orgprice; list_order.push(product); updateUI(list_order); } localStorage.setItem("ORDER_LIST", JSON.stringify(list_order)); updateUI(list_order); updateTotal(list_order); check(list_order); calculate(list_order); } //ràng buộc nếu có sản phẩm trong cart thì không thể thay đổi store function check(arr) { var storeSelect = document.getElementById('storeSelect'); if (arr.length > 0) { storeSelect.disabled = true; } else { storeSelect.disabled = false; } } //tính Total price function calculate(arr) { var totalPrice = 0; if (arr && arr.length > 0) { arr.forEach(function (product) { totalPrice += product.total; }) } var totalMoney = document.getElementById('TotalMoney'); totalMoney.textContent = totalPrice.toLocaleString('vi-VN') + "d"; } //giảm quantity function decrease(element) { var list_order = $.parseJSON(localStorage.getItem("ORDER_LIST")); var parentRow = element.closest('.row'); var artNo = parentRow.getAttribute('data-artNo'); var foundProduct = list_order.find(function (item) { return item.artNo == artNo; }) if (foundProduct && foundProduct.quantity > 1) { if (foundProduct.quantity % 1 == 0) { foundProduct.quantity -= 1; } else { foundProduct.quantity = parseFloat((foundProduct.quantity - 1).toFixed(1)); } foundProduct.total = foundProduct.quantity * foundProduct.orgprice; } else { var index = list_order.indexOf(foundProduct); list_order.splice(index, 1); check(list_order); } localStorage.setItem("ORDER_LIST", JSON.stringify(list_order)); updateUI(list_order); updateTotal(list_order); calculate(list_order); } //tăng quantity function increase(element) { var list_order = $.parseJSON(localStorage.getItem("ORDER_LIST")); var parentRow = element.closest('.row'); var artNo = parentRow.getAttribute('data-artNo'); var foundProduct = list_order.find(function (item) { return item.artNo == artNo; }) if (foundProduct) { foundProduct.quantity += 1; foundProduct.total = foundProduct.orgprice * foundProduct.quantity; localStorage.setItem("ORDER_LIST", JSON.stringify(list_order)); calculate(list_order); updateUI(list_order); updateTotal(list_order); } } //xóa sản phẩm function erase(element) { var list_order = $.parseJSON(localStorage.getItem("ORDER_LIST")); var parentRow = element.closest('.row'); var artNo = parentRow.getAttribute('data-artNo'); var foundProduct = list_order.find(function (item) { return item.artNo == artNo; }) if (foundProduct) { var index = list_order.indexOf(foundProduct); list_order.splice(index, 1); localStorage.setItem("ORDER_LIST", JSON.stringify(list_order)); check(list_order); calculate(list_order); updateUI(list_order); updateTotal(list_order); } } //Nhập số quantity function changequantity(element) { var list_order = $.parseJSON(localStorage.getItem("ORDER_LIST")); var newValue = element.value.replace(/[^0-9.]/g, ''); newValue = parseFloat(newValue); var parentRow = element.closest('.row'); var artNo = parentRow.getAttribute('data-artNo'); var foundProduct = list_order.find(function (item) { return item.artNo == artNo; }) if (foundProduct) { if (isNaN(newValue) || newValue < 0) { newValue = 0; } if (newValue === 0) { var index = list_order.indexOf(foundProduct); list_order.splice(index, 1); check(list_order); } else { foundProduct.quantity = newValue; foundProduct.total = foundProduct.orgprice * newValue; } localStorage.setItem("ORDER_LIST", JSON.stringify(list_order)); updateUI(list_order); updateTotal(list_order); calculate(list_order); } } // cập nhật số thứ tự function updateTotal(arr) { var count = 1; var maxNumber = 0; for (var i = 0; i < arr.length; i++) { arr[i].number = count; maxNumber = Math.max(maxNumber, count); count++; } var cartContent = document.querySelector('.cartContent'); var items = cartContent.querySelectorAll('.row'); items.forEach(function (item, index) { var artNo = item.getAttribute('data-artNo'); var foundProduct = arr.find(function (item) { return item.artNo == artNo; }); if (foundProduct) { var numberElement = item.querySelector('.name'); numberElement.textContent = `${foundProduct.number}/${maxNumber}. ${foundProduct.artName}`; } }); } function updateUI(arr) { var cartContent = document.querySelector('.cartContent'); cartContent.innerHTML = ''; arr.forEach(function (product) { var artPrice = product.orgprice; var artName = product.artName; var artNo = product.artNo; var artNum = product.number; var quantity = product.quantity; var total = artPrice * product.quantity; var totalElement = document.createElement("div"); totalElement.classList.add("price"); var cardHTML = `

${artNum}/${artNum}. ${artName}

Price: ${artPrice.toLocaleString('vi-VN') + "d"}/unit
- +

${total.toLocaleString('vi-VN') + "d"}
`; cartContent.insertAdjacentHTML('beforeend', cardHTML); }) }