239 lines
6.4 KiB
JavaScript
239 lines
6.4 KiB
JavaScript
|
|
lazy_load_group.push(
|
|
{
|
|
id: 'js-hottpye-bestsale',
|
|
target: '#js-hottpye-bestsale',
|
|
loadFn: function () {
|
|
getProductBestsale();
|
|
},
|
|
},
|
|
|
|
|
|
)
|
|
|
|
function lazyCategoryBox(){
|
|
for (let i = 0; i <= category_to_fetch.length - 1 && 1<2; i++) {
|
|
let idCat = category_to_fetch[i]
|
|
lazy_load_group.push(
|
|
{
|
|
id: "js-product-" + idCat,
|
|
target: "#js-product-" + idCat,
|
|
loadFn: function () {
|
|
getCategoryProduct(idCat)
|
|
},
|
|
},
|
|
);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
var swiper = new Swiper(".banner_homepage", {
|
|
pagination: {
|
|
el: ".swiper-pagination",
|
|
type: "fraction",
|
|
},
|
|
navigation: {
|
|
nextEl: ".swiper-button-next",
|
|
prevEl: ".swiper-button-prev",
|
|
},
|
|
});
|
|
|
|
|
|
var swiper = new Swiper(".list-feedback", {
|
|
slidesPerView: 3,
|
|
spaceBetween: 10,
|
|
navigation: {
|
|
nextEl: ".swiper-button-next",
|
|
prevEl: ".swiper-button-prev",
|
|
},
|
|
breakpoints: {
|
|
1610: {
|
|
slidesPerView: 4,
|
|
},
|
|
1210: {
|
|
slidesPerView: 3,
|
|
},
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
// SWIPER HOMEPAGE CATEGORY
|
|
function swiperDealBox() {
|
|
new Swiper(".swiper-deal-box", {
|
|
slidesPerView: 4,
|
|
spaceBetween: 12,
|
|
rewind: true,
|
|
speed: 1000,
|
|
preloadImages: false,
|
|
lazy: true,
|
|
|
|
navigation: {
|
|
nextEl: ".swiper-button-next",
|
|
prevEl: ".swiper-button-prev",
|
|
},
|
|
breakpoints: {
|
|
1200: {
|
|
slidesPerView: 4,
|
|
},
|
|
1600: {
|
|
slidesPerView: 5,
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
swiperDealBox();
|
|
</script>
|
|
|
|
<script>
|
|
// AJAX CATEGORY BOX - NEW PRODUCT
|
|
function getProductBestsale() {
|
|
var params = {
|
|
action_type: "product-list",
|
|
hotType: "bestsale",
|
|
sort: "order",
|
|
page: 1,
|
|
show: 12,
|
|
};
|
|
var target = "#js-hottpye-bestsale";
|
|
Hura.Ajax.get("product", params).then(function (data) {
|
|
//console.log(data.list);
|
|
if (data.total == 0) {
|
|
$(target).html(
|
|
`<h3 class="box-empty d-flex align-items-center justify-content-center">Sản phẩm đang được cập nhật...!</h3>`
|
|
);
|
|
} else {
|
|
var html = Hura.Template.parse(productBestSale, data.list.splice(0, 4));
|
|
Hura.Template.render(target, html);
|
|
let total = data.total;
|
|
$("#total").html(`${total}`);
|
|
}
|
|
});
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
<script>
|
|
// AJAX CATEGORY BOX - HOT PRODUCT
|
|
function getCategoryProduct(id) {
|
|
var params = {
|
|
action_type: "product-list",
|
|
category: id,
|
|
|
|
};
|
|
var target = "#js-product-hot-" + id;
|
|
var targetSmall = "#js-product-" + id;
|
|
|
|
Hura.Ajax.get("product", params).then(function (data) {
|
|
//console.log(data.list);
|
|
if (data.total == 0) {
|
|
$(target).html(
|
|
`<h3 class="box-empty d-flex align-items-center justify-content-center">Sản phẩm đang được cập nhật...!</h3>`
|
|
);
|
|
|
|
$(targetSmall).html(
|
|
`<h3 class="box-empty d-flex align-items-center justify-content-center">Sản phẩm đang được cập nhật...!</h3>`
|
|
);
|
|
|
|
} else {
|
|
|
|
var html = Hura.Template.parse(listHotCategoryHome, data.list.splice(0,1));
|
|
Hura.Template.render(target, html);
|
|
let quantity_change_btns = $(`#js-product-hot-${id}`).find(".js-quantity-change");
|
|
quantity_change_btns.each(function(){
|
|
$(this).addClass(`js-quantity-change-${id}`);
|
|
$('.js-buy-quantity').addClass(`js-quantity-change-${id}`);
|
|
})
|
|
listenQuantityBuy(id);
|
|
|
|
|
|
var htmlSmall = Hura.Template.parse(listCategoryHome, data.list.splice(0,6));
|
|
Hura.Template.render(targetSmall, htmlSmall);
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<script>
|
|
// ADD PRODUCT TO CART - PRODUCT DETAILS
|
|
function addProductToCart(product_id, variant_id_fake, props) {
|
|
let props_quantity = parseInt($(`.js-buy-quantity-temp-${product_id}`).attr("value"));
|
|
let stockQuantity = parseInt($(".bk-check-out-of-stock").attr("value"));
|
|
console.log(props_quantity);
|
|
|
|
var variant_id = 0;
|
|
var data = $('.js-variant-option-container input[type="hidden"]').val();
|
|
if (data) {
|
|
var newData = JSON.parse(data)
|
|
variant_id = newData.variant_id;
|
|
}
|
|
|
|
if (stockQuantity) {
|
|
var product_props = {
|
|
quantity: props_quantity,
|
|
buyer_note: "",
|
|
};
|
|
|
|
Hura.Cart.Product.add(product_id, variant_id, product_props).then(function (
|
|
response
|
|
) {
|
|
// Error response
|
|
if (response.status === "error") {
|
|
if (response.error_type == "item-in-cart") {
|
|
alert("Sản phẩm đã trong giỏ hàng");
|
|
} else if (response.error_type == "invalid-item-id")
|
|
alert("ID sản phẩm không đúng");
|
|
else alert(response.message);
|
|
}
|
|
// Success response
|
|
else {
|
|
modalSuccess();
|
|
change_cart_amount();
|
|
}
|
|
});
|
|
} else {
|
|
alert("Sản phẩm không có sẵn. Vui lòng liên hệ. Xin cảm ơn!")
|
|
}
|
|
}
|
|
|
|
// LANG NGHE THAY DOI SO LUONG SP
|
|
function listenQuantityBuy(id) {
|
|
|
|
let $track_change = $(`.js-quantity-change-${id}`);
|
|
|
|
//thay doi so luong sp mua, neu nhap so luong
|
|
$track_change.on("change", function (e) {
|
|
let $row1 = $(this).closest(".cart-quantity-select");
|
|
if($(this).val() < 1 && 1<2) $(this).val(1);
|
|
$row1.find(".js-buy-quantity-temp").attr("value", e.target.value);
|
|
});
|
|
|
|
//thay doi so luong sp theo - hoac +
|
|
$track_change.on("click", function (e) {
|
|
|
|
if (e.target.nodeName === "INPUT") return;
|
|
|
|
let quantity_change = parseInt(this.getAttribute("data-value"));
|
|
let $row = $(this).closest(".cart-quantity-select");
|
|
let current_quantity = parseInt($row.find(".js-buy-quantity").val());
|
|
|
|
|
|
//loai bo so luong vo ly
|
|
if(current_quantity + quantity_change < 1 && 1 < 2) {
|
|
$(".js-buy-quantity").val(1);
|
|
return ;
|
|
}
|
|
|
|
let totalQuantity = current_quantity + quantity_change;
|
|
|
|
$row.find(".js-buy-quantity").val(totalQuantity);
|
|
$row.find(".js-buy-quantity-temp").attr("value", totalQuantity);
|
|
});
|
|
}
|