購物車沒有加入任何商品
×































































































































































商品數量要大於0!
');
return false;
}
if( $(".div_group[data-required]").length ){
$( ".alert-error" ).remove();
var r = 0;
var v_qty ;
$(".div_group[data-required]").each(function( index ) {
var required = $(this).data("required") || 0;
v_qty = 0;
$(this).find(".free_present_qty").each(function() {
v_qty = v_qty + parseInt($(this).val());
});
if( required == 1 && v_qty == 0 ) r++;
});
if(r > 0){
$('#free_present_list').before(' * 贈品為必選項目!
');
$('html, body').animate({
scrollTop: ($('#free_present_list').offset().top - 150)
}, 1000);
iziToast.show({
timeout: 3000,
color: '#eb4359',
messageColor: '#FFF',
message: "* 贈品為必選項目",
position: 'center',
progressBar: false,
progressBarEasing: 'ease',
});
return false;
}
if($(".warning").text().length > 0 ){
return false;
}
}
if( $("#options .control-group[data-max-qty]").length ){
var r = true;
$("#options .control-group[data-max-qty]").each(function( index ) {
var option_ckb_id = $(this).data("option-id") || 0;
if( option_ckb_id ) {
r = checkCheckboxOptionQtyLimition(option_ckb_id);
if( r == false ) return false;
}
});
if( r == false ) return false;
}
$('.button-quick-checkout').attr("disabled","disabled");
$('.icon-spinner').removeClass('hidden');
$("input[name='product_id']").attr("value", 3699);
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea,.cart input[name=\'promption_id\']'),
dataType: 'json',
success: function(json) {
$( ".error" ).remove();
$( ".alert-danger" ).remove();
$('.icon-spinner').addClass('hidden');
$('.button-quick-checkout').removeAttr("disabled", "disabled");
if (json['error']) {
$( ".error" ).remove();
if (json['error']['option']) {
$(".alert-error").remove();
var error_option_msg = 0;
for (i in json['error']['option']) {
error_option_msg = json['error']['option'][i];
if( is.not.desktop() ) {
$('#option-' + i).after('' + json['error']['option'][i] + '
');
} else {
$('#option-' + i).after('' + json['error']['option'][i] + ''); } } if( error_option_msg ) { iziToast.show({ timeout: 3000, color: '#eb4359', messageColor: '#FFF', message: error_option_msg, position: 'center', progressBar: false, progressBarEasing: 'ease', }); } } if (json['error']['prod_stock']) { if( is.not.desktop() ) { $( ".alert-error" ).remove(); $('#product_id').after('
'+ json['error']['prod_stock'] + '
');
iziToast.show({
timeout: 3000,
color: '#eb4359',
messageColor: '#FFF',
message: json['error']['prod_stock'],
position: 'center',
progressBar: false,
progressBarEasing: 'ease',
});
} else {
$( ".alert-danger" ).remove();
$('#product_id').after(''+ json['error']['prod_stock'] + '
');
}
}
if (json['error']['buy_together']) {
for (j in json['error']['buy_together']) {
$('#error_buy_togther').after('' + json['error']['buy_together'][j] + '');
}
}
}
if (json['success']) {
try { gaTrackMultiPixelsAddToCart("AddToCart"); } catch (e) { }
try { gaTrackProductAddToCart(); } catch (e) { }
var qty = 1;
if($("select[name='quantity']").length){
qty = $("select[name='quantity'] option:selected").val();
} else {
qty = $("input[name='quantity']").val();
}
var product_price = qty * 440;
global_quuid = QUUID();
product_price = Number(product_price);
if( isNaN(product_price) ) {
product_price = 0;
}
fbq('track', 'AddToCart', {
content_name: '[85-130cm] 質感皮革拼接彈性吊帶 #Taurus金牛座',
content_ids: ['3699'],
content_type: 'product',
value: product_price,
currency: 'TWD'
}, {eventID: global_quuid + "ccc"});
setTimeout(function(){
window.location.href = "https://littleuniverse.freestore.tw/cart";
}, 1000);
}
if( is.not.desktop() ) {
if (json['error']) {
$('html, body').animate({ scrollTop: $('#options').offset().top }, 'slow');
}
}
}
});
return false;
}
function FB_AddToWishlist(){
fbq('track', 'AddToWishlist', {
value: '440',
content_name: '[85-130cm] 質感皮革拼接彈性吊帶 #Taurus金牛座',
content_ids: ['3699'],
content_type: 'product',
content_category: "小物",
currency: 'TWD'
}, {eventID: global_quuid});
try { gaTrackMultiPixelsAddToCart("AddToWishlist"); } catch (e) { }
}
// button-cart
function buttonAddToCart() {
// 檢查加價購是否有錯誤
if (window.buyTogetherHasError) {
$( ".alert-danger" ).remove();
$('#product_id').after('加價購商品數量設定有誤,請檢查後重新選擇!
');
return false;
}
if($("select[name='quantity']").length){
check_qty = $("select[name='quantity'] option:selected").val();
} else {
check_qty = $("input[name='quantity']").val();
}
if(check_qty == 0){
$( ".alert-danger" ).remove();
$('#product_id').after('商品數量要大於0!
');
return false;
}
if( $(".div_group[data-required]").length ){
$( ".alert-error" ).remove();
var r = 0;
var v_qty ;
$(".div_group[data-required]").each(function( index ) {
var required = $(this).data("required") || 0;
v_qty = 0;
$(this).find(".free_present_qty").each(function() {
v_qty = v_qty + parseInt($(this).val());
});
if( required == 1 && v_qty == 0 ) r++;
});
if(r > 0){
$('#free_present_list').before(' * 贈品為必選項目!
');
$('html, body').animate({
scrollTop: ($('#free_present_list').offset().top - 150)
}, 1000);
iziToast.show({
timeout: 3000,
color: '#eb4359',
messageColor: '#FFF',
message: "* 贈品為必選項目",
position: 'center',
progressBar: false,
progressBarEasing: 'ease',
});
return false;
}
if($(".warning").text().length > 0 ){
return false;
}
}
if( $("#options .control-group[data-max-qty]").length ){
var r = true;
$("#options .control-group[data-max-qty]").each(function( index ) {
var option_ckb_id = $(this).data("option-id") || 0;
if( option_ckb_id ) {
r = checkCheckboxOptionQtyLimition(option_ckb_id);
if( r == false ) return false;
}
});
if( r == false ) return false;
}
$('.button-cart').attr("disabled","disabled");
$('.icon-spinner').removeClass('hidden');
$("input[name='product_id']").attr("value", 3699);
$( ".alert-danger" ).remove();
// **新增:收集表單數據並過濾重複的加價購商品**
var formData = $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea,.cart input[name=\'promption_id\'], .well-lg input[type=\'checkbox\']:checked, .well-lg input[type=\'radio\']:checked, .well-lg select[name^=\'buy_together_qty_\'], .well-lg input[name^=\'add_price_options_\']');
// 收集所有有規格的加價購商品
var optionsProductKeys = [];
formData.filter('input[name^="add_price_options_"]').each(function() {
var optionKey = $(this).attr('name').replace('add_price_options_', '');
// 提取原始的 product_id-buy_together_id 部分 (去除時間戳)
var parts = optionKey.split('-');
if (parts.length >= 2) {
var originalKey = parts[0] + '-' + parts[1];
optionsProductKeys.push(originalKey);
}
});
// 過濾表單數據,移除重複的無規格版本
var filteredData = formData.filter(function() {
if ($(this).attr('name') === 'add_price[]') {
var value = $(this).val();
// 檢查這個值是否在有規格的商品列表中
if (optionsProductKeys.includes(value)) {
console.log('buttonAddToCart - 過濾掉重複的無規格加價購商品:', value);
return false; // 排除這個元素
}
}
return true; // 保留這個元素
});
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: filteredData,
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, information, .error').remove();
$('.icon-spinner').addClass('hidden');
if (json['error']) {
$( ".error" ).remove();
if (json['error']['option']) {
$(".alert-error").remove();
var error_option_msg = 0;
for (i in json['error']['option']) {
error_option_msg = json['error']['option'][i];
if( is.not.desktop() ) {
$('#option-' + i).after('' + json['error']['option'][i] + '
');
} else {
$('#option-' + i).after('' + json['error']['option'][i] + ''); } } if( error_option_msg ) { iziToast.show({ timeout: 3000, color: '#eb4359', messageColor: '#FFF', message: error_option_msg, position: 'center', progressBar: false, progressBarEasing: 'ease', }); } } if (json['error']['prod_stock']) { if( is.not.desktop() ) { $( ".alert-error" ).remove(); $('#product_id').after('
'+ json['error']['prod_stock'] + '
');
iziToast.show({
timeout: 3000,
color: '#eb4359',
messageColor: '#FFF',
message: json['error']['prod_stock'],
position: 'center',
progressBar: false,
progressBarEasing: 'ease',
});
} else {
$( ".alert-danger" ).remove();
$('#product_id').after(''+ json['error']['prod_stock'] + '
');
}
}
if (json['error']['buy_together']) {
for (j in json['error']['buy_together']) {
$('#error_buy_togther').after('' + json['error']['buy_together'][j] + '');
}
}
$('.button-cart').removeAttr("disabled", "disabled");
}
if( is.not.desktop() ) {
if (json['error']) {
$('html, body').animate({ scrollTop: $('#options').offset().top }, 'slow');
}
}
if (json['success']) {
try { gaTrackMultiPixelsAddToCart("AddToCart"); } catch (e) { }
try { gaTrackProductAddToCart(); } catch (e) { }
var qty = 1;
if($(".cart select[name='quantity']").length){
qty = $(".cart select[name='quantity'] option:selected").val();
} else {
qty = $(".cart input[name='quantity']").val();
}
var product_price = qty * 440;
global_quuid = QUUID();
product_price = Number(product_price);
if( isNaN(product_price) ) {
product_price = 0;
}
fbq('track', 'AddToCart', {
content_name: '[85-130cm] 質感皮革拼接彈性吊帶 #Taurus金牛座',
content_ids: ['3699'],
content_type: 'product',
value: product_price,
currency: 'TWD'
}, {eventID: global_quuid + "ccc"});
$('#notification').html('');
$('.alert').fadeIn('slow');
$('#cart-total').html(json['total']);
var scroll_time = 700;
var ToScrollTop = 0;
if( is.not.desktop() ) {
scroll_time = 300;
ToScrollTop = document.documentElement.scrollTop;
}
$('html, body').animate({ ToScrollTop: 0 }, scroll_time, function() {
var attr = $('.button-cart').attr('disabled');
if (typeof attr !== typeof undefined && attr !== false) {
var cart = $('#cart');
var imgtodrag = $('#zoom1');
var cart_top = 50;
var cart_right = $(window).width() / 1.5;
if( is.not.desktop() ) {
cart_right = $("#mobile-navbar #shopping-cart-list").offset().left;
} else {
cart_right = $("#header #cart").offset().left;
}
if( cart_right < 100 ) cart_right = $(window).width() / 1.5;
if( is.not.desktop() ) {
cart = $('#mobile-navbar .icon-shopping-cart');
cart_top = 0;
$('#cart-total-items').html("( "+json['total']+" )");
$(".button-quick-checkout-mobile").remove();
$("#button-cart").css('width', '36%');
$("#button-cart").unbind("click");
$("#button-cart").find('.ok-add-to-cart').remove();
$("#button-cart").prepend('');
$("#button-instant-checkout").removeClass('hidden');
$("#button-instant-checkout").css('width', '60%');
}
var imgclone = imgtodrag.clone()
.offset({
top: imgtodrag.offset().top,
left: imgtodrag.offset().left
})
.css({
'opacity': '1.0',
'position': 'absolute',
'top': imgtodrag.offset().top,
'left': imgtodrag.offset().left,
'height': $('#zoom1').width(),
'width': $('#zoom1').height(),
'z-index': '99999999999',
'minHeight': '50px'
})
.appendTo($('body'))
.animate({
'top' : cart_top,
'left' : cart_right,
'width' : 36,
'height' : 20,
'opacity' : '0.01'
}, 700, 'easeInOutCirc', function() {
$(imgclone).remove();
imgclone.detach();
});
if( is.not.desktop() ) {
openSideCart('3699');
}
}
if( is.desktop() ) {
$("#cart > .heading a").trigger('mouseover');
setTimeout(function(){ refreshMiniCartScrollBar(); }, 300);
}
$('.button-cart').removeAttr("disabled", "disabled");
});
}
}
});
return false;
}
function addReview(){
$.ajax({
url: 'index.php?route=product/product/write&product_id=3699',
type: 'post',
dataType: 'json',
data: 'name=' + encodeURIComponent($('input[name=\'name\']').val()) + '&text=' + encodeURIComponent($('textarea[name=\'text\']').val()) + '&rating=' + encodeURIComponent($('input[name=\'rating\']:checked').val() ? $('input[name=\'rating\']:checked').val() : '') + '&captcha=' + encodeURIComponent($('input[name=\'captcha\']').val()) + '&recaptcha_challenge_field=' + encodeURIComponent($('input[name=\'recaptcha_challenge_field\']').val()) + '&recaptcha_response_field=' + encodeURIComponent($('input[name=\'recaptcha_response_field\']').val()),
beforeSend: function() {
$('.success, .warning').remove();
$('#button-review').attr('disabled', true);
$('#review-title').after('
請稍等' + data['error'] + '
');
}
if (data['success']) {
$('#review-title').after('' + data['success'] + '
');
$('input[name=\'name\']').val('');
$('textarea[name=\'text\']').val('');
$('input[name=\'rating\']:checked').attr('checked', '');
$('input[name=\'captcha\']').val('');
$('#review').load('index.php?route=product/product/review&product_id=3699');
postbackTrack();
}
}
});
}
function updateBuyTogetherQty(qty, opt_name, input_value) {
var target_input = $("input[value='"+input_value+"']");
var target_select = $("select[name='"+opt_name+"']");
// **新增:驗證數量限制**
if (target_select.length > 0) {
validateBuyTogetherTotal(input_value, target_select[0]);
}
if( qty > 0 ) {
target_select.addClass("highlight");
target_input.prop('checked', true);
// **修正:如果是 radio 類型,清除同組其他選項的所有相關元素**
if(target_input.attr('type') === 'radio') {
var radio_name = target_input.attr('name');
$("input[name='"+radio_name+"']:not([value='"+input_value+"'])").each(function() {
var other_value = $(this).val();
// 1. 取消勾選其他選項
$(this).prop('checked', false);
// 2. 重置其他選項的一般數量選擇器
var other_opt_name = 'buy_together_qty_' + other_value;
$("select[name='"+other_opt_name+"']").val(0).removeClass("highlight");
// **新增:清除其他選項的多規格選擇器和 hidden inputs**
var other_container_id = '#lg_option_' + other_value;
// 清除所有多規格相關的選擇器
$(other_container_id + ' select[name^="buy_together_qty_"]').each(function() {
$(this).val(0).removeClass("highlight");
});
// 清除所有多規格相關的 hidden inputs
$(other_container_id + ' input[name^="add_price_options_"]').each(function() {
$(this).remove();
});
// 清除所有多規格相關的 add_price[] inputs
$(other_container_id + ' input[name="add_price[]"].multi-spec-buy-together').each(function() {
$(this).remove();
});
// **新增:完全清空其他選項的容器**
$(other_container_id).empty();
});
}
} else {
target_select.removeClass("highlight");
target_input.prop('checked', false);
// **新增:當數量為 0 時,也清除相關的多規格選擇器**
var container_id = '#lg_option_' + input_value;
$(container_id + ' select[name^="buy_together_qty_"]').val(0).removeClass("highlight");
$(container_id + ' input[name^="add_price_options_"]').remove();
$(container_id + ' input[name="add_price[]"].multi-spec-buy-together').remove();
$(container_id).empty(); // 完全清空容器
}
}
function postbackTrack(){
}
function buttonAddPrice(){
// 檢查加價購是否有錯誤
if (window.buyTogetherHasError) {
$( ".alert-danger" ).remove();
$('#buy_together_list').prepend('加價購商品數量設定有誤,請檢查後重新選擇!
');
return false;
}
if( $(".div_group[data-required]").length ){
$( ".alert-error" ).remove();
var r = 0;
var v_qty ;
$(".div_group[data-required]").each(function( index ) {
var required = $(this).data("required") || 0;
v_qty = 0;
$(this).find(".free_present_qty").each(function() {
v_qty = v_qty + parseInt($(this).val());
});
if( required == 1 && v_qty == 0 ) r++;
});
if(r > 0){
$('#free_present_list').before(' * 贈品為必選項目!
');
$('html, body').animate({
scrollTop: ($('#free_present_list').offset().top - 150)
}, 1000);
iziToast.show({
timeout: 3000,
color: '#eb4359',
messageColor: '#FFF',
message: "* 贈品為必選項目",
position: 'center',
progressBar: false,
progressBarEasing: 'ease',
});
return false;
}
if($(".warning").text().length > 0 ){
return false;
}
}
if( $("#options .control-group[data-max-qty]").length ){
var r = true;
$("#options .control-group[data-max-qty]").each(function( index ) {
var option_ckb_id = $(this).data("option-id") || 0;
if( option_ckb_id ) {
r = checkCheckboxOptionQtyLimition(option_ckb_id);
if( r == false ) return false;
}
});
if( r == false ) return false;
}
$('#button_add_price').attr("disabled","disabled");
$('.icon-spinner').removeClass('hidden');
$("input[name='product_id']").attr("value", 3699);
$( ".alert-danger" ).remove();
// **修正:收集表單數據並過濾重複的加價購商品**
var formData = $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea,.cart input[name=\'promption_id\'], .well-lg input[type=\'checkbox\']:checked, .well-lg input[type=\'radio\']:checked, .well-lg select[name^=\'buy_together_qty_\'], .well-lg input[name^=\'add_price_options_\']');
// 收集所有有規格的加價購商品
var optionsProductKeys = [];
formData.filter('input[name^="add_price_options_"]').each(function() {
var optionKey = $(this).attr('name').replace('add_price_options_', '');
// 提取原始的 product_id-buy_together_id 部分 (去除時間戳)
var parts = optionKey.split('-');
if (parts.length >= 2) {
var originalKey = parts[0] + '-' + parts[1];
optionsProductKeys.push(originalKey);
}
});
// 過濾表單數據,移除重複的無規格版本
var filteredData = formData.filter(function() {
if ($(this).attr('name') === 'add_price[]') {
var value = $(this).val();
// 檢查這個值是否在有規格的商品列表中
if (optionsProductKeys.includes(value)) {
console.log('過濾掉重複的無規格加價購商品:', value);
return false; // 排除這個元素
}
}
return true; // 保留這個元素
});
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: filteredData,
dataType: 'json',
success: function(json) {
//alert(json['addpr']);
$('.icon-spinner').addClass('hidden');
$('#button_add_price').removeAttr("disabled", "disabled");
$( ".error" ).remove();
$( ".alert" ).remove();
if (json['error']) {
if (json['error']['option']) {
$(".alert-error").remove();
var error_option_msg = 0;
for (i in json['error']['option']) {
error_option_msg = json['error']['option'][i];
if( is.not.desktop() ) {
$('#option-' + i).after('' + json['error']['option'][i] + '
');
} else {
$('#option-' + i).after('' + json['error']['option'][i] + ''); } } if( error_option_msg ) { iziToast.show({ timeout: 3000, color: '#eb4359', messageColor: '#FFF', message: error_option_msg, position: 'center', progressBar: false, progressBarEasing: 'ease', }); } } if (json['error']['buy_together']) { for (j in json['error']['buy_together']) { $('#error_buy_togther').after('' + json['error']['buy_together'][j] + ''); } } } if (json['success']) { try { gaTrackMultiPixelsAddToCart("AddToCart"); } catch (e) { } try { gaTrackProductAddToCart(); } catch (e) { } var qty = 1; if($(".cart select[name='quantity']").length){ qty = $(".cart select[name='quantity'] option:selected").val(); } else { qty = $(".cart input[name='quantity']").val(); } var product_price = qty * 440; global_quuid = QUUID(); product_price = Number(product_price); if( isNaN(product_price) ) { product_price = 0; } fbq('track', 'AddToCart', { content_name: '[85-130cm] 質感皮革拼接彈性吊帶 #Taurus金牛座', content_ids: ['3699'], content_type: 'product', value: product_price, currency: 'TWD' }, {eventID: global_quuid + "ccc"}); $(".ck_buy_tgr[data-bt-price]:checked").each(function(index) { var bt_price = parseFloat($(this).data("bt-price")); var bt_pname = $(this).data("bt-pname"); var pro_brand = $(this).attr("data-brand"); var pro_category_path = $(this).attr("data-category-path"); var bt_value = $(this).val().split('-'); var bt_product_id = bt_value[0]; var qty = 1; var product_price = qty * bt_price; global_quuid = QUUID(); product_price = Number(product_price); if( isNaN(product_price) ) { product_price = 0; } if ( typeof bt_pname !== 'undefined' ) { fbq('track', 'AddToCart', { content_name: bt_pname, content_ids: [bt_product_id], content_type: 'product', value: product_price, currency: 'TWD' }, {eventID: global_quuid + "ccc"}); } gecommProductToCart.product_id = bt_product_id; gecommProductToCart.quantity = qty; gecommProductToCart.product_name = bt_pname; gecommProductToCart.price = bt_price; gecommProductBrand_cyntelli = pro_brand; gecommProductCategoryPath = pro_category_path; }); setTimeout(function(){ window.location.href = "https://littleuniverse.freestore.tw/cart"; }, 1500); } if( is.not.desktop() ) { if (json['error']) { $('html, body').animate({ scrollTop: $('#options').offset().top }, 'slow'); } } } }); return false; } function init_review(){ $('#review .pagination a').each(function( index ) { var href = $(this).attr("href"); $(this).attr("href", "javascript:void(0);return false;"); $(this).attr("data-href", href); }); $('#review .pagination a').click(function() { var link = $(this).attr("data-href"); $('').insertBefore($('#review')); $('#review').fadeOut('slow'); $('#review').load(link, function() { init_review(); $('#review-spin-wait').remove(); $('#review').fadeIn('slow'); }); return false; }); } function isFacebookApp() { var ua = navigator.userAgent || navigator.vendor || window.opera; return (ua.indexOf("FBAN") > -1) || (ua.indexOf("FBAV") > -1); } function numberWithCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } function changeImageProductVariation(product_option_value_id, option_id) { document.getElementById('option-value-' + product_option_value_id).checked = true; $("#option-" + option_id + ".control-group .option-image").removeClass("selected"); $("#option-value-" + product_option_value_id).closest(".option-image").addClass("selected"); var optid = option_id; update_saleprice_based_select_options(optid); return false; } function update_saleprice_based_select_options(optid) { var ori_prices = $("#price-price-block .product-sell-price").data("content"); var ori_prices_label = $("#price-price-block .product-sell-price").text(); var ori_prices_prefix = ori_prices_label.replace(/[0-9,]/g,""); var total_saleprices = ori_prices; var saleprices_flag = 0; // 原價也要跟著規格價差變動 var ori_old_prices = $("#price-price-block .price-old").data("content") || 0; var total_oldprices = parseInt(ori_old_prices); $("#options .control-group").find(".controls").each(function( index ) { var selected = $(this).find("select option[value]:selected"); if( selected && selected != undefined ){ var prefix = $(selected).data("prefix"); var price = $(selected).data("price"); if( prefix && prefix != undefined ){ if( price && price != undefined ){ switch(prefix){ case "=": saleprices_flag = 1; total_saleprices = price; total_oldprices = price; break; } } } } }); $("#options .control-group").find(".controls").each(function( index ) { var selected = $(this).find("select option[value]:selected"); if( selected && selected != undefined ){ var prefix = $(selected).data("prefix"); var price = $(selected).data("price"); if( prefix && prefix != undefined ){ if( price && price != undefined ){ switch(prefix){ case "+": saleprices_flag = 1; total_saleprices = parseInt(total_saleprices) + parseInt(price); total_oldprices = parseInt(total_oldprices) + parseInt(price); break; case "-": saleprices_flag = 1; total_saleprices = parseInt(total_saleprices) - parseInt(price); total_oldprices = parseInt(total_oldprices) - parseInt(price); break; } } } } }); $("#options .control-group").find("input[type='checkbox']:checked").each(function() { var $this = $(this); var prefix = $this.data("prefix"); var price = parseInt($this.data("price")) || 0; var qty = 1; var $qtyInput = $this.closest('label').find('.multicheck-options'); if($qtyInput.length) { qty = parseInt($qtyInput.val()) || 1; } if(price > 0) { saleprices_flag = 1; switch(prefix) { case "=": total_saleprices = price * qty; total_oldprices = price * qty; break; case "+": total_saleprices += price * qty; total_oldprices += price * qty; break; case "-": total_saleprices -= price * qty; total_oldprices -= price * qty; break; } } }); $("#options .control-group").find("input[type='radio']:checked").each(function() { var $this = $(this); var prefix = $this.data("prefix"); var price = parseInt($this.data("price")) || 0; if(price > 0) { saleprices_flag = 1; switch(prefix) { case "=": total_saleprices = price; total_oldprices = price; break; case "+": total_saleprices += price; total_oldprices += price; break; case "-": total_saleprices -= price; total_oldprices -= price; break; } } }); if( saleprices_flag ) { if( total_saleprices < 1 ) { total_saleprices = 0; } if( total_oldprices < 1 ) { total_oldprices = 0; } //$("#price-price-block .price-old").hide(); $("#price-price-block .product-sell-price").text(ori_prices_prefix + numberWithCommas(total_saleprices)); // 更新原價顯示(原價 + 規格價差) if( ori_old_prices > 0 ) { $("#price-price-block .price-old").text(ori_prices_prefix + numberWithCommas(total_oldprices)); } } else { ori_prices = $("#price-price-block .product-sell-price").data("content"); total_saleprices = $("#price-price-block .product-sell-price").text(); total_saleprices = total_saleprices.replace(/[\D.]/,""); if( ori_prices != total_saleprices ) { $("#price-price-block .price-old").show(); $("#price-price-block .product-sell-price").text(ori_prices_prefix + numberWithCommas(ori_prices)); } // 還原原價顯示 if( ori_old_prices > 0 ) { $("#price-price-block .price-old").text(ori_prices_prefix + numberWithCommas(ori_old_prices)); } } $("#price-price-block").hide(); $("#price-price-block").fadeIn(2000); load_free_present(); } function changeRadioProductVariation(product_option_value_id, option_id) { document.getElementById('option-value-' + product_option_value_id).checked=true; $("#option-" + option_id + ".control-group label.radio").removeClass("opton-selected"); $("#option-" + option_id + ".control-group label.radio #option-value-" + product_option_value_id).closest("label.radio").addClass("opton-selected"); var optid = $("#option-value-" + product_option_value_id).closest('.control-group').attr('id').replace('option-', ''); update_saleprice_based_select_options(optid); return false; } function updateMobileGalleryForOption(imageUrl) { if(!window.productSwiper) return; var zoomImg = $("#image-additional li").find("img[src='"+imageUrl+"']").parents("a").attr("href"); var index = -1; $('#mobile-product-gallery .swiper-slide img').each(function(i) { if($(this).attr('src') === zoomImg) { index = i; return false; } }); if(index === -1) { var imageName = imageUrl.split('/').pop(); $('#mobile-product-gallery .swiper-slide img').each(function(i) { var currentSrc = $(this).attr('src'); if(currentSrc && currentSrc.indexOf(imageName) !== -1) { index = i; return false; } }); } if(index === -1) { $('#mobile-product-gallery .swiper-slide img').each(function(i) { var currentSrc = $(this).attr('src').split('/').pop(); var thumbSrc = imageUrl.split('/').pop(); if(currentSrc === thumbSrc) { index = i; return false; } }); } if(index !== -1) { window.productSwiper.slideTo(index); } else { console.log("找不到匹配的圖片: " + imageUrl); } } function init_inline(){ loadCSS("https://cdnjs.cloudflare.com/ajax/libs/hint.css/1.2.1/hint.min.css"); if (typeof stop_custom_variation_style === 'undefined') { loadCSS("https://storage.freestore.tw/css/catalog/product_variation_option_custom.241101.css?=1777227807"); } loadCSS("https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.css"); getScript("https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.js", function() { initMobileProductGallery(); }); getScript("https://cdn.jsdelivr.net/npm/jquery.nice-number@2.1.0/dist/jquery.nice-number.min.js",function(){ $("#options .multicheck-options").niceNumber({'autoSize':false, onDecrement: function ($currentInput, amount, settings) { if (amount < 1) { $currentInput.val(1); } var opt_val_ta = $currentInput.closest("label.checkbox").attr("for"); $("#" + opt_val_ta).prop("checked", true); $("#" + opt_val_ta).closest("label.checkbox").addClass("opton-selected"); var data_option_id = $("#" + opt_val_ta).closest("[data-option-id]").data("option-id"); checkCheckboxOptionQtyLimition(data_option_id); }, onIncrement: function ($currentInput, amount, settings) { var opt_val_ta = $currentInput.closest("label.checkbox").attr("for"); $("#" + opt_val_ta).prop("checked", true); $("#" + opt_val_ta).closest("label.checkbox").addClass("opton-selected"); var data_option_id = $("#" + opt_val_ta).closest("[data-option-id]").data("option-id"); checkCheckboxOptionQtyLimition(data_option_id); } }); $("#options label.checkbox").find("input[type='checkbox']").change(function() { var checked_state = $(this).is(':checked'); if( checked_state ) { $(this).closest("label.checkbox").addClass("opton-selected"); $(this).closest("label.checkbox").find(".multicheck-options").val(1); } else { $(this).closest("label.checkbox").removeClass("opton-selected"); $(this).closest("label.checkbox").find(".multicheck-options").val(0); } }); $("#options").fadeIn("slow"); }); //20220113 Fix 購物圖片選項 點選圖片同步選取選項 if($(".option-image").length){ $(".option-image").find("a").click(function(){ $(this).parents(".option-image").find("input[id^='option-value-']").attr('checked','checked'); }); } //20210510 Add 選項連動商品圖 單選切換連動圖 $(".changeImage label.radio").click(function(){ if($(".changeImage input[type='radio']:checked")||$(".changeImage select option:selected")){ var optionImage = []; $(".changeImage").each(function(i){ if($(this).find("input[type='radio']:checked").length&&$(this).find("input[type='radio']:checked").val()){ optionImage[i] = []; optionImage[i][0] = $(this).attr("id").replace("option-",""); optionImage[i][1] = $(this).find("input[type='radio']:checked").val(); } if($(this).find("select option:selected").length&&$(this).find("select option:selected").val()){ optionImage[i] = []; optionImage[i][0] = $(this).attr("id").replace("option-",""); optionImage[i][1] = $(this).find("select option:selected").val(); } }); $.ajax({ url: 'index.php?route=product/product_options/povToPoi', type: 'POST', dataType: 'html', data: { pid:$("#product_id").val(),optionImage:optionImage}, beforeSend: function() { }, success: function(json) { $("#image-additional li a").each(function(){ if($(this).hasClass("zoom-active")){ $(this).removeClass('zoom-active'); } }); if(json){ $("#image-additional li").find("img[src='"+json+"']").parents("a").addClass("zoom-active").trigger("mouseenter"); // 220608 Fix 商品連動圖手機版大圖不會變化問題 if( is.not.desktop() ){ var zoomImg = $("#image-additional li").find("img[src='"+json+"']").parents("a").attr("href"); $('#zoom1').attr("src", zoomImg); $('#zoom1').data("hd-image", zoomImg); $('#zoom1').data("zoom-image", zoomImg); if(window.productSwiper) { updateMobileGalleryForOption(zoomImg || json); } // 停留選項 // $('html,body').animate({ // scrollTop:$("#options").offset().top-70 // }, "show"); } }else{ $("#image-additional li a").eq(0).addClass("zoom-active").trigger("mouseenter"); // 220608 Fix 商品連動圖手機版大圖不會變化問題 if( is.not.desktop() ){ var zoomImg = $("#image-additional li a").eq(0).attr("href"); $('#zoom1').attr("src", zoomImg); $('#zoom1').data("hd-image", zoomImg); $('#zoom1').data("zoom-image", zoomImg); if(window.productSwiper) { window.productSwiper.slideTo(0); } // 停留選項 // $('html,body').animate({ // scrollTop:$("#options").offset().top-70 // }, "show"); } } }, error: function(xhr, ajaxOptions, thrownError) { //alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); } }); //20210510 Add 選項連動商品圖 下拉選單切換連動圖 $(".changeImage select").change(function(){ if($(".changeImage input[type='radio']:checked")||$(".changeImage select option:selected")){ var optionImage = []; $(".changeImage").each(function(i){ if($(this).find("input[type='radio']:checked").length&&$(this).find("input[type='radio']:checked").val()){ optionImage[i] = []; optionImage[i][0] = $(this).attr("id").replace("option-",""); optionImage[i][1] = $(this).find("input[type='radio']:checked").val(); } if($(this).find("select option:selected").length&&$(this).find("select option:selected").val()){ optionImage[i] = []; optionImage[i][0] = $(this).attr("id").replace("option-",""); optionImage[i][1] = $(this).find("select option:selected").val(); } }); $.ajax({ url: 'index.php?route=product/product_options/povToPoi', type: 'POST', dataType: 'html', data: { pid:$("#product_id").val(),optionImage:optionImage}, beforeSend: function() { }, success: function(json) { $("#image-additional li a").each(function(){ if($(this).hasClass("zoom-active")){ $(this).removeClass('zoom-active'); } }); if(json){ $("#image-additional li").find("img[src='"+json+"']").parents("a").addClass("zoom-active").trigger("mouseenter"); // 220608 Fix 商品連動圖手機版大圖不會變化問題 if( is.not.desktop() ){ var zoomImg = $("#image-additional li").find("img[src='"+json+"']").parents("a").attr("href"); $('#zoom1').attr("src", zoomImg); $('#zoom1').data("hd-image", zoomImg); $('#zoom1').data("zoom-image", zoomImg); if(window.productSwiper) { updateMobileGalleryForOption(zoomImg || json); } // 停留選項 // $('html,body').animate({ // scrollTop:$("#options").offset().top-70 // }, "show"); } }else{ $("#image-additional li a").eq(0).addClass("zoom-active").trigger("mouseenter"); // 220608 Fix 商品連動圖手機版大圖不會變化問題 if( is.not.desktop() ){ var zoomImg = $("#image-additional li a").eq(0).attr("href"); $('#zoom1').attr("src", zoomImg); $('#zoom1').data("hd-image", zoomImg); $('#zoom1').data("zoom-image", zoomImg); if(window.productSwiper) { window.productSwiper.slideTo(0); } // 停留選項 // $('html,body').animate({ // scrollTop:$("#options").offset().top-70 // }, "show"); } } }, error: function(xhr, ajaxOptions, thrownError) { //alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); } }); setTimeout(function(){ if( is.not.desktop() ){ $('#zoom1').attr("src", $('#zoom1').data("hd-image")); } }, 1500); getScript("https://static.addtoany.com/menu/page.js",function(){ }); $('#myModal').on('show.bs.modal', function (e) { if( is.not.desktop() ) { $('.button-cart').removeClass("hidden animated fadeInUp").addClass("animated fadeOutDown"); $('.button-quick-checkout').removeClass("hidden animated fadeInUp").addClass("animated fadeOutDown"); } setTimeout(function() { $.datepicker.setDefaults({ dateFormat: 'yy/mm/dd' }); $('.modal .date').datepicker({ dateFormat: 'yy/mm/dd', changeMonth: true, changeYear: true, minDate: 0, beforeShow: function(input, inst) { $('#ui-datepicker-div').css({ 'z-index': 2147483647, 'position': 'relative' }); }, onSelect: function(dateText, inst) { var value = $(this).val(); if (value) { var parts = value.split('/'); if (parts.length === 3 && parts[2].length === 4) { $(this).val(parts[2] + '/' + parts[0] + '/' + parts[1]); } } } }).on('change blur', function() { var value = $(this).val(); if (value) { var parts = value.split('/'); if (parts.length === 3 && parts[2].length === 4) { $(this).val(parts[2] + '/' + parts[0] + '/' + parts[1]); } } }); $('.modal .datetime').datetimepicker({ dateFormat: 'yy-mm-dd', timeFormat: 'HH:mm', controlType: 'select', minDate: 0, beforeShow: function(input, inst) { $('#ui-datepicker-div').css({ 'z-index': 2147483647, 'position': 'relative' }); $('.ui-timepicker-div').css({ 'z-index': 2147483647, 'position': 'relative' }); }, onClose: function(dateText, inst) { $('#ui-datepicker-div').css('z-index', ''); $('.ui-timepicker-div').css('z-index', ''); } }); $('').appendTo('head'); }, 100); }); $('').appendTo('head'); $("#myModal").on("hidden.bs.modal",function(e){ if( is.not.desktop() ) { $('.button-cart').removeClass("fadeOutDown").addClass("animated fadeInUp"); $('.button-quick-checkout').removeClass("fadeOutDown").addClass("animated fadeInUp"); } }); $(".ck_buy_tgr").prop("checked", false); if( is.not.desktop() ){ $("#maincontent").removeClass("span9").addClass("span12"); $("#main-image").attr("style", "padding:0px;overflow:hidden;min-height:initial;"); if( !isFacebookApp() && !disabledScroll ) { setTimeout(function(){ $('.button-cart').addClass("animated fadeOutDown"); $('.button-quick-checkout-mobile').addClass("animated fadeOutDown"); }, 1500); } $('#zoom1').attr("src", $('#zoom1').data("hd-image")); } if( is.desktop() ){ $("#zoom1").imagesLoaded( function() { $("#main-defer-image").remove(); $("#main-image").removeClass("hidden"); $("#zoom1").elevateZoom({ easing : false, gallery:'image-additional', cursor: 'pointer', galleryActiveClass: "zoom-active", zoomWindowFadeIn: 0, zoomWindowFadeOut: 0, zoomWindowWidth: 0, zoomWindowHeight: 0, lensSize: 0, borderSize: 0, lensFadeIn: 0, lensFadeOut: 0, tint:false, tintColour:'#fff', tintOpacity:0, scrollZoom : false, imageCrossfade: false, loadingIcon: "", responsive: true }); var ez = $('#zoom1').data('elevateZoom'); ez.refresh(); $(".zoomContainer").remove(); $("#image-additional-container").show(); }); } $("#image-additional a").hover(function() { $(".zoomContainer").remove(); var image_pop_url = $(this).data("zoom-image"); var image_pop_title = $(this).attr("title"); $("#main-image .fancybox-product").attr("href", image_pop_url); $("#main-image .fancybox-product, #main-image .fancybox-product img").attr("alt", image_pop_title); $("#main-image .fancybox-product, #main-image .fancybox-product img").attr("title", image_pop_title); }); var productStockAPI = "index.php?route=product/product/getStockQuantity&product_id=3699&jsoncallback=?"; setInterval(function(){ $.getJSON( productStockAPI, {format: "json"}) .done(function(data) { if(!is.empty(data.quantity)) { $("#product-stock-current").html(data.quantity); }}); }, 60000); // Load options_list_window $('input[name^="add_price"]').bind('click', function() { $('#cart_options_list').html("
'); } } setTimeout(function() { $('.error').fadeOut(); }, 2000); }else{ // 多規格支援:為每個規格選擇創建唯一標識符 var optionName = json['options_name'].replace(/;/g, ' '); var timestamp = Date.now(); // 使用時間戳確保唯一性 var uniqueId = prod_id + '-' + bytr_id + '-' + timestamp; // 唯一標識符 var optionHtml = '
';
optionHtml += '
';
// 插入HTML到對應的位置
$('#lg_option_' + prod_id + '-' + bytr_id).append(optionHtml);
setTimeout(function() {
var newSelect = $('select[name="buy_together_qty_' + uniqueId + '"]');
if (newSelect.length > 0) {
validateBuyTogetherTotal(prod_id + '-' + bytr_id, newSelect[0]);
}
}, 100);
// 檢查是否已經有多規格選擇,如果有就取消原本的勾選
var multiSpecCount = $('#lg_option_' + prod_id + '-' + bytr_id + ' div[data-option-item]').length;
if(multiSpecCount > 0) {
// 有多規格選擇,取消原本的勾選避免重複
$('#add_price_' + prod_id + '-' + bytr_id).prop('checked', false);
} else {
// 只有單一規格選擇,保持勾選
$('#add_price_' + prod_id + '-' + bytr_id).prop('checked', true);
}
$('#cart_options_list').html("");
$('#myModal').modal('hide');
$('.modal-backdrop').remove();
if( is.not.desktop() ) {
$('.button-cart').removeClass("fadeOutDown").addClass("animated fadeInUp");
$('.button-quick-checkout').removeClass("fadeOutDown").addClass("animated fadeInUp");
}
// 模擬點擊主商品選項
const mainProductContainer = document.getElementById('options'); // 主商品的容器 ID
if (mainProductContainer) {
const selectedOptions = mainProductContainer.querySelectorAll('.radio.opton-selected');
selectedOptions.forEach(option => {
option.click(); // 模擬點擊
});
}
}
}
});
});
var oldURL = document.referrer;
$.fancybox.defaults.hash = false;
$("[data-fancybox='images']").fancybox({
afterLoad: function(instance, slide) {
if( $(".fancybox-container").length > 1 ) {
$(".fancybox-container").not(':first').remove();
}
},
afterClose: function() {
window.onhashchange = function(e) {
if( window.location.hash.indexOf("#gallery") !=-1 ){
e.preventDefault();
$.fancybox.close();
if( is.not.empty(oldURL) ) {
window.onhashchange = null;
window.location.href = oldURL;
}
return false;
}
}
}
});
if( is.desktop() ) {
$("#main-image .fancybox-product").click(function(e) {
e.stopPropagation();
e.preventDefault();
var $links = $("[data-fancybox='gallery']");
var zoom_active_index = $("#image-additional li > a.zoom-active").parent().index();
$.fancybox.open( $links, { hash : false }, zoom_active_index );
if( $(".fancybox-container").length > 1 ) {
$(".fancybox-container").not(':first').remove();
}
return false;
});
$("#image-additional a").click(function(e) {
e.stopPropagation();
e.preventDefault();
var $links = $("[data-fancybox='gallery']");
var zoom_active_index = $("#image-additional li > a.zoom-active").parent().index();
$.fancybox.open( $links, { hash : false }, zoom_active_index );
if( $(".fancybox-container").length > 1 ) {
$(".fancybox-container").not(':first').remove();
}
return false;
});
} else {
$("#main-image .fancybox-product").click(function(e) {
e.stopPropagation();
e.preventDefault();
var $links = $("[data-fancybox='gallery']");
$.fancybox.open( $links, { hash : false }, 0 );
if( $(".fancybox-container").length > 1 ) {
$(".fancybox-container").not(':first').remove();
}
return false;
});
$("[data-fancybox='gallery']").fancybox({ hash : false });
}
$("a.screenshot").hover(function(e){
this.t = this.title;
this.title = "";
var c = (this.t != "") ? "';
// 創建獨立的加價購項目(使用唯一標識符)
optionHtml += "";
optionHtml += "";
optionHtml += '';
optionHtml += '
';
optionHtml += '';
optionHtml += '
';
optionHtml += '' + optionName + '
'; optionHtml += '" + this.t : ""; this.rel = this.rel.replace(" noopener noreferrer nofollow",""); $("body").append("
"+ c +"
限時優惠%D 天 %H:%M:%S
'));
}
});
}, 2000);
}
if( is.not.desktop() ) {
$("#zoom1").imagesLoaded( function() { $("#main-defer-image").remove(); $("#main-image").removeClass("hidden"); $("#image-additional-container").show(); });
$("#image-additional").find(".zoom-active").removeClass("zoom-active");
var lastScroll = 0;
var lastDirection = 0;
var down = true;
var delta = 0;
$(window).on("scroll", function() {
if( $("#myModal").css('display') == 'block' ) {
$('.button-cart').removeClass("hidden animated fadeInUp").addClass("animated fadeOutDown");
$('.button-quick-checkout').removeClass("hidden animated fadeInUp").addClass("animated fadeOutDown");
}
if( isFacebookApp() || disabledScroll ) {
$('.button-cart').removeClass("hidden animated fadeOutDown");
$('.button-quick-checkout-mobile').removeClass("hidden animated fadeOutDown");
return;
}
var scroll = $(this).scrollTop();
down = scroll > lastScroll;
delta = Math.abs(lastScroll - scroll);
lastScroll = scroll;
if( (down!=lastDirection) ) {
if( down == true ) {
if( delta > 15 ) {
$('.button-cart').removeClass("hidden animated fadeInUp").addClass("animated fadeOutDown");
$('.button-quick-checkout-mobile').removeClass("hidden animated fadeInUp").addClass("animated fadeOutDown");
}
} else {
$('.button-cart').removeClass("hidden animated fadeOutDown").addClass("animated fadeInUp");
$('.button-quick-checkout-mobile').removeClass("hidden animated fadeOutDown").addClass("animated fadeInUp");
}
}
lastDirection = down;
});
if( isFacebookApp() || disabledScroll ) {
$(window).unbind("scroll");
$('#button-cart').attr("class","button-cart button pull-left");
$('#button-quick-checkout').attr("class","btn btn-default btn-block button-quick-checkout button-quick-checkout-mobile");
$('#button-cart').show();
$('#button-quick-checkout').show();
}
}
$("#options").on('change', 'input[type="checkbox"], .nice-number input', 'input[type="radio"]', function() {
var optid = $(this).closest('.control-group').attr('id').replace('option-','');
update_saleprice_based_select_options(optid);
});
$("#options .multicheck-options").on('change', function() {
var optid = $(this).closest('.control-group').attr('id').replace('option-','');
update_saleprice_based_select_options(optid);
});
$(document).on('click', '.nice-number button', function() {
var optid = $(this).closest('.control-group').attr('id').replace('option-','');
update_saleprice_based_select_options(optid);
});
}
function loadislogin() {
$("#login_n").hide();
}
function loadpromotionlist() {
var html = "";
$.ajax({
url: "index.php?route=product/product/getLoggedInPromotionList&product_id=3699",
type: "post",
dataType: "json",
success: function(json) {
if(json.length > 0){
html += '促銷活動
'; html += '- ';
for(var i = 0; i < json.length; i++) {
html += ' ';
}
html += '
| 尺寸 | "; cloudmaker_value += cloudmaker_header; /*cloudmaker_value += "台南小西門 | "; cloudmaker_value += "東區旗艦 | "; cloudmaker_value += "勤美誠品 | "; cloudmaker_value += "信義誠品 | ";*/ cloudmaker_value += "
"; //cloudmaker_value += "總筆數 : "+ cjson.length +" 筆"; //cloudmaker_value += "
"; $('#cloudmaker_stock').append(cloudmaker_value); }else{ console.log("cloudmaker_stock(L26177A000125) is null"); } } }, error: function(xhr, ajaxOptions, thrownError) { //console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); } function load_options(){ $.ajax({ url: 'index.php?route=product/product_options&key=3699&type=prod', dataType: 'html', beforeSend: function() { }, success: function(html) { $('#options').html(html); }, error: function(xhr, ajaxOptions, thrownError) { //alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); } function checkCheckboxOptionQtyLimition(option_id){ try { var max_qty = parseInt($("#options #option-" + option_id).data("max-qty")) || 0; var min_qty = parseInt($("#options #option-" + option_id).data("min-qty")) || 0; var option_checkbox_name = $("#options #option-" + option_id).data("option-name"); if( max_qty || min_qty ) { $("#options #option-" + option_id).find(".alert-error").remove(); var qty_total_chk = 0; $("#options #option-" + option_id).find("input[type='text'].CheckboxOptionQtyGroup").each(function( index ) { var pov_id = $(this).data("pov-id"); if( $("#option-value-" + pov_id).is(':checked') ) { qty_total_chk += parseInt($(this).val()) || 0; } }); if( max_qty ) { if( qty_total_chk > max_qty ) { $("#options #option-" + option_id + " > label.control-label").after("
選項 總數量 限制最多 " + max_qty + " 項!請重新修改數量" );
return false;
}
}
if( min_qty ) {
if( qty_total_chk < min_qty ) {
$("#options #option-" + option_id + " > label.control-label").after("
選項 總數量 至少須 " + min_qty + " 項!請重新修改數量" );
return false;
}
}
}
} catch (e) {}
return true;
}
var a2a_config = a2a_config || {};
a2a_config.locale = "zh-TW";
try {
var main_image_element = document.getElementById("main-defer-image");
main_image_element = function() {
main_image_element.style.opacity = 1;
main_image_element.style.transition = "all 0.2s";
};
}
catch (e) { }
function load_free_present(){
var pid = 3699;
//抓取產品的價格
/*var price = $('#price-price-block .price-normal').attr('data-content');*/
var currentPriceText = $('#price-price-block .product-sell-price').text();
var price = currentPriceText.replace(/[^0-9]/g, '');
if(!price) price = $('#price-price-block .price-new').attr('data-content');
var qty = $('input[name="quantity"]').val();
if(!qty) qty = $('select[name="quantity"]').val();
$.ajax({
url: 'index.php?route=module/free_present',
type: 'post',
dataType: 'html',
data: {pid:pid, price:price, qty:qty},
beforeSend: function() {
},
success: function(html) {
$('#free_present_list').html(html);
$('#free_present_list').show();
},
error: function(xhr, ajaxOptions, thrownError) {
//console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
function load_buy_together(){
var pid = 3699;
var price = $('#price-price-block .price-normal').attr('data-content');
if(!price) price = $('#price-price-block .price-new').attr('data-content');
var qty = $('input[name="quantity"]').val();
if(!qty) qty = $('select[name="quantity"]').val();
$.ajax({
url: 'index.php?route=module/buy_together',
type: 'post',
dataType: 'html',
data: {pid:pid, price:price, qty:qty},
beforeSend: function() {
},
success: function(html) {
$('#buy_together_list').html(html);
$('#buy_together_list').show();
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
function initMobileProductGallery() {
if (is.not.desktop() && $('#mobile-product-gallery-container').length) {
$('#mobile-product-gallery-container').show();
var invalidSlides = [];
$('#mobile-product-thumbs .swiper-slide img').each(function() {
var $img = $(this);
if (!$img.attr('src') || $img.attr('src') === '') {
// 保存需要移除的索引或URL
invalidSlides.push($img.closest('.swiper-slide').index());
}
});
// 同時從主幻燈片和縮圖幻燈片中移除無效幻燈片
for (var i = invalidSlides.length - 1; i >= 0; i--) {
var index = invalidSlides[i];
$('#mobile-product-gallery .swiper-slide').eq(index).remove();
$('#mobile-product-thumbs .swiper-slide').eq(index).remove();
}
// 修改縮圖 Swiper 配置
var thumbsSwiper = new Swiper('#mobile-product-thumbs', {
spaceBetween: 8,
slidesPerView: 'auto',
freeMode: true,
watchSlidesProgress: true,
centerInsufficientSlides: true,
touchRatio: 1,
slideToClickedSlide: true,
height: 80, // 明確設定高度
resizeObserver: true // 啟用尺寸變更監聽
});
// 修改主要 Swiper 配置
var mainSwiper = new Swiper('#mobile-product-gallery', {
slidesPerView: 1,
spaceBetween: 10,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
autoHeight: true,
updateOnImagesReady: true,
thumbs: {
swiper: thumbsSwiper
},
resizeObserver: true, // 啟用尺寸變更監聽
on: {
init: function() {
this.updateAutoHeight(10); // 初始化時更新高度
},
imagesReady: function() {
this.updateAutoHeight(10);
},
slideChange: function() {
this.updateAutoHeight(10);
var activeIndex = this.activeIndex;
if (thumbsSwiper && thumbsSwiper.slides) {
thumbsSwiper.params.speed = 0;
thumbsSwiper.slideTo(activeIndex);
setTimeout(function() {
$('#mobile-product-thumbs .swiper-slide').removeClass('swiper-slide-active');
$('#mobile-product-thumbs .swiper-slide').eq(activeIndex).addClass('swiper-slide-active');
thumbsSwiper.params.speed = 300;
}, 10);
}
}
}
});
thumbsSwiper.on('click', function() {
if (typeof thumbsSwiper.clickedIndex !== 'undefined') {
mainSwiper.slideTo(thumbsSwiper.clickedIndex);
}
});
// 隱藏原始元素
$("#main-defer-image").hide();
$("#main-image").hide();
$("#image-additional-container").hide();
window.productSwiper = mainSwiper;
window.thumbsSwiper = thumbsSwiper;
// 增加 CSS 修復
$('').appendTo('head');
// 監聽視窗大小變化
$(window).on('resize', function() {
if (mainSwiper) {
mainSwiper.updateAutoHeight(10);
}
// 確保縮圖高度正確
$('.mobile-product-thumbs').css('height', '80px');
});
// 確保第一張圖片被選中
setTimeout(function() {
$('#mobile-product-thumbs .swiper-slide').eq(0).addClass('swiper-slide-active');
// 額外觸發一次更新以確保高度計算正確
mainSwiper.updateAutoHeight(10);
thumbsSwiper.update();
}, 100);
}
}
function validateBuyTogetherTotal(productKey, selectElement) {
var qty = parseInt($(selectElement).val()) || 0;
// 找到對應的 checkbox/radio 元素
var targetInput = $("input[value='" + productKey + "']");
// 取得數量限制
var maxQty = targetInput.data('restrict-amount') || 99;
// 計算同一個加價購商品的所有規格選擇器總數量
var totalQty = 0;
var containerId = '#lg_option_' + productKey;
// 計算所有多規格選擇器的數量
$(containerId + ' select[name^="buy_together_qty_"]').each(function() {
totalQty += parseInt($(this).val()) || 0;
});
// 加上一般數量選擇器的數量(如果存在)
var generalSelect = $('select[name="buy_together_qty_' + productKey + '"]');
if (generalSelect.length > 0) {
totalQty += parseInt(generalSelect.val()) || 0;
}
// 檢查是否超過限制
if (totalQty > maxQty) {
var productName = targetInput.data('bt-pname') || '商品';
var errorMessage = productName + ' 數量上限為 ' + maxQty;
var buyTogetherLabel = $('#lab_addprice_' + productKey);
var titleElement = buyTogetherLabel.closest('.well-lg').find('p b').first();
if (titleElement.length > 0) {
// 清除舊錯誤訊息並顯示新錯誤
titleElement.find('.quantity-error').remove();
titleElement.append('' + errorMessage + '');
}
// 設置全域錯誤標記,阻擋加入購物車
window.buyTogetherHasError = true;
return false;
} else {
// 數量符合限制,清除該區塊的錯誤訊息
$('.quantity-error').remove(); // 清除所有錯誤訊息
// 保存當前數值
$(selectElement).attr('data-previous-value', qty);
// 檢查是否還有其他錯誤
checkBuyTogetherErrors();
}
// 處理勾選/取消勾選邏輯
if (totalQty > 0) {
targetInput.prop('checked', true);
$(selectElement).addClass("highlight");
if(targetInput.attr('type') === 'radio') {
var radio_name = targetInput.attr('name');
$("input[name='" + radio_name + "']:not([value='" + productKey + "'])").each(function() {
$(this).prop('checked', false);
var other_value = $(this).val();
$("select[data-product-key='" + other_value + "']").val(0).removeClass("highlight");
});
}
} else {
targetInput.prop('checked', false);
$(selectElement).removeClass("highlight");
}
}
// 檢查是否還有錯誤的函數
function checkBuyTogetherErrors() {
var hasErrors = $('.quantity-error').length > 0;
window.buyTogetherHasError = hasErrors;
}
// 初始化錯誤標記
window.buyTogetherHasError = false;


