templates/frontend/index/js/shopping-cart.html.twig line 1

Open in your IDE?
  1. <script type="text/javascript">
  2.     function refreshShoppingCart() {
  3.         $.ajax({
  4.             url : '{{ path('app_frontend_cart_shopping_cart') }}',
  5.             method: "GET",
  6.             success: function (data) {
  7.                 let $shoppingCart = $('#shopping-cart');
  8.                 $.each(data.areas, function(index, area) {
  9.                     let template = getShoppingCartItem(area);
  10.                     $shoppingCart.find('.product-area').append(template);
  11.                 });
  12.                 refreshCartTotalAndItemCount();
  13.             }
  14.         });
  15.     }
  16.     function refreshCartTotalAndItemCount() {
  17.         $.ajax({
  18.             url : '{{ path('app_frontend_cart_refresh-cart-total-and-item-count') }}',
  19.             method: "GET",
  20.             success: function (data) {
  21.                 let $shoppingCart = $('#shopping-cart');
  22.                 let $itemsInCart = $('#itemsInCart');
  23.                 $shoppingCart.find('.total-price >.price').text(data.cartTotal);
  24.                 $shoppingCart.find('.cart-heading').find('.count-cart-item').text(data.areaCount);
  25.                 $itemsInCart.text(data.areaCount);
  26.                 toggleToCartBtn(data.areaCount);
  27.             }
  28.         });
  29.     }
  30.     function toggleToCartBtn(elementCount) {
  31.         let $toCartBtn = $('#to-cart-btn');
  32.         if (elementCount > 0) {
  33.             $toCartBtn.removeClass('disabled');
  34.         }
  35.         if (elementCount === 0) {
  36.             $toCartBtn.addClass('disabled');
  37.         }
  38.     }
  39.     function getShoppingCartItem(area) {
  40.         let template = `<div class="product-item" data-uuid="`+area.uuid+`">
  41.         <div class="product-detail">
  42.             <div class="item-wrapper">
  43.                 <span class="product-name">`+area.name+`</span>
  44.                 <div class="item-wrapper">
  45.                     <span class="product-variation">
  46.                         <span><strong>{{ 'app.measurements'|trans }}</strong>: <span class="width">`+area.width+`</span> x <span class="height">`+area.height+`</span> mm</span><br>
  47.                         <span><strong>{{ 'app.contractDuration'|trans }}</strong>: <span class="minDuration">`+area.minDuration+`</span> {{ 'app.months'|trans }}</span><br>
  48.                         <span><strong>{{ 'app.unitPricePerYear'|trans }}</strong>: <span class="pricePerYear">`+area.pricePerYear+`</span> {{ 'app.currency_sign'|trans }}</span>`
  49.         if (area.withinSetup) {
  50.             template+= `<br><span><strong>{{ 'app.productionAndSetup'|trans }}</strong>: <span class="setupPrice">`+area.setupPrice+`</span> {{ 'app.currency_sign'|trans }}</span>`;
  51.         }
  52.         template+= `</span>
  53.                         </div>
  54.                             <div class="item-wrapper">
  55.                                 <span class="product-price">
  56.                                     <span class="pricePerPeriod">`+area.pricePerPeriod+`</span> {{ 'app.currency_sign'|trans }}
  57.                                 </span>
  58.                         </div>
  59.                     </div>
  60.                 </div>
  61.                 <div class="cart-edit">
  62.                     <div class="item-wrapper d-flex mr--5 align-items-center">
  63.                         <button type="button" class="delete-cart removeFromCartButton" data-uuid-area="`+area.uuid+`">
  64.                             <i class="fal fa-trash"></i>
  65.                         </button>
  66.                     </div>
  67.                 </div>
  68.             </div>`;
  69.         return template;
  70.     }
  71. </script>