"'><
商品編號:
供貨狀況:
尚有庫存
加入最愛
已銷售: 0 件
此商品可以折抵紅利
0
點
- ,,";
var isHideAddToCartBtn = new ProductVariants(variants_info).get_product_option_list().every(function(item){
return parseInt(item.quantity) <= 0 && item.inventory_policy === "deny";
});
var isPreOrder = new ProductVariants(variants_info).get_product_option_list().every(function(item){
return parseInt(item.quantity) <= 0 && item.inventory_policy === "continue";
});
if (isHideAddToCartBtn) {
// 商品頁下滑加入購物車按鈕
$('#add_to_cart').css("display", "none");
$('.btn_to_cart_mobile').hide();
$('.btn_to_cart_mobile_default').hide();
$('.btn_quick_buy_mobile').hide();
$('.btn_quick_buy_mobile_default').hide();
$('#message_to_buy').css("display", "block");
$('.btn_msg_mobile').show();
$('.btn_msg_mobile_default').show();
$('#notice_to_buy').css("display", "block");
// 購物車按鈕和庫存狀態
$('.addToCart').hide();
$('.btn_msg').show();
$('.btn_notice').show();
$('.product_inventory_policy .val').text("庫存不足");
} else {
if (isPreOrder) {
$('#add_to_cart').text("預購商品");
$('.btn_to_cart_mobile').text("預購商品");
$('.btn_to_cart_mobile_default').text("預購商品");
$('.btn_quick_buy_mobile').hide();
$('.btn_quick_buy_mobile_default').hide();
}
}
})();
// 商品圖輪播
var productImage = new Swiper('.product_img_swiper', {
// Disable preloading of all images
preloadImages: false,
// Enable lazy loading
lazy: true,
loop: true,
navigation: {
nextEl: '.photo-swiper-next',
prevEl: '.photo-swiper-prev',
}
});
// 圖片放大
$('.product_photos .swiper-container .swiper-button').on('click', function(e){
e.stopPropagation()
})
$('.product_photo.img-flex img').on('click', function(){
if (document.getElementById('photo_with_images_color')) {
var index = 0;
var productsSrc = [document.getElementById('photo_with_images_color').src];
} else if (productImage.$wrapperEl) {
var index = productImage.realIndex;
var productImages = $(productImage.$wrapperEl[0]).find('img');
var productsSrc = [];
productImages.map(function(index, el) {
if (index !== 0 && index !== productImages.length-1) {
productsSrc.push(el.dataset.src || el.src)
}
})
} else {
return null;
}
gallery_img.updateImgs(productsSrc)
gallery_img.toggleGallery(true, { index: index })
});
// 圖片頁碼
$(".thumb").on('click', 'li', function(){
$(this).addClass('active').siblings().removeClass('active');
productImage.slideTo($(this).index()+1, 500);
});
// 輪播轉換縮圖
$('.product_img_swiper .swiper-button').click(function(){
var swiperIndex = $('.swiper-slide').index($('.swiper-slide-active'));
var pages = $(".thumb li").length;
var photoIndex = (swiperIndex + pages - 1 ) % pages;
$($(".thumb li")[photoIndex]).addClass('active').siblings().removeClass('active');
});
//滑動換圖
productImage.on('touchEnd', function(){
setTimeout(function(){
var swiperIndex = $('.swiper-slide').index($('.swiper-slide-active'));
var pages = $(".thumb li").length;
var photoIndex = (swiperIndex + pages - 1 ) % pages;
$($(".thumb li")[photoIndex]).addClass('active').siblings().removeClass('active');
}, 300);
});
// 商品說明介紹標籤
$(".desc_sections li").on('click', function(){
$(this).children().addClass('active');
$(this).siblings().children().removeClass('active');
productImage.slideTo($(this).index() + 1, 500);
});
// 產品說明
$(window).on('scroll', function () {
var headerHeight = $("#header").height()
var desc_sections = $(".desc_sections");
var desc_section_list = $(".desc_section");
var descSectionHeight = $(".desc_sections").height()
var descSectionTop = $(".desc_sections").offset().top - headerHeight
var product_window = $(this);
// 滑動固定產品說明
if (product_window.scrollTop() > descSectionTop){
desc_sections.stop().addClass("desc_sections_hold").css({"min-height": descSectionHeight}).find("ul").css({"top": headerHeight})
if($(window).width() < 768) {
// 手機版,往下滑時,開啟 product modal
$(".product_button_mobile").css("display", "none");
$(".product_button_mobile_default").css("display", "flex");
}
}else{
desc_sections.stop().removeClass("desc_sections_hold")
if($(window).width() < 768) {
$(".product_button_mobile").css("display", "flex");
$(".product_button_mobile_default").css("display", "none");
}
}
// 點選產品說明滑動
$(".desc_sections a.scroll").bind("click",function(event){
var targetScrollTop = $($(this).attr("href")).offset().top - headerHeight - descSectionHeight + 1
$("html, body").stop().animate({scrollTop: targetScrollTop}, 300);
});
// 顯示當前產品說明
$.each(desc_section_list, function(index, desc_section){
var desc_sectionTop = $(desc_section).offset().top - headerHeight - descSectionHeight - 1
var desc_sectionHeight = $(desc_section).height()
var current_desc_section = $("a.scroll[href$='" + $(desc_section).attr("id") + "']");
if (product_window.scrollTop() > desc_sectionTop || index === 0){
current_desc_section.stop().addClass('active').parent().siblings().find("a").removeClass('active')
}else{
current_desc_section.removeClass('active')
}
});
});
// 加入購物車 open product modal
$(".open_product_modal").on('click', function(){
var variants = parseInt("0");
// 若單一選項,不須跳出 modal,直接加入購物車
if (variants > 0) {
var variantId = selectedVariant.id;
if ($(".desc_sections").hasClass("desc_sections_hold")) {
var productHandle = '/products/' + $(this).data('handle');
var collectionId = $(this).data('collection');
new_addcart_modal.popModal(productHandle, collectionId, null, null, false, false, variantId);
} else {
// 當於上方列時,判斷是否有選到東西,有的話直接加入購物車,不須跳出文字提示
if (parseInt(variantId) > 0) {
$(".btn_to_cart").trigger('click');
} else {
window.msg("請選擇商品款式", 'info').show();
}
}
} else {
$(".btn_to_cart").trigger('click');
}
})
// 立即購買 mobile product modal
$(".open_quick_buy_modal").on('click', function(){
var variants = parseInt("0");
// 若單一選項,不須跳出 modal,直接加入購物車
if (variants > 0) {
var variantId = selectedVariant.id;
if ($(".desc_sections").hasClass("desc_sections_hold")) {
var productHandle = '/products/' + $(this).data('handle');
var collectionId = $(this).data('collection');
new_addcart_modal.popModal(productHandle, collectionId, null, null, false, true, variantId);
} else {
// 當於上方列時,判斷是否有選到東西,有的話直接加入購物車,不須跳出文字提示
if (parseInt(variantId) > 0) {
$(".btn-quick_buy").trigger('click');
} else {
window.msg("請選擇商品款式", 'info').show();
}
}
} else {
$(".btn-quick_buy").trigger('click');
}
})
// 聯絡商家
$(".btn_msg, .btn_msg_mobile, .btn_msg_mobile_default, #message_to_buy").on('click', function(){
var variant = {
compareAtPrice: selectedVariant.compareAtPrice,
id: selectedVariant.id,
imgUrl: $('#product .product_info .thumb .active img').attr('src'),
inventoryPolicy: selectedVariant.inventoryPolicy,
inventoryQuantity: selectedVariant.inventoryQuantity,
price: selectedVariant.price,
productTitle: selectedVariant.name == "" ? "\"'\u003e\u003c\u003cSCRIPT a=2\u003eqss=7;//\u003c\u003c/SCRIPT\u003e" : "\"'\u003e\u003c\u003cSCRIPT a=2\u003eqss=7;//\u003c\u003c/SCRIPT\u003e" + ' - ' + selectedVariant.name,
sku: selectedVariant.sku,
title: selectedVariant.name || null,
}
$('#messagebuy-Modal').data('variant',variant);
})
// 貨到通知
$(".btn_notice").on('click', function() {
var variantId = selectedVariant.id || parseInt('32137022');
$(".btn_notice").attr('disabled', 'disabled');
$.ajax({
url: '/toggle_pv_notification',
method: 'POST',
dataType: 'json',
data: {
product_variant_id: variantId,
},
success: function(response) {
var noticeText = response.notice ? '已登記補貨通知' : '已售完,貨到通知我';
variantNotifications[variantId] = response.notice;
window.msg(response.message, "success").show();
$(".btn_notice").attr('disabled', false);
$(".btn_notice").text(noticeText);
},
error: function(xhr) {
var response = xhr.responseJSON;
var msg = response && response.error || '網路連線異常,請重新整理';
window.msg(msg, "error").show();
$(".btn_notice").attr('disabled', false);
},
})
});
function setSelectedVariant(variant) {
selectedVariant = variant;
selectedVariant.notification = variantNotifications[variant.id] || false;
}
function groupBy(xs, key) {
return xs.reduce(function (rv, x) {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
};
function setUpDiscountsTag() {
$.ajax({
url: window.location.pathname + '/discounts_list',
method: 'GET',
success: function(result){
if ( result.length > 0 ) {
var discounts_list = groupBy(result, 'campaign_type');
Object.keys(discounts_list).map(function(key, index){
discounts_list[key].map(function(discount, index){
var discount_row = document.createElement('div');
discount_row.className = 'discount-list';
if (discount.url){
var discount_title = document.createElement('a');
$(discount_title).attr("href", discount.url);
}else{
var discount_title = document.createElement('span');
}
discount_title.className = 'discount-title'
discount_title.innerText = discount.title;
discount_row.append(discount_title);
$('.product_discounts_list .list_block').append(discount_row);
});
});}
if ($('.product_discounts_list .discount-list').length > 0) {
$('.product_discounts_list').removeClass('hide');
}
},
});
}
setUpDiscountsTag();
})