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').text(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.         $('#category_select').on('change', function() {
  85.         // 遷移先URL取得
  86.         var url = $(this).val();
  87.         // URLが取得できていればページ遷移
  88.         if(url != '') {
  89.             location.href = url;
  90.         }
  91.       });
  92.     </script>
  93. {% endblock %}
  94. {% block main %}
  95. {%  set Categories = repository('Eccube\\Entity\\Category').findAll() %}
  96. {% if Category.name is defined %}
  97. {% set categoryName = Category.name %}
  98. {% else %}
  99. {% set categoryName = '商品一覧' %}
  100. {% endif %}
  101. <section class="l-lower-mv product-mv">
  102.   <div class="inner l-lower-mv__inner">
  103.     <h1 class="l-lower-mv__title">Line up<span class="l-lower-mv__subtitle">商品一覧</span></h1>
  104.   </div>
  105. </section>
  106. <section class="product">
  107.   <div class="inner product__inner">
  108.     <div class="l-breadcrumb">
  109.       <ul itemscope itemtype="https://schema.org/BreadcrumbList" class="l-breadcrumb__list">
  110.         <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="l-breadcrumb__item">
  111.           <a itemprop="item" href="{{ url('homepage') }}" class="l-breadcrumb__link">
  112.             <span class="freight-neo-pro" itemprop="name">TOP</span>
  113.           </a>
  114.           <meta itemprop="position" content="1" />
  115.         </li>
  116.         <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="l-breadcrumb__item">
  117.           <a itemprop="item" href="{{ url('product_list') }}" class="l-breadcrumb__link">
  118.             <span class="freight-neo-pro" itemprop="name">{{ categoryName }}</span>
  119.           </a>
  120.           <meta itemprop="position" content="2" />
  121.         </li>
  122.       </ul>
  123.     </div>
  124.     <div class="product__container">
  125.       <article class="product__article">
  126.         {% if search_form.category_id.vars.errors|length > 0 %}
  127.         <div class="ec-searchnavRole">
  128.           <p class="errormsg text-danger">{{ 'ご指定のカテゴリは存在しません'|trans }}</p>
  129.         </div>
  130.         {% else %}
  131.         <div class="product__search">
  132.           <form name="form1" id="form1" method="get" action="?">
  133.             {% for item in search_form %}
  134.             <input type="hidden" id="{{ item.vars.id }}" name="{{ item.vars.full_name }}" {% if item.vars.value is not
  135.               empty %} value="{{ item.vars.value }}" {% endif %} />
  136.             {% endfor %}
  137.           </form>
  138.           <div class="product__search-top">
  139.             {% if Category is not null %}
  140.             {# {% for Path in Category.path %} #}
  141.               {# {% if Category.parent == null %} #}
  142.               <h2 class="product__search-heading">{{ Category.name }}</h2>
  143.               {# {% else %} #}
  144.               {# <h2 class="product__search-heading">{{ Category.Parent.name }} {{ Category.name }}</h2> #}
  145.               {# {% endif %} #}
  146.             {# {% endfor %} #}
  147.             {% else %}
  148.             <h2 class="product__search-heading">{{ '全て'|trans }}</h2>
  149.             {% endif %}
  150.             {% if pagination.totalItemCount > 0 %}
  151.             <div class="product__search-select-wrap">
  152.               <select name="category_select" id="category_select" class="form-select -category">
  153.                 <option value="{{ url('product_list') }}">全ての商品</option>
  154.                 {% set SortedCategories = Categories|sort((a, b) => b.sort_no <=> a.sort_no) %}
  155.                 {% for Category in SortedCategories %}
  156.                   {% set ParentCategory = Category %}
  157.                   {% set SortedChildren = Category.children|sort((a, b) => b.sort_no <=> a.sort_no) %}
  158.                   {% for ChildCategory in SortedChildren %}
  159.                 <option value="{{ url('product_list') }}?category_id={{ParentCategory.id}}">{{ParentCategory.name}}</option>
  160.                 <option value="{{ url('product_list') }}?category_id={{ChildCategory.id}}">&emsp;{{ChildCategory.name}}</option>
  161.                   {% endfor %}
  162.                 {% endfor %}
  163.               </select>
  164.               {{ form_widget(search_form.disp_number, {'id': '', 'attr': {'class': 'disp-number'}}) }}
  165.               {{ form_widget(search_form.orderby, {'id': '', 'attr': {'class': 'order-by'}}) }}
  166.             </div>
  167.             {% endif %}
  168.           </div>
  169.           <div class="product__search-bottom">
  170.             <div class="product__search-counter">
  171.               {% if pagination.totalItemCount > 0 %}
  172.               {{ '<span class="product__search-counter--bold">%count%</span><span>件の商品が見つかりました</span>'|trans({ '%count%':
  173.               pagination.totalItemCount })|raw }}
  174.               {% else %}
  175.               <span>{{ 'お探しの商品は見つかりませんでした'|trans }}</span>
  176.               {% endif %}
  177.             </div>
  178.           </div>
  179.         </div>
  180.         {% if pagination.totalItemCount > 0 %}
  181.         <div class="product__wrap">
  182.           <ul class="product__list">
  183.             {% for Product in pagination %}
  184.             <li class="product__item">
  185.               <a href="{{ url('product_detail', {'id': Product.id}) }}" class="product__item-link">
  186.                 <picture class="product__item-image">
  187.                   <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}"
  188.                     {% if loop.index> 5 %} loading="lazy" {% endif %}>
  189.                 </picture>
  190.                 <p class="product__item-name">{{ Product.name }}</p>
  191.                 <!-- {% if Product.description_list %}
  192.                 <p>{{ Product.description_list|raw|nl2br }}</p>
  193.                 {% endif %} -->
  194.                 <p class="product__item-price">
  195.                   {% if Product.hasProductClass %}
  196.                   {% if Product.getPrice02Min == Product.getPrice02Max %}
  197.                   {{ Product.getPrice02IncTaxMin|price }}<span>(税込)</span>
  198.                   {% else %}
  199.                   {{ Product.getPrice02IncTaxMin|price }}
  200.                   ~
  201.                   {{ Product.getPrice02IncTaxMax|price }}<span>(税込)</span>
  202.                   {% endif %}
  203.                   {% else %}
  204.                   {{ Product.getPrice02IncTaxMin|price }}<span>(税込)</span>
  205.                   {% endif %}
  206.                 </p>
  207.                 <ul class="p-tags product__tags">
  208.                 {% for Tag in Product.Tags %}
  209.                   <li class="p-tag">{{Tag.name}}</li>
  210.                 {% endfor %}
  211.                 </ul>
  212.               </a>
  213.               {% if Product.stock_find %}
  214.               {% set form = forms[Product.id] %}
  215.               <!-- <form name="form{{ Product.id }}" id="productForm{{ Product.id }}"
  216.                 action="{{ url('product_add_cart', {id:Product.id}) }}" method="post">
  217.                 <div class="ec-productRole__actions">
  218.                   {% if form.classcategory_id1 is defined %}
  219.                   <div class="ec-select">
  220.                     {{ form_widget(form.classcategory_id1) }}
  221.                     {{ form_errors(form.classcategory_id1) }}
  222.                   </div>
  223.                   {% if form.classcategory_id2 is defined %}
  224.                   <div class="ec-select">
  225.                     {{ form_widget(form.classcategory_id2) }}
  226.                     {{ form_errors(form.classcategory_id2) }}
  227.                   </div>
  228.                   {% endif %}
  229.                   {% endif %}
  230.                   <div class="ec-numberInput">
  231.                     <span>{{ '数量'|trans }}</span>
  232.                     {{ form_widget(form.quantity, {'attr': {'class': 'quantity'}}) }}
  233.                     {{ form_errors(form.quantity) }}
  234.                   </div>
  235.                 </div>
  236.                 {{ form_rest(form) }}
  237.               </form> -->
  238.               <!-- <div class="ec-productRole__btn">
  239.                 <button type="submit" class="ec-blockBtn--action add-cart" data-cartid="{{ Product.id }}"
  240.                   form="productForm{{ Product.id }}">
  241.                   {{ 'カートに入れる'|trans }}
  242.                 </button>
  243.               </div> -->
  244.               {% else %}
  245.               <!-- <div class="ec-productRole__btn">
  246.                 <button type="button" class="ec-blockBtn--action" disabled="disabled">
  247.                   {{ 'ただいま品切れ中です。'|trans }}
  248.                 </button>
  249.               </div> -->
  250.               {% endif %}
  251.             </li>
  252.             {% endfor %}
  253.           </ul>
  254.         </div>
  255.         <!-- <div class="ec-modal">
  256.           <div class="ec-modal-overlay">
  257.             <div class="ec-modal-wrap">
  258.               <span class="ec-modal-close">
  259.                 <span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt="" /></span>
  260.               </span>
  261.               <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  262.               <div class="ec-modal-box">
  263.                 <div class="ec-role">
  264.                   <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  265.                   <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  266.                 </div>
  267.               </div>
  268.             </div>
  269.           </div>
  270.         </div> -->
  271.         <div class="ec-pagerRole">
  272.           {% include "pager.twig" with {'pages': pagination.paginationData} %}
  273.         </div>
  274.         {% endif %}
  275.         {% endif %}
  276.       </article>
  277.       <sidebar class="product__sidebar">
  278.         <div class="product__sidebar-wrap">
  279.         {% set SortedCategories = Categories|sort((a, b) => b.sort_no <=> a.sort_no) %}
  280.         {% for Category in SortedCategories %}
  281.           {% set ParentCategory = Category %}
  282.           {% if ParentCategory.parent == null %}
  283.           <ul class="product__sidebar-list">
  284.             <li class="product__sidebar-item product__sidebar-item--parent">
  285.               <a href="{{ url('product_list') }}?category_id={{ParentCategory.id}}" class="product__sidebar-link">{{ParentCategory.name}}</a>
  286.             </li>
  287.             {% set SortedChildren = Category.children|sort((a, b) => b.sort_no <=> a.sort_no) %}
  288.             {% for ChildCategory in SortedChildren %}
  289.             <li class="product__sidebar-item">
  290.               <a href="{{ url('product_list') }}?category_id={{ChildCategory.id}}" class="product__sidebar-link">{{ ChildCategory.name }}</a>
  291.             </li>
  292.             {% endfor %}
  293.           </ul>
  294.           {% endif %}
  295.         {% endfor %}
  296.         </div>
  297.       </sidebar>
  298.     </div>
  299.   </div>
  300. </section>
  301. <!-- /.product -->
  302. {% endblock %}