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() {
  18.             // 表示件数を変更
  19.             $('.disp-number').change(function() {
  20.                 var dispNumber = $(this).val();
  21.                 $('#disp_number').val(dispNumber);
  22.                 $('#pageno').val(1);
  23.                 $("#form1").submit();
  24.             });
  25.             // 並び順を変更
  26.             $('.order-by').change(function() {
  27.                 var orderBy = $(this).val();
  28.                 $('#orderby').val(orderBy);
  29.                 $('#pageno').val(1);
  30.                 $("#form1").submit();
  31.             });
  32.             $('.add-cart').on('click', function(e) {
  33.                 var $form = $(this).parents('li').find('form');
  34.                 // 個数フォームのチェック
  35.                 var $quantity = $form.parent().find('.quantity');
  36.                 if ($quantity.val() < 1) {
  37.                     $quantity[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  38.                     setTimeout(function() {
  39.                         loadingOverlay('hide');
  40.                     }, 100);
  41.                     return true;
  42.                 } else {
  43.                     $quantity[0].setCustomValidity('');
  44.                 }
  45.                 e.preventDefault();
  46.                 $.ajax({
  47.                     url: $form.attr('action'),
  48.                     type: $form.attr('method'),
  49.                     data: $form.serialize(),
  50.                     dataType: 'json',
  51.                     beforeSend: function(xhr, settings) {
  52.                         // Buttonを無効にする
  53.                         $('.add-cart').prop('disabled', true);
  54.                     }
  55.                 }).done(function(data) {
  56.                     // レスポンス内のメッセージをalertで表示
  57.                     $.each(data.messages, function() {
  58.                         $('#ec-modal-header').html(this);
  59.                     });
  60.                     $('.ec-modal').show()
  61.                     // カートブロックを更新する
  62.                     $.ajax({
  63.                         url: '{{ url('block_cart') }}',
  64.                         type: 'GET',
  65.                         dataType: 'html'
  66.                     }).done(function(html) {
  67.                         $('.ec-headerRole__cart').html(html);
  68.                     });
  69.                 }).fail(function(data) {
  70.                     alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  71.                 }).always(function(data) {
  72.                     // Buttonを有効にする
  73.                     $('.add-cart').prop('disabled', false);
  74.                 });
  75.             });
  76.         });
  77.         $('.ec-modal-wrap').on('click', function(e) {
  78.             // モーダル内の処理は外側にバブリングさせない
  79.             e.stopPropagation();
  80.         });
  81.         $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  82.             $('.ec-modal').hide()
  83.         });
  84.     </script>
  85. {% endblock %}
  86. {% block main %}
  87.     {% if search_form.category_id.vars.errors|length > 0 %}
  88.         <div class="ec-searchnavRole">
  89.             <p class="errormsg text-danger">{{ 'ご指定のカテゴリは存在しません'|trans }}</p>
  90.         </div>
  91.     {% else %}
  92.         <div class="ec-searchnavRole">
  93.         <div class="ec-pageHeader">
  94.             <h1>{{ 'あおいのお菓子'|trans }}</h1>
  95.         </div>
  96.         {% set Categories = repository('Eccube\\Entity\\Category').getList() %}
  97.         <ul class="categories">
  98.             {% for Category in Categories %}
  99.                 <li><a href="{{url('product_list',{'category_id':Category["id"]})}}">{{ Category["name"]}}</a></li>
  100.             {% endfor %}
  101.         </ul>
  102.             <form name="form1" id="form1" method="get" action="?">
  103.                 {% for item in search_form %}
  104.                     <input type="hidden" id="{{ item.vars.id }}"
  105.                            name="{{ item.vars.full_name }}"
  106.                            {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %}/>
  107.                 {% endfor %}
  108.             </form>
  109.             <div class="container">
  110.             <div class="ec-searchnavRole__topicpath">
  111.                 <ol class="ec-topicpath">
  112.                     <li class="ec-topicpath__item"><a href="{{ url('product_list') }}">{{ '全て'|trans }}</a>
  113.                     </li>
  114.                     {% if Category is not null %}
  115.                         {% for Path in Category.path %}
  116.                             <li class="ec-topicpath__divider">|</li>
  117.                             <li class="ec-topicpath__item{% if loop.last %}--active{% endif %}"><a
  118.                                         href="{{ url('product_list') }}?category_id={{ Path.id }}">{{ Path.name }}</a>
  119.                             </li>
  120.                         {% endfor %}
  121.                     {% endif %}
  122.                     {% if search_form.vars.value and search_form.vars.value.name %}
  123.                         <li class="ec-topicpath__divider">|</li>
  124.                         <li class="ec-topicpath__item">{{ '「%name%」の検索結果'|trans({ '%name%': search_form.vars.value.name }) }}</li>
  125.                     {% endif %}
  126.                 </ol>
  127.             </div>
  128.             </div>
  129.             <div class="container">
  130.             <div class="ec-searchnavRole__infos">
  131.                 <div class="ec-searchnavRole__counter">
  132.                     {% if pagination.totalItemCount > 0 %}
  133.                         {{ '<span class="ec-font-bold">%count%件</span><span>の商品が見つかりました</span>'|trans({ '%count%': pagination.totalItemCount })|raw }}
  134.                     {% else %}
  135.                         <span>{{ 'お探しの商品は見つかりませんでした'|trans }}</span>
  136.                     {% endif %}
  137.                 </div>
  138.                 {% if pagination.totalItemCount > 0 %}
  139.                     <div class="ec-searchnavRole__actions">
  140.                         <div class="ec-select">
  141.                             {{ form_widget(search_form.disp_number, {'id': '', 'attr': {'class': 'disp-number'}}) }}
  142.                             {{ form_widget(search_form.orderby, {'id': '', 'attr': {'class': 'order-by'}}) }}
  143.                         </div>
  144.                     </div>
  145.                 {% endif %}
  146.             </div>
  147.             </div>
  148.         </div>
  149.         {% if pagination.totalItemCount > 0 %}
  150.             <div class="container">
  151.             <div class="ec-shelfRole">
  152.                 <ul class="ec-shelfGrid">
  153.                     {% for Product in pagination %}
  154.                         <li class="ec-shelfGrid__item">
  155.                             <a href="{{ url('product_detail', {'id': Product.id}) }}">
  156.                                 <p class="ec-shelfGrid__item-image">
  157.                                     <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}" {% if loop.index > 5 %} loading="lazy"{% endif %}>
  158.                                 </p>
  159.                                 <p>{{ Product.name }}</p>
  160.                                 {% if Product.description_list %}
  161.                                     <p>{{ Product.description_list|raw|nl2br }}</p>
  162.                                 {% endif %}
  163.                                 <p class="price02-default">
  164.                                     {% if Product.hasProductClass %}
  165.                                         {% if Product.getPrice02Min == Product.getPrice02Max %}
  166.                                             {{ Product.getPrice02IncTaxMin|price }}
  167.                                         {% else %}
  168.                                             {{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}
  169.                                         {% endif %}
  170.                                     {% else %}
  171.                                         {{ Product.getPrice02IncTaxMin|price }}
  172.                                     {% endif %}
  173.                                 </p>
  174.                             </a>
  175.                             {% if Product.stock_find %}
  176.                                 {% set form = forms[Product.id] %}
  177.                                 <form name="form{{ Product.id }}" id="productForm{{ Product.id }}" action="{{ url('product_add_cart', {id:Product.id}) }}" method="post">
  178.                                     <div class="ec-productRole__actions">
  179.                                         {% if form.classcategory_id1 is defined %}
  180.                                             <div class="ec-select">
  181.                                                 {{ form_widget(form.classcategory_id1) }}
  182.                                                 {{ form_errors(form.classcategory_id1) }}
  183.                                             </div>
  184.                                             {% if form.classcategory_id2 is defined %}
  185.                                                 <div class="ec-select">
  186.                                                     {{ form_widget(form.classcategory_id2) }}
  187.                                                     {{ form_errors(form.classcategory_id2) }}
  188.                                                 </div>
  189.                                             {% endif %}
  190.                                         {% endif %}
  191.                                         <div class="ec-numberInput"><span>{{ '数量'|trans }}</span>
  192.                                             {{ form_widget(form.quantity, {'attr': {'class': 'quantity'}}) }}
  193.                                             {{ form_errors(form.quantity) }}
  194.                                         </div>
  195.                                     </div>
  196.                                     {{ form_rest(form) }}
  197.                                 </form>
  198.                                 <div class="ec-productRole__btn">
  199.                                     <button type="submit" class="ec-blockBtn--action add-cart" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}">
  200.                                         {{ 'カートに入れる'|trans }}
  201.                                     </button>
  202.                                 </div>
  203.                             {% else %}
  204.                                 <div class="ec-productRole__btn">
  205.                                     <button type="button" class="ec-blockBtn--action" disabled="disabled">
  206.                                         {{ 'ただいま品切れ中です。'|trans }}
  207.                                     </button>
  208.                                 </div>
  209.                             {% endif %}
  210.                         </li>
  211.                     {% endfor %}
  212.                 </ul>
  213.             </div>
  214.             </div>
  215.             <div class="ec-modal">
  216.                 <div class="ec-modal-overlay">
  217.                     <div class="ec-modal-wrap">
  218.                         <span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  219.                         <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  220.                         <div class="ec-modal-box">
  221.                             <div class="ec-role">
  222.                                 <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  223.                                 <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  224.                             </div>
  225.                         </div>
  226.                     </div>
  227.                 </div>
  228.             </div>
  229.             <div class="ec-pagerRole">
  230.                 {% include "pager.twig" with {'pages': pagination.paginationData} %}
  231.             </div>
  232.         {% endif %}
  233.     {% endif %}
  234. {% endblock %}