$(function() {
var category_array = new Array('schwinger','Katzen')
/* Show and Hide Products of the selected category */
function ShowCategory(buttonIDX) {
var length = category_array.length,
element = null;
for (var i = 0; i < length; i++) {
element = category_array[i];
/* Hide all menues */
if (i != buttonIDX && buttonIDX >= 0) {
$('.cat_'+element).hide();
} else {
$('.cat_'+element).show('slow');
}
}
}
/* click trigger for category navigation */
$('.catbtn').on("click", function() {
var catidx = $(this).attr('idx');
$('.catbtn').removeClass('MiniShopActiveCat'); /* remove all active state classes */
$(this).addClass('MiniShopActiveCat'); /* add active state to clicked item */
catbtn = $(this).attr('idxname');
if (!$(this).attr('idxname')) {
$('.cattext').show();
} else {
$('.cattext').hide();
}
ShowCategory(catidx); /* Show cat */
})
$(".anzfeld").each( function() {
$(this).before('<div class="IncButton">+</div>');
$(this).after('<div class="DecButton">-</div>');
});
$(".IncButton, .DecButton, .td_price").on("click", function() {
var $button = $(this);
var oldValue = $button.parent().find("input").val();
var CartValue = $button.parent().find("input").attr('MiniShopPrice');
CartValue = parseFloat(CartValue).toFixed(2);
if ($button.text() == "+") {
var newVal = parseFloat(oldValue) + 1;
UpdateCart(CartValue,'positive')
} else if ($button.text() == "-") {
// Don't allow decrementing below zero
if (oldValue > 0) {
var newVal = parseFloat(oldValue) - 1;
UpdateCart(CartValue,'negative')
} else {
newVal = 0;
}
} else {
var newVal = parseFloat(oldValue) + 1;
UpdateCart(CartValue,'positive')
}
$button.parent().find(".anzfeld").val(newVal);
/* Saving Cookie with ordered value */
var ProductID = $button.parent().find("input").attr('idx');
$.cookie('Minishop_Prod_'+ProductID, $button.parent().find("input").val(), { path: '/' });
});
function roundCHF(value){
return (Math.ceil(value*20)/20).toFixed(2);
}
function UpdateCart(cartValue,posneg) {
var ActualCartValue = $('.MiniShopSubTotal').html();
ActualCartValue = parseFloat(ActualCartValue).toFixed(2);
var ActualProductsTotalValue = $('.MiniShopProductsTotal').html();
ActualProductsTotalValue = parseFloat(ActualProductsTotalValue);
var ActualShippingCostsValue = $('.MiniShopShippingCosts').html();
ActualShippingCostsValue = parseFloat(ActualShippingCostsValue).toFixed(2);
var CartValue = parseFloat(cartValue).toFixed(2)
if (posneg == 'positive') {
var NewCartValue = parseFloat(ActualCartValue)+parseFloat(CartValue);
NewCartValue = NewCartValue.toFixed(2);
NewProductsTotalValue = ActualProductsTotalValue + 1;
} else {
var NewCartValue = ActualCartValue-CartValue;
NewCartValue = NewCartValue.toFixed(2);
NewProductsTotalValue = ActualProductsTotalValue - 1;
}
var NewShippingCostsValue = parseFloat(NewCartValue)+parseFloat(ActualShippingCostsValue)
NewShippingCostsValue = NewShippingCostsValue.toFixed(2);
/* Update cart subtotal and total */
if (NewCartValue < 0) { NewCartValue = "0.00"; }
$('.MiniShopSubTotal').html(NewCartValue);
$.cookie('Minishop_SubTotal', NewCartValue, { path: '/' }); /* Save cookie with subtotal */
if (NewShippingCostsValue == ActualShippingCostsValue) { NewShippingCostsValue = "0.00"; }
$('.MiniShopTotal').html(NewShippingCostsValue);
$.cookie('Minishop_Total', NewShippingCostsValue, { path: '/' }); /* Save cookie with total */
/* Update Products Total text - Es sind xxx artikel im Warebkorb */
if (NewProductsTotalValue > 1) {
$('.MiniShopProductsTotalPrefix').html('Es sind ');
} else if (NewProductsTotalValue == 0) {
$('.MiniShopProductsTotalPrefix').html('Es sind ');
} else {
$('.MiniShopProductsTotalPrefix').html('Es ist ');
}
if (NewProductsTotalValue < 0) { NewProductsTotalValue = "0"; }
$('.MiniShopProductsTotal').html(NewProductsTotalValue);
$.cookie('Minishop_ProductsTotal', NewProductsTotalValue, { path: '/' }); /* Save cookie with products total */
}
/* Initially hide all category entries and show first category entries */
ShowCategory(0); /* Show first category entry */
/*$('.ContentRight').hide(); Hide the right area, so more space for shop */
$('.desc_all').hide(); /* Hide all Product Descriptions */
}); /* Document ready end */
function DeleteBasket() {
$('.anzfeld').each(function() {
var idx = $(this).attr('idx');
$(this).val('0');
$('.MiniShopSubTotal').html('0.00');
$('.MiniShopTotal').html('0.00');
$('.MiniShopShippingCosts').html('15.00')
$('.MiniShopProductsTotal').html('0');
$.cookie('Minishop_Prod_'+idx, '', { path: '/' });
$.cookie('Minishop_SubTotal', '', { path: '/' });
$.cookie('Minishop_Total', '', { path: '/' });
$.cookie('Minishop_ProductsTotal', '', { path: '/' });
})
}
Es sind "0 Artikel " im Warenkorb
Zwischensumme: CHF 0.00
Versandkosten: CHF 15.00
Total: CHF 0.00