templates/application/cart/index.html.twig line 1

Open in your IDE?
  1. {% extends 'application/layout.html.twig' %}
  2. {% block content %}
  3.     <main class="main">
  4.         <div class="breadcrumb">
  5.             <div class="container">
  6.                 <ol class="breadcrumb__list">
  7.                     <li class="breadcrumb__item"><a href="{{ path('home') }}" class="breadcrumb__link">Главная</a></li>
  8.                     <li class="breadcrumb__item active" aria-current="page">Корзина</li>
  9.                 </ol>
  10.             </div>
  11.         </div>
  12.         <div id="cartItems">
  13.             {{ include('application/cart/items.html.twig') }}
  14.         </div>
  15.     </main>
  16. {% endblock %}
  17. {% block scripts %}
  18. <script>
  19.     function initCartItems() {
  20.         $('#clearPromo').click(function () {
  21.             $(this).hide();
  22.             $.ajax({
  23.                 type: "POST",
  24.                 url: '{{ path('clear-promo-ajax') }}',
  25.                 success: function (data) {
  26.                     location.reload();
  27.                 }
  28.             }).fail(function() {
  29.                 alertPopup('Ошибка');
  30.             });
  31.             return false;
  32.         });
  33.         $('#promoForm').submit(function () {
  34.             $.ajax({
  35.                 type: "POST",
  36.                 url: '{{ path('apply-promo-ajax') }}',
  37.                 data: $(this).serialize(),
  38.                 success: function (data) {
  39.                     if (data.success) {
  40.                         //alertPopup('Промокод успешно активирован');
  41.                         /*
  42.                         $('#promoButton').hide();
  43.                         $('#promoAlert').show();
  44.                         $('#clearPromo').show();
  45.                         promo.attr('disabled', 'disabled');
  46.                          */
  47.                         location.reload();
  48.                     } else {
  49.                         alertPopup('Неверный промокод');
  50.                     }
  51.                 }
  52.             }).fail(function() {
  53.                 alertPopup('Ошибка');
  54.             });
  55.             return false;
  56.         });
  57.         $('.addRelatedProduct').click(function () {
  58.             let id = $(this).attr('data-id');
  59.             $.ajax({
  60.                 type: "POST",
  61.                 url: '{{ path('cart-put-ajax') }}',
  62.                 data: {
  63.                     id: id,
  64.                     count: 1
  65.                 },
  66.                 success: function (data) {
  67.                     $('#cartDiv').html(data.cartHtml);
  68.                     $('#cartItems').html(data.itemsHtml);
  69.                     initCartItems();
  70.                     prepareProductBlockCount($('#cartItems'));
  71.                 }
  72.             }).fail(function() {
  73.                 alertPopup('Ошибка');
  74.             })
  75.         });
  76.         $('.cart-quantity').change(function () {
  77.             let id = $(this).attr('data-id');
  78.             let count = $(this).val();
  79.             $.ajax({
  80.                 type: "POST",
  81.                 url: '{{ path('cart-put-ajax') }}',
  82.                 data: {
  83.                     id: id,
  84.                     count: count
  85.                 },
  86.                 success: function (data) {
  87.                     $('#cartDiv').html(data.cartHtml);
  88.                     $('#cartItems').html(data.itemsHtml);
  89.                     initCartItems();
  90.                     prepareProductBlockCount($('#cartItems'));
  91.                 }
  92.             }).fail(function() {
  93.                 alertPopup('Ошибка');
  94.             })
  95.         });
  96.         $('.cart-delete').click(function () {
  97.             let button = $(this);
  98.             let id = button.attr('data-id');
  99.             button.attr('disabled', 'disabled');
  100.             $.ajax({
  101.                 type: "POST",
  102.                 url: '{{ path('cart-delete-ajax') }}',
  103.                 data: {
  104.                     id: id
  105.                 },
  106.                 success: function (data) {
  107.                     $('#cartDiv').html(data.cartHtml);
  108.                     $('#cartItems').html(data.itemsHtml);
  109.                     initCartItems();
  110.                     prepareProductBlockCount($('#cartItems'));
  111.                 }
  112.             }).fail(function() {
  113.                 alertPopup('Ошибка');
  114.             }).always(function() {
  115.                 button.removeAttr('disabled');
  116.             });
  117.             return false;
  118.         });
  119.         $('#draftSave').click(function () {
  120.             let button = $(this);
  121.             button.attr('disabled', 'disabled');
  122.             $.ajax({
  123.                 type: "POST",
  124.                 url: '{{ path('draft-save-ajax') }}',
  125.                 success: function (data) {
  126.                     alertPopup('Черновик сохранен');
  127.                 }
  128.             }).fail(function() {
  129.                 alertPopup('Ошибка');
  130.             }).always(function() {
  131.                 button.removeAttr('disabled');
  132.             });
  133.             return false;
  134.         });
  135.         $('#clearCart').click(function () {
  136.             let button = $(this);
  137.             button.attr('disabled', 'disabled');
  138.             $.ajax({
  139.                 type: "POST",
  140.                 url: '{{ path('cart-clear-ajax') }}',
  141.                 success: function (data) {
  142.                     $('#cartDiv').html(data.cartHtml);
  143.                     $('#cartItems').html(data.itemsHtml);
  144.                     initCartItems();
  145.                     prepareProductBlockCount($('#cartItems'));
  146.                 }
  147.             }).fail(function() {
  148.                 alertPopup('Ошибка');
  149.             }).always(function() {
  150.                 button.removeAttr('disabled');
  151.             });
  152.             return false;
  153.         });
  154.         $('#cartLoadRetail').click(function () {
  155.             let button = $(this);
  156.             button.attr('disabled', 'disabled');
  157.             $.ajax({
  158.                 type: "POST",
  159.                 url: '{{ path('cart-load-retail-ajax') }}',
  160.                 success: function (data) {
  161.                     $('#cartDiv').html(data.cartHtml);
  162.                     $('#cartItems').html(data.itemsHtml);
  163.                     initCartItems();
  164.                     prepareProductBlockCount($('#cartItems'));
  165.                 }
  166.             }).fail(function() {
  167.                 alertPopup('Ошибка');
  168.             }).always(function() {
  169.                 button.removeAttr('disabled');
  170.             });
  171.             return false;
  172.         });
  173.     }
  174.     initCartItems();
  175.     {% if app.request.query.get('changed') %}
  176.     alertPopup('Состав корзины был актуализирован в соответствии с доступными остатками');
  177.     {% endif %}
  178.     {% if app.request.query.get('notInStock') %}
  179.     alertPopup('На складе нет нужного количества товаров');
  180.     {% endif %}
  181.     {% if app.request.query.get('notValid') %}
  182.     alertPopup('Для приема заказа недостаточно информации. Просим Вас обратиться к Вашему менеджеру');
  183.     {% endif %}
  184. </script>
  185. {% endblock %}