Merge branch 'master' of code.areya.de:Areya/areya-energy

master
Benjamin Völkl 2022-09-01 19:14:11 +02:00
commit 7aba06cc51
2 changed files with 67 additions and 46 deletions

View File

@ -1,6 +1,7 @@
<!doctype html>
<html lang="{{str_replace('_', '-', app()->getLocale())}}">
<head>
<meta name="checkout" content="{{url('/checkout')}}">
<meta name="get-contents" content="{{url('/contents/all')}}">
@insert("content.includes.meta")
@insert("content.includes.css")
@ -115,6 +116,38 @@
<button type="button" class="btn-close" id="btn-close-message" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
</div>
<div class="modal fade bd-example-modal-sm" id="modal-confirm-addition-of-products" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Você gostaria de colocar os produtos do link no carrinho?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-confirm-product-link" data-bs-dismiss="modal">Ja</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Nein</button>
</div>
</div>
</div>
</div>
<div class="modal fade bd-example-modal-sm" id="modal-confirm-product-replacement" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Você possui produtos no carrinho, deseja descartar e colocar os produtos do link no carrinho?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-confirm-product-link" data-bs-dismiss="modal">Ja</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Nein</button>
</div>
</div>
</div>
</div>
@yield('content')
@insert("content.includes.footer")
@insert("content.includes.scripts")
@ -129,6 +162,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 +192,32 @@
<td class="align-middle text-end">${formatter.format(item.data_fields.preis)}</td>
</tr>`;
$('#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');
@ -195,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');

View File

@ -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 = `
<tr>
<td class="text-start">
<img class="rounded img-fluid" src="https://picsum.photos/120/120">
</td>
<td class="text-start">
<span class="fs-5">${item.title}</span>
<br>
<small class="text-success">sofort verfügbar</small>
<br>
<select class="form-select form-select-sm select-quantity" data-id="${item.id}" style="width:125px;" aria-label="Default select example">`;
for(let i = 1; i <= 5; i++){
if(objProductInfo.quantity == i) elementProduct += `<option selected value="${i}">Anzahl: ${i}</option>`;
else elementProduct += `<option value="${i}">Anzahl: ${i}</option>`;
}
elementProduct += `
</select>
<button data-id="${item.id}" class="btn-remove-product text-muted small text-decoration-none" style="padding: 0; border: none; background: transparen;">Löschen</button>
</td>
<td class="align-middle text-end">${formatter.format(item.data_fields.preis)}</td>
</tr>`;
$('#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(); });
});
</script>
@stop