app/template/default/Product/list.twig line 1

Open in your IDE?
  1. {#
  2. This file is part of EC-CUBE
  3. Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  4. http://www.ec-cube.co.jp/
  5. For the full copyright and license information, please view the LICENSE
  6. file that was distributed with this source code.
  7. #}
  8. {% extends 'default_frame.twig' %}
  9. {% set body_class = 'product_page' %}
  10. {% block javascript %}
  11. <script>
  12.     eccube.productsClassCategories = {
  13. {% for Product in pagination %}
  14. "{{ Product.id|escape('js') }}": {{ class_categories_as_json(Product)|raw }}{% if loop.last == false %}, {% endif %}
  15. {% endfor %}
  16. };
  17. function orderbySubmit (orderId) {
  18.     $('#orderby').val(orderId);
  19.     $('#pageno').val(1);
  20.     $("#form1").submit();
  21. }
  22. $(document).mouseup(function(e)
  23. {
  24.     var container = $(".orderbyLabel");
  25.     // if the target of the click isn't the container nor a descendant of the container
  26.     if (!container.is(e.target) && container.has(e.target).length === 0)
  27.     {
  28.         $('.dropdownOrderbyList').css('visibility', 'hidden');
  29.     }
  30. });
  31. $(function() {
  32. var url_string = location.href;
  33. var url = new URL(url_string);
  34. var product_name = url.searchParams.get("name");
  35. var details_title = "商品一覧";
  36. if (product_name)
  37.     details_title = product_name + "の商品一覧";
  38. details_title = `<span>${details_title}</span>`
  39. $('#list_name').html(details_title);
  40. if (url.href.indexOf('orderby') < 0) {
  41.     $('#orderby > div:first-child input').prop('checked', true);
  42.     $('.orderbyLabel').text('並び替え');
  43.     $('.dropdownOrderbyList > li:first-child').addClass('active');
  44. } else {
  45.     var orderid = url.searchParams.get("orderby");
  46.     $(`.dropdownOrderbyList__item#orderby__${orderid}`).addClass('active');
  47.     var orderLabel = $(`.dropdownOrderbyList__item#orderby__${orderid}`).text();
  48.     $('.orderbyLabel').text(orderLabel);
  49. }
  50. // 表示件数を変更
  51. $('.disp-number').change(function() {
  52.     var dispNumber = $(this).val();
  53.     $('#disp_number').val(dispNumber);
  54.     $('#pageno').val(1);
  55.     $("#form1").submit();
  56. });
  57. // sp 並び順を変更
  58. $('.orderbyLabel').on('click', function (e) {
  59.     e.preventDefault();
  60.     const element = document.querySelector('.dropdownOrderbyList');
  61.     const visibility = element.style.visibility;
  62.     if (visibility == 'visible') {
  63.         $('.dropdownOrderbyList').css('visibility', 'hidden');
  64.     } else {
  65.         $('.dropdownOrderbyList').css('visibility', 'visible');
  66.     }
  67. });
  68. // 並び順を変更
  69. $('.order-by input[name="orderby"]').change(function() {
  70.     var orderBy = $(this).val();
  71.     $('#orderby').val(orderBy);
  72.     $('#pageno').val(1);
  73.     $("#form1").submit();
  74. });
  75. $('.add-cart').on('click', function(e) {
  76.     var $form = $(this).parents('li').find('form');
  77.     // 個数フォームのチェック
  78.     var $quantity = $form.parent().find('.quantity');
  79.     if ($quantity.val() < 1) {
  80.         $quantity[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  81.         setTimeout(function() {
  82.             loadingOverlay('hide');
  83.         }, 100);
  84.         return true;
  85.     } else {
  86.         $quantity[0].setCustomValidity('');
  87.     }
  88.     e.preventDefault();
  89.     $.ajax({
  90.         url: $form.attr('action'),
  91.         type: $form.attr('method'),
  92.         data: $form.serialize(),
  93.         dataType: 'json',
  94.         beforeSend: function(xhr, settings) {
  95.             // Buttonを無効にする
  96.             $('.add-cart').prop('disabled', true);
  97.         }
  98.     }).done(function(data) {
  99.         // レスポンス内のメッセージをalertで表示
  100.         $.each(data.messages, function() {
  101.             $('#ec-modal-header').text(this);
  102.         });
  103.         $('.ec-modal').show()
  104.         // カートブロックを更新する
  105.         $.ajax({
  106.             url: '{{ url('block_cart') }}',
  107.             type: 'GET',
  108.             dataType: 'html'
  109.         }).done(function(html) {
  110.             $('.ec-headerRole__cart').html(html);
  111.         });
  112.     }).fail(function(data) {
  113.         alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  114.     }).always(function(data) {
  115.         // Buttonを有効にする
  116.         $('.add-cart').prop('disabled', false);
  117.     });
  118. });
  119. });
  120. $('.ec-modal-wrap').on('click', function(e) {
  121. // モーダル内の処理は外側にバブリングさせない
  122. e.stopPropagation();
  123. });
  124. $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  125. $('.ec-modal').hide()
  126. });
  127. </script>
  128. {% endblock %}
  129. {% block main %}
  130.     {% if search_form.category_id.vars.errors|length > 0 %}
  131.         <div class="ec-searchnavRole">
  132.             <p class="errormsg text-danger">{{ 'ご指定のカテゴリは存在しません'|trans }}</p>
  133.         </div>
  134.     {% else %}
  135.         <div class="ec-searchnavRole">
  136.             <div class="ec-searchnavRole__topicpath">
  137.                 <ol class="ec-topicpath">
  138.                     {% if Category %}
  139.                         <li class="ec-topicpath__item">
  140.                             <span>{{ Category }}{{ 'の商品一覧' }}</span>
  141.                         </li>
  142.                     {% else %}
  143.                         <li class="ec-topicpath__item" id="list_name">
  144.                             {#                            <span>{{ subtitle }}{{ 'の商品一覧' }}</span> #}
  145.                         </li>
  146.                     {% endif %}
  147.                 </ol>
  148.             </div>
  149.         </div>
  150.         <div class="ec-blockspliter"></div>
  151.         <div class="ec-searchnavRole ec-searchnavRole-height ec-productListSPSearchNav">
  152.             <form name="form1" id="form1" method="get" action="?">
  153.                 {% for item in search_form %}
  154.                     <input type="hidden" id="{{ item.vars.id }}"
  155.                            name="{{ item.vars.full_name }}"
  156.                            {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %}/>
  157.                 {% endfor %}
  158.             </form>
  159.             <div class="ec-searchnavRole__infospace show-resultPC">
  160.                 {#                {% if pagination.totalItemCount > 0 %} #}
  161.                 {#                    <div class="ec-searchnavRole__actions"> #}
  162.                 {#                        <div class="ec-select"> #}
  163.                 {#                            {{ form_widget(search_form.disp_number, {'id': '', 'attr': {'class': 'disp-number'}}) }} #}
  164.                 {#                        </div> #}
  165.                 {#                    </div> #}
  166.                 {#                {% endif %} #}
  167.                 <span>{{ '並び替え'|trans }}</span>
  168.             </div>
  169.             <div class="ec-searchnavRole__infos ec-spOrderby show-resultSP">
  170.                 <div class="orderbyLabel"></div>
  171.                 <ul class="dropdownOrderbyList">
  172.                     {% for orderitem in OrderList %}
  173.                         <li class="dropdownOrderbyList__item" id="orderby__{{ orderitem.id }}" onclick="orderbySubmit({{ orderitem.id }})">{{ orderitem.name }}</li>
  174.                     {% endfor %}
  175.                 </ul>
  176.             </div>
  177.             <div class="ec-searchnavRole__infos show-resultPC">
  178.                 {{ form_widget(search_form.orderby, {'attr': {'class': 'order-by'}}) }}
  179.             </div>
  180.         </div>
  181.         <div class="ec-blockspliter"></div>
  182.         {% if pagination.totalItemCount > 0 %}
  183.             <div class="ec-role">
  184.                 <div class="ec-newItemRole">
  185.                     <div class="ec-newItemRole__list">
  186.                         {% for Product in pagination %}
  187.                             <div class="ec-newItemRole__listItem">
  188.                                 <a href="{{ url('product_detail', {'id': Product.id}) }}">
  189.                                     <figure>
  190.                                         <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}"
  191.                                              alt="{{ Product.name }}" {% if loop.index > 5 %} loading="lazy"{% endif %}>
  192.                                     </figure>
  193.                                     {% if Product.new_arrival %}
  194.                                         <span class="newitembadge">NEW</span>
  195.                                     {% else %}
  196.                                         <span class="newitembadge" style="background-color: unset;"></span>
  197.                                     {% endif %}
  198.                                     <div>
  199.                                         <p class="ec-newItemRole__listItemTitle">{{ Product.name|trans }}</p>
  200.                                         <p class="ec-newItemRole__listItemPrice">
  201.                                             {% if Product.hasProductClass %}
  202.                                                 {% if Product.getPrice02Min == Product.getPrice02Max %}
  203.                                                     {{ Product.getPrice02IncTaxMin|price }}
  204.                                                 {% else %}
  205.                                                     {{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}
  206.                                                 {% endif %}
  207.                                             {% else %}
  208.                                                 {{ Product.getPrice02IncTaxMin|price }}
  209.                                             {% endif %}{{ '(税込)'|trans }}
  210.                                         </p>
  211.                                     </div>
  212.                                 </a>
  213.                             </div>
  214.                         {% endfor %}
  215.                     </div>
  216.                 </div>
  217.                 {% if pagination.pageCount > 1 %}
  218.                     <div class="ec-blockspliter"></div>
  219.                 {% endif %}
  220.             </div>
  221.             {% if pagination.pageCount > 1 %}
  222.                 <div class="ec-role">
  223.                     <div class="ec-pagerRole ec-newsPagination">
  224.                         {% include "pager.twig" with {'pages': pagination.paginationData} %}
  225.                     </div>
  226.                 </div>
  227.             {% endif %}
  228.             <div class="ec-blockspliter productListSpliter"></div>
  229.             <div class="ec-blockempty"></div>
  230.             <div class="ec-modal">
  231.                 <div class="ec-modal-overlay">
  232.                     <div class="ec-modal-wrap">
  233.                         <span class="ec-modal-close"><span class="ec-icon"><img
  234.                                         src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  235.                         <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  236.                         <div class="ec-modal-box">
  237.                             <div class="ec-role">
  238.                                 <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  239.                                 <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  240.                             </div>
  241.                         </div>
  242.                     </div>
  243.                 </div>
  244.             </div>
  245.         {% endif %}
  246.     {% endif %}
  247. {% endblock %}