diff --git a/assets/js/methods.js b/assets/js/methods.js
index 0a7450d..81110c4 100644
--- a/assets/js/methods.js
+++ b/assets/js/methods.js
@@ -1,34 +1,35 @@
-function getInfoFromSelectedProduct(){
+function getInfoFromSelectedProduct() {
let ids = objProducts.map(obj => obj.id);
- return $.get($('meta[name="get-contents"]').attr('content')+"/"+ids.join(","));
+ return $.get($('meta[name="get-contents"]').attr('content') + "/" + ids.join(","));
}
-function numberToEuroFormat(number){
- let formatter = new Intl.NumberFormat('de', {style: 'currency', currency: 'EUR'});
+function numberToEuroFormat(number) {
+ let formatter = new Intl.NumberFormat('de', { style: 'currency', currency: 'EUR' });
return formatter.format(number);
}
-function getQuantityOfProducts(){
+function getQuantityOfProducts() {
let quantitys = objProducts.map(obj => obj.quantity);
let quantityOfProducts = 0;
- for(let i = 0; i < quantitys.length; i++) { if(Number.isInteger(Number(quantitys[i]))) quantityOfProducts += Number(quantitys[i]); }
+ for (let i = 0; i < quantitys.length; i++) { if (Number.isInteger(Number(quantitys[i]))) quantityOfProducts += Number(quantitys[i]); }
return quantityOfProducts;
}
-function getProductInfo(productInfo){
+function getProductInfo(productInfo) {
let objProduct = objProducts.find(obj => obj.id == productInfo.id);
return jQuery.extend({}, objProduct, productInfo);
}
-function calculatePrice(objProduct){
+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;
+ 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){
+function createProductElement(objProduct) {
+ console.log(objProduct);
calculatePrice(objProduct);
let elementProduct = `
@@ -37,7 +38,7 @@ function createProductElement(objProduct){
- ${objProduct.title}
+ ${objProduct.title}
sofort verfügbar
@@ -47,73 +48,73 @@ function createProductElement(objProduct){
|
${numberToEuroFormat(objProduct.calc_preis)}`;
- if(objProduct.calc_preis != objProduct.preis) elementProduct += `
+ if (objProduct.calc_preis != objProduct.preis) elementProduct += `
- ${(((objProduct.calc_preis-objProduct.preis)*100)/objProduct.preis).toFixed(2)} %
+ ${(((objProduct.calc_preis - objProduct.preis) * 100) / objProduct.preis).toFixed(2)} %
`;
- elementProduct += ` |
+ elementProduct += `
`;
return elementProduct;
}
-function addToBag(productId){
+function addToBag(productId) {
let objProductInfo = objProducts.find(obj => obj.id == productId);
let index = objProducts.indexOf(objProductInfo);
- if(index == -1) objProducts.push({id: productId, quantity: 1});
+ if (index == -1) objProducts.push({ id: productId, quantity: 1 });
updateProductsInLocalStorage();
}
function isJson(str) {
try { JSON.parse(str); }
- catch(e) { return false; }
+ catch (e) { return false; }
return true;
}
-function isEncoded(str){
+function isEncoded(str) {
try { atob(str); }
- catch(e) { return false; }
+ catch (e) { return false; }
return true;
}
-function hasCartCode(){
+function hasCartCode() {
let urlPath = window.location.pathname;
let code = urlPath.split("/");
- code = code[code.length-1];
- if(isEncoded(code)){
+ code = code[code.length - 1];
+ if (isEncoded(code)) {
let productLink = atob(code);
- if(isJson(productLink)) return true;
+ if (isJson(productLink)) return true;
}
return false;
}
-function getCartCode(){
+function getCartCode() {
let urlPath = window.location.pathname;
let code = urlPath.split("/");
- code = code[code.length-1];
- if(isEncoded(code)) return atob(code);
+ code = code[code.length - 1];
+ if (isEncoded(code)) return atob(code);
return null;
}
-function updateProductsInLocalStorage(){
+function updateProductsInLocalStorage() {
localStorage.setItem("products", JSON.stringify(objProducts));
$('#count-products-in-bag').text(getQuantityOfProducts());
$('#list-products-in-bag').html('');
totalPrice = 0;
- if(objProducts.length > 0){
- getInfoFromSelectedProduct().done(function(response, status){
- response.contents.forEach(function(product){
+ if (objProducts.length > 0) {
+ getInfoFromSelectedProduct().done(function (response, status) {
+ response.contents.forEach(function (product) {
let objProduct = getProductInfo(product);
objProduct = calculatePrice(objProduct);
- totalPrice += objProduct.calc_preis*objProduct.quantity;
+ totalPrice += objProduct.calc_preis * objProduct.quantity;
let elementProduct = createProductElement(objProduct);
$('#list-products-in-bag').append(elementProduct);
});
$('#total-price').text(numberToEuroFormat(totalPrice));
- }).fail(function(response){
+ }).fail(function (response) {
$('.cart-link').hide();
$(".btn-share").hide();
$('#count-products-in-bag').hide();
@@ -131,8 +132,8 @@ function updateProductsInLocalStorage(){
$('#no-products').hide();
$('#cart-error').hide();
$('#modal-buttons').show();
-
- cartLink = window.location.origin+'/'+btoa(JSON.stringify(objProducts));
+
+ cartLink = window.location.origin + '/' + btoa(JSON.stringify(objProducts));
$('.cart-link').val(cartLink);
shareData = {
title: "Share cart list",
@@ -140,9 +141,9 @@ function updateProductsInLocalStorage(){
url: cartLink,
};
-
- }else{
+
+ } else {
$('.cart-link').hide();
$(".btn-share").hide();
$('#count-products-in-bag').hide();
@@ -153,19 +154,19 @@ function updateProductsInLocalStorage(){
$('#modal-buttons').hide();
}
let productId = $('meta[name="product-id"]').attr('content');
- if(productId != undefined){
+ if (productId != undefined) {
let objProduct = objProducts.find(obj => obj.id == productId);
- if(objProduct == undefined) {
+ if (objProduct == undefined) {
$('#btn-add-to-bag').show();
$('#btn-show-bag').hide();
- if(objProducts.length > 0) $('#btn-check-out').parent().hide();
+ if (objProducts.length > 0) $('#btn-check-out').parent().hide();
else $('#btn-check-out').parent().show();
}
else {
$('#btn-add-to-bag').hide();
$('#btn-show-bag').show();
$('#btn-check-out').parent().hide();
- $('#count-items-in-bag').html(objProduct.quantity+``);
+ $('#count-items-in-bag').html(objProduct.quantity + ``);
}
}
}
\ No newline at end of file