From 65543e6617b9804b74ab0eb2c9d7374506661a95 Mon Sep 17 00:00:00 2001 From: Gustavo Luigi Date: Thu, 1 Sep 2022 17:40:34 +0200 Subject: [PATCH 1/2] . --- content/master.blade.php | 15 ++++++++++ content/pages/checkout.blade.php | 47 +------------------------------- 2 files changed, 16 insertions(+), 46 deletions(-) diff --git a/content/master.blade.php b/content/master.blade.php index ef7b867..2bfc3b9 100644 --- a/content/master.blade.php +++ b/content/master.blade.php @@ -129,6 +129,7 @@ for(let i = 0; i < quantitys.length; i++) { quantityOfProducts += Number(quantitys[i]); } $('#count-products-in-bag').text(quantityOfProducts); $('#list-products-in-bag').html(''); + if(typeof updateProducts === "function") $('#list-products').html(''); totalPrice = 0; if(objProducts.length > 0) { let ids = objProducts.map(obj => obj.id); @@ -158,18 +159,32 @@ ${formatter.format(item.data_fields.preis)} `; $('#list-products-in-bag').append(elementProduct); + if(typeof updateProducts === "function") $('#list-products').append(elementProduct); }); $('#total-price').text(formatter.format(totalPrice)); + if(typeof updateProducts === "function") $('#total-checkout-price').text(formatter.format(totalPrice)); }); $('#count-products-in-bag').show(); $('#list-products-in-bag').parent().parent().parent().parent().parent().find('.modal-footer').show(); $('#total-price').parent().parent().parent().show(); $('#no-products').hide(); + if(typeof updateProducts === "function"){ + $('#form-section').show(); + $('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').show(); + $('#total-checkout-price').parent().parent().parent().show(); + $('#no-products-in-checkout').hide(); + } }else { $('#count-products-in-bag').hide(); $('#list-products-in-bag').parent().parent().parent().parent().parent().find('.modal-footer').hide(); $('#total-price').parent().parent().parent().hide(); $('#no-products').show(); + if(typeof updateProducts === "function"){ + $('#form-section').hide(); + $('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').hide(); + $('#total-checkout-price').parent().parent().parent().hide(); + $('#no-products-in-checkout').show(); + } } $('#total-price').text(formatter.format(totalPrice)); let productId = $('meta[name="product-id"]').attr('content'); diff --git a/content/pages/checkout.blade.php b/content/pages/checkout.blade.php index 1c0781f..87400f5 100644 --- a/content/pages/checkout.blade.php +++ b/content/pages/checkout.blade.php @@ -300,58 +300,13 @@ utilsScript: "{{storage('assets/libs/intl-tel-input/js/utils.min.js')}}", }); - function updateProducts(){ - $('#list-products').html(''); - if(objProducts.length > 0) { - let ids = objProducts.map(obj => obj.id); - $.get($('meta[name="get-contents"]').attr('content')+"/"+ids.join(","), function(response, status){ - response.contents.forEach(function(item){ - let objProductInfo = objProducts.find(obj => obj.id == item.id); - let elementProduct = ` - - - - - - ${item.title} -
- sofort verfügbar -
- - - - ${formatter.format(item.data_fields.preis)} - `; - $('#list-products').append(elementProduct); - }); - $('#total-checkout-price').text(formatter.format(totalPrice)); - }); - $('#form-section').show(); - $('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').show(); - $('#total-checkout-price').parent().parent().parent().show(); - $('#no-products-in-checkout').hide(); - }else { - $('#form-section').hide(); - $('#list-products').parent().parent().parent().parent().parent().find('.modal-footer').hide(); - $('#total-checkout-price').parent().parent().parent().hide(); - $('#no-products-in-checkout').show(); - } - } + function updateProducts(){} $(window).on('load', function(){ - updateProducts(); $('#anfrage').submit(function(){ objProducts = []; updateProductsInLocalStorage(); }); - $(document).on('click', '.btn-remove-product', function(){ updateProducts(); }); - $(document).on('change', '.select-quantity', function(){ updateProducts(); }); }); @stop From 57844a980470148ed0b0765f79c0027f27908149 Mon Sep 17 00:00:00 2001 From: Gustavo Luigi Date: Thu, 1 Sep 2022 19:12:48 +0200 Subject: [PATCH 2/2] add cart list --- content/master.blade.php | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/content/master.blade.php b/content/master.blade.php index 2bfc3b9..934162c 100644 --- a/content/master.blade.php +++ b/content/master.blade.php @@ -1,6 +1,7 @@ + @insert("content.includes.meta") @insert("content.includes.css") @@ -115,6 +116,38 @@ + + @yield('content') @insert("content.includes.footer") @insert("content.includes.scripts") @@ -210,11 +243,29 @@ if(index == -1) objProducts.push({id: productId, quantity: 1}); updateProductsInLocalStorage(); } + function isJson(str) { + try { JSON.parse(str); } + catch (e) { return false; } + return true; + } $(window).on('load', function(){ if(localStorage.getItem("dismiss-message") == 1) $('.alert-dismissible').remove(); else $('.alert-dismissible').show(); $('#btn-close-message').click(function(){ localStorage.setItem("dismiss-message", 1); }); if(localStorage.getItem("products") != null) objProducts = JSON.parse(localStorage.getItem("products")); + let urlPath = window.location.pathname; + let code = urlPath.split("/"); + code = code[code.length-1]; + let productLink = atob(code); + if(isJson(productLink)){ + if(objProducts.length > 0) $('#modal-confirm-product-replacement').modal('show'); + else $('#modal-confirm-addition-of-products').modal('show'); + } + $('.btn-confirm-product-link').click(function(){ + objProducts = JSON.parse(productLink); + updateProductsInLocalStorage(); + window.location.replace($('meta[name="checkout"]').attr('content')); + }); updateProductsInLocalStorage(); $(document).on('click', '.btn-remove-product', function(){ let productId = $(this).attr('data-id');