<script type="text/javascript">
function refreshShoppingCart() {
$.ajax({
url : '{{ path('app_frontend_cart_shopping_cart') }}',
method: "GET",
success: function (data) {
let $shoppingCart = $('#shopping-cart');
$.each(data.areas, function(index, area) {
let template = getShoppingCartItem(area);
$shoppingCart.find('.product-area').append(template);
});
refreshCartTotalAndItemCount();
}
});
}
function refreshCartTotalAndItemCount() {
$.ajax({
url : '{{ path('app_frontend_cart_refresh-cart-total-and-item-count') }}',
method: "GET",
success: function (data) {
let $shoppingCart = $('#shopping-cart');
let $itemsInCart = $('#itemsInCart');
$shoppingCart.find('.total-price >.price').text(data.cartTotal);
$shoppingCart.find('.cart-heading').find('.count-cart-item').text(data.areaCount);
$itemsInCart.text(data.areaCount);
toggleToCartBtn(data.areaCount);
}
});
}
function toggleToCartBtn(elementCount) {
let $toCartBtn = $('#to-cart-btn');
if (elementCount > 0) {
$toCartBtn.removeClass('disabled');
}
if (elementCount === 0) {
$toCartBtn.addClass('disabled');
}
}
function getShoppingCartItem(area) {
let template = `<div class="product-item" data-uuid="`+area.uuid+`">
<div class="product-detail">
<div class="item-wrapper">
<span class="product-name">`+area.name+`</span>
<div class="item-wrapper">
<span class="product-variation">
<span><strong>{{ 'app.measurements'|trans }}</strong>: <span class="width">`+area.width+`</span> x <span class="height">`+area.height+`</span> mm</span><br>
<span><strong>{{ 'app.contractDuration'|trans }}</strong>: <span class="minDuration">`+area.minDuration+`</span> {{ 'app.months'|trans }}</span><br>
<span><strong>{{ 'app.unitPricePerYear'|trans }}</strong>: <span class="pricePerYear">`+area.pricePerYear+`</span> {{ 'app.currency_sign'|trans }}</span>`
if (area.withinSetup) {
template+= `<br><span><strong>{{ 'app.productionAndSetup'|trans }}</strong>: <span class="setupPrice">`+area.setupPrice+`</span> {{ 'app.currency_sign'|trans }}</span>`;
}
template+= `</span>
</div>
<div class="item-wrapper">
<span class="product-price">
<span class="pricePerPeriod">`+area.pricePerPeriod+`</span> {{ 'app.currency_sign'|trans }}
</span>
</div>
</div>
</div>
<div class="cart-edit">
<div class="item-wrapper d-flex mr--5 align-items-center">
<button type="button" class="delete-cart removeFromCartButton" data-uuid-area="`+area.uuid+`">
<i class="fal fa-trash"></i>
</button>
</div>
</div>
</div>`;
return template;
}
</script>