diff --git a/assets/js/methods.js b/assets/js/methods.js
index d4a8fed..29e7c59 100644
--- a/assets/js/methods.js
+++ b/assets/js/methods.js
@@ -20,7 +20,16 @@ function getProductInfo(productInfo){
return jQuery.extend(objProduct, productInfo);
}
+function calculatePrice(objProduct){
+ objProduct.calc_preis = objProduct.preis;
+ if(objProduct.quantity >= 5) objProduct.calc_preis = objProduct.preis_5;
+ if(objProduct.quantity >= 10) objProduct.calc_preis = objProduct.preis_10;
+ if(Number(objProduct.quantity) >= Number(objProduct.module_pro_palette)) objProduct.calc_preis = objProduct.preis_palette;
+ return objProduct;
+}
+
function createProductElement(objProduct){
+ calculatePrice(objProduct);
let elementProduct = `
@@ -33,16 +42,20 @@ function createProductElement(objProduct){
sofort verfügbar
-
+
|
- ${numberToEuroFormat(objProduct.preis)} |
+
+ ${numberToEuroFormat(objProduct.calc_preis)}`;
+ if(objProduct.calc_preis != objProduct.preis) elementProduct += `
+
+
+ ${(((objProduct.calc_preis-objProduct.preis)*100)/objProduct.preis).toFixed(2)} %
+ `;
+ elementProduct += ` |
`;
return elementProduct;
}
diff --git a/assets/js/script.js b/assets/js/script.js
index 4a52cd0..c5b761a 100644
--- a/assets/js/script.js
+++ b/assets/js/script.js
@@ -80,25 +80,35 @@ $(window).on('load', function(){
}
});
- $(document).on('change', '.select-quantity', function(){
+ $(document).on('input', '.select-quantity', function(){
let quantity = $(this).val();
let productId = $(this).attr('data-id');
let objProductInfo = objProducts.find(obj => obj.id == productId);
let index = objProducts.indexOf(objProductInfo);
objProducts[index].quantity = quantity;
- localStorage.setItem("products", JSON.stringify(objProducts));
-
+ calculatePrice(objProductInfo);
+ let elementPrice = `
+ ${numberToEuroFormat(objProductInfo.calc_preis)}`;
+ if(objProductInfo.calc_preis != objProductInfo.preis) elementPrice += `
+
+
+ ${(((objProductInfo.calc_preis-objProductInfo.preis)*100)/objProductInfo.preis).toFixed(2)} %
+ `;
+ $(this).parent().parent().find('.product-price').html(elementPrice);
$('#count-products-in-bag').text(getQuantityOfProducts());
getInfoFromSelectedProduct().done(function(response, status){
totalPrice = 0;
response.contents.forEach(function(product){
let objProduct = getProductInfo(product);
- totalPrice += objProduct.preis*objProduct.quantity;
+ calculatePrice(objProduct);
+ totalPrice += objProduct.calc_preis*objProduct.quantity;
});
$('#total-price').text(numberToEuroFormat(totalPrice));
if(typeof updateProducts === "function") $('#total-checkout-price').text(numberToEuroFormat(totalPrice));
});
-
productId = $('meta[name="product-id"]').attr('content');
if(productId != undefined){
let objProduct = objProducts.find(obj => obj.id == productId);
@@ -115,7 +125,7 @@ $(window).on('load', function(){
$('#count-items-in-bag').html(objProduct.quantity+``);
}
}
-
+ localStorage.setItem("products", JSON.stringify(objProducts));
});
$('#btn-copy-cart-link').click(function(){
$('.cart-link').select();