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.     
  88.     {# タイトル #}
  89.     <div class="container">
  90.         {% set request_uri = app.request.server.get('REQUEST_URI') %}
  91.         {% if Category is not null %}
  92.             {% if Category.children|length > 0 %}
  93.                 <h2 class="page-title">
  94.                     <span class="_main">
  95.                         {{ Category.name }}
  96.                     </span>
  97.                 </h2>
  98.             {% else %}
  99.                 {% set ParentCat = Category.Parent %}
  100.                 <h2 class="page-title">
  101.                     <span class="_main">
  102.                         {{ ParentCat.name }}
  103.                     </span>
  104.                 </h2>
  105.             {% endif %}
  106.         {% elseif search_form.vars.value and search_form.vars.value.name %}
  107.             <h2 class="page-title">
  108.                 <span class="_main">
  109.                     {{ '「%name%」の検索結果'|trans({ '%name%': search_form.vars.value.name }) }}
  110.                 </span>
  111.             </h2>
  112.         {% else %}
  113.             <h2 class="page-title">
  114.                 <span class="_main">全ての商品</span>
  115.                 <span class="_sub">PRODUCTS ALL</span>
  116.             </h2>
  117.         {% endif %}
  118.     </div>
  119.     {% if search_form.category_id.vars.errors|length > 0 %}
  120.         <div class="ec-searchnavRole">
  121.             <p class="errormsg text-danger">{{ 'ご指定のカテゴリは存在しません'|trans }}</p>
  122.         </div>
  123.     {% else %}
  124.         <div class="ec-searchnavRole">
  125.             <form name="form1" id="form1" method="get" action="?">
  126.                 {% for item in search_form %}
  127.                     <input type="hidden" id="{{ item.vars.id }}"
  128.                            name="{{ item.vars.full_name }}"
  129.                            {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %}/>
  130.                 {% endfor %}
  131.             </form>
  132.             
  133.             <div class="ec-searchnavRole__infos">
  134.                 <div class="ec-searchnavRole__counter">
  135.                     {% if pagination.totalItemCount > 0 %}
  136.                         {{ '<span class="ec-font-bold">%count%件</span><span>の商品が見つかりました</span>'|trans({ '%count%': pagination.totalItemCount })|raw }}
  137.                     {% else %}
  138.                         <span>{{ 'お探しの商品は見つかりませんでした'|trans }}</span>
  139.                     {% endif %}
  140.                 </div>
  141.                 {% if pagination.totalItemCount > 0 %}
  142.                     <div class="ec-searchnavRole__actions">
  143.                         <div class="ec-select">
  144.                             <div class="ec-select__group">
  145.                                 <span>件数</span>
  146.                                 {{ form_widget(disp_number_form, {'id': '', 'attr': {'class': 'disp-number'}}) }}
  147.                             </div>
  148.                             <div class="ec-select__group">
  149.                                 <span>表示順</span>
  150.                                 {{ form_widget(order_by_form, {'id': '', 'attr': {'class': 'order-by'}}) }}
  151.                             </div>
  152.                         </div>
  153.                     </div>
  154.                 {% endif %}
  155.             </div>
  156.         </div>
  157.         
  158.         {% if Category is not null %}
  159.         {# 子カテゴリがある場合 #}
  160.             {% if Category.children|length > 0 %}
  161.                 <div class="cat-nav">
  162.                     <div class="container">
  163.                         {% set cate_childs = Category.getDescendants %}
  164.                         {% if cate_childs %}
  165.                         {% set h = Category.hierarchy + 1 %}
  166.                         <ul class="cat-nav__list">
  167.                             {% for cate in cate_childs %}
  168.                                 {% if h == cate.hierarchy %}
  169.                                 <li class="cat-nav__item">
  170.                                     <a href="{{ url('product_list') }}?category_id={{ cate.id }}">{{ cate.name }}</a>
  171.                                 </li>
  172.                                 {% endif %}
  173.                             {% endfor %}
  174.                         </ul>
  175.                         {% endif %}
  176.                     </div>
  177.                 </div>
  178.             {% else %}
  179.                 <div class="cat-nav">
  180.                     <div class="container">
  181.                         {# 子カテゴリがない場合 #}
  182.                         <ul class="cat-nav__list">
  183.                             <li class="cat-nav__item is-current">
  184.                                 <a href="{{ url('product_list') }}?category_id={{ Category.id }}">
  185.                                     {{ Category.name }}
  186.                                 </a>
  187.                             </li>
  188.                         {% set SameRankCategories = repository('Eccube\\Entity\\Category').getList(Category.Parent) %}
  189.                         {% for SameRankCategory in SameRankCategories if Category is not same as(SameRankCategory)  %}
  190.                             <li class="cat-nav__item">
  191.                                 <a href="{{ url('product_list') }}?category_id={{ SameRankCategory.id }}">
  192.                                     {{ SameRankCategory.name }}
  193.                                 </a>
  194.                             </li>
  195.                         {% endfor %}
  196.                         </ul>
  197.                     </div>
  198.                 </div>
  199.             {% endif %}
  200.         {% endif %}
  201.         
  202.         
  203.         
  204.         
  205.         {% if pagination.totalItemCount > 0 %}
  206.             <div class="ec-shelfRole _list">
  207.                 <ul class="ec-shelfGrid">
  208.                     {% for Product in pagination %}
  209.                         <li class="ec-shelfGrid__item">
  210.                             <a href="{{ url('product_detail', {'id': Product.id}) }}">
  211.                                 <p class="ec-shelfGrid__item-image">
  212.                                     <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}" loading="lazy">
  213.                                 </p>
  214.                                 <p class="ec-shelfGrid__item-title">{{ Product.name }}</p>
  215.                                 <div class="ec-shelfGrid__item-btn">
  216.                                     <span class="btn-basic _red _small">
  217.                                         詳しく見る
  218.                                     </span>
  219.                                 </div>
  220.                                 <p class="ec-shelfGrid__item-description">
  221.                                     {% if Product.description_list %}
  222.                                         <p>{{ Product.description_list|raw|nl2br }}</p>
  223.                                     {% endif %}
  224.                                 </p>
  225.                             </a>
  226.                             {# {% if Product.stock_find %}
  227.                                 {% set form = forms[Product.id] %}
  228.                                 <form name="form{{ Product.id }}" id="productForm{{ Product.id }}" action="{{ url('product_add_cart', {id:Product.id}) }}" method="post">
  229.                                     <div class="ec-productRole__actions">
  230.                                         {% if form.classcategory_id1 is defined %}
  231.                                             <div class="ec-select">
  232.                                                 {{ form_widget(form.classcategory_id1) }}
  233.                                                 {{ form_errors(form.classcategory_id1) }}
  234.                                             </div>
  235.                                             {% if form.classcategory_id2 is defined %}
  236.                                                 <div class="ec-select">
  237.                                                     {{ form_widget(form.classcategory_id2) }}
  238.                                                     {{ form_errors(form.classcategory_id2) }}
  239.                                                 </div>
  240.                                             {% endif %}
  241.                                         {% endif %}
  242.                                         <div class="ec-numberInput"><span>{{ '数量'|trans }}</span>
  243.                                             {{ form_widget(form.quantity, {'attr': {'class': 'quantity'}}) }}
  244.                                             {{ form_errors(form.quantity) }}
  245.                                         </div>
  246.                                     </div>
  247.                                     {{ form_rest(form) }}
  248.                                 </form>
  249.                                 <div class="ec-productRole__btn">
  250.                                     <button type="submit" class="ec-blockBtn--action add-cart" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}">
  251.                                         {{ 'カートに入れる'|trans }}
  252.                                     </button>
  253.                                 </div>
  254.                             {% else %}
  255.                                 <div class="ec-productRole__btn">
  256.                                     <button type="button" class="ec-blockBtn--action" disabled="disabled">
  257.                                         {{ 'ただいま品切れ中です。'|trans }}
  258.                                     </button>
  259.                                 </div>
  260.                             {% endif %} #}
  261.                         </li>
  262.                     {% endfor %}
  263.                 </ul>
  264.             </div>
  265.             <div class="ec-modal">
  266.                 <div class="ec-modal-overlay">
  267.                     <div class="ec-modal-wrap">
  268.                         <span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  269.                         <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  270.                         <div class="ec-modal-box">
  271.                             <div class="ec-role">
  272.                                 <span class="btn-basic _sub _prev">{{ 'お買い物を続ける'|trans }}</span>
  273.                                 <a href="{{ url('cart') }}" class="btn-cart">{{ 'カートへ進む'|trans }}</a>
  274.                             </div>
  275.                         </div>
  276.                     </div>
  277.                 </div>
  278.             </div>
  279.             <div class="ec-pagerRole">
  280.                 {% include "pager.twig" with {'pages': pagination.paginationData} %}
  281.             </div>
  282.         {% endif %}
  283.     {% endif %}
  284. {% endblock %}