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. {% block stylesheet %}
  10.     <link rel="stylesheet" href="{{ asset('assets/css/contents-list.css', 'user_data') }}">
  11.     <link rel="stylesheet" href="{{ asset('assets/css/main_module.css', 'user_data') }}">
  12.     <style>
  13.         .tab {
  14.             margin: 100px 10% 0;
  15.         }
  16.         .tab-list {
  17.             display: flex;
  18.             gap: 1px;
  19.         }
  20.         .tab-item {
  21.             border-radius: 5px 5px 0 0;
  22.             background-color: #09860D;
  23.             border-top: solid 1px #09860D;
  24.             border-right: solid 1px #09860D;
  25.             border-left: solid 1px #09860D;
  26.             padding: 0.5em 1.2em;
  27.             color: #FFF;
  28.             cursor: pointer;
  29.         }
  30.         .tab-content {
  31.             display: flex;
  32.             justify-content: space-between;
  33.             border: solid 1px #09860D;
  34.             border-radius: 0 8px 8px 8px;
  35.         }
  36.         .tab-panel {
  37.             display: none;
  38.         }
  39.         .tab-item.active {
  40.             background-color: #fff;
  41.             color: #09860D;
  42.             font-weight: bold;
  43.             position: relative;
  44.         }
  45.         .tab-item.active::before{
  46.             content: "";
  47.             width: 100%;
  48.             border-bottom: 1px solid  #FFF;
  49.             position: absolute;
  50.             bottom: -1px;
  51.             left: 0;
  52.         }
  53.         .tab-panel.active {
  54.             display: block;
  55.             padding: 3%;
  56.         }
  57.         .tab-panel.active h2 {
  58.             font-size: 20px;
  59.             font-weight: bold;
  60.         }
  61.     </style>
  62. {% endblock %}
  63. {% set body_class = 'product_page' %}
  64. {% block javascript %}
  65.     <script>
  66.         eccube.productsClassCategories = {
  67.             {% for Product in pagination %}
  68.             "{{ Product.id|escape('js') }}": {{ class_categories_as_json(Product)|raw }}{% if loop.last == false %}, {% endif %}
  69.             {% endfor %}
  70.         };
  71.         $(function() {
  72.             // 表示件数を変更
  73.             $('.disp-number').change(function() {
  74.                 var dispNumber = $(this).val();
  75.                 $('#disp_number').val(dispNumber);
  76.                 $('#pageno').val(1);
  77.                 $("#form1").submit();
  78.             });
  79.             // // 並び順を変更
  80.             $('.order-by').change(function() {
  81.                 var orderBy = $(this).val();
  82.                 $('#orderby').val(orderBy);
  83.                 $('#pageno').val(1);
  84.                 $("#form1").submit();
  85.             });
  86.             $('.add-cart').on('click', function(e) {
  87.                 var $form = $(this).parents('li').find('form');
  88.                 // 個数フォームのチェック
  89.                 var $quantity = $form.parent().find('.quantity');
  90.                 if ($quantity.val() < 1) {
  91.                     $quantity[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  92.                     setTimeout(function() {
  93.                         loadingOverlay('hide');
  94.                     }, 100);
  95.                     return true;
  96.                 } else {
  97.                     $quantity[0].setCustomValidity('');
  98.                 }
  99.                 e.preventDefault();
  100.                 $.ajax({
  101.                     url: $form.attr('action'),
  102.                     type: $form.attr('method'),
  103.                     data: $form.serialize(),
  104.                     dataType: 'json',
  105.                     beforeSend: function(xhr, settings) {
  106.                         // Buttonを無効にする
  107.                         $('.add-cart').prop('disabled', true);
  108.                     }
  109.                 }).done(function(data) {
  110.                     // レスポンス内のメッセージをalertで表示
  111.                     $.each(data.messages, function() {
  112.                         $('#ec-modal-header').html(this);
  113.                     });
  114.                     $('.ec-modal').show()
  115.                     // カートブロックを更新する
  116.                     $.ajax({
  117.                         url: '{{ url('block_cart') }}',
  118.                         type: 'GET',
  119.                         dataType: 'html'
  120.                     }).done(function(html) {
  121.                         $('.ec-headerRole__cart').html(html);
  122.                     });
  123.                 }).fail(function(data) {
  124.                     alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  125.                 }).always(function(data) {
  126.                     // Buttonを有効にする
  127.                     $('.add-cart').prop('disabled', false);
  128.                 });
  129.             });
  130.         });
  131.         $('.ec-modal-wrap').on('click', function(e) {
  132.             // モーダル内の処理は外側にバブリングさせない
  133.             e.stopPropagation();
  134.         });
  135.         $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  136.             $('.ec-modal').hide()
  137.         });
  138.         
  139.                 // タブの見出し(tab-item)を取得
  140.         const tabItems = document.querySelectorAll(".tab-item");
  141.         
  142.         let activeTabId = document.querySelector(".tab-item.active").id;
  143.         document.querySelector(".category-btn").value = activeTabId;
  144.         
  145.         tabItems.forEach((tabItem) => {
  146.             tabItem.addEventListener("click", () => {
  147.                 // すべてのタブを非アクティブにする
  148.                 tabItems.forEach((t) => {
  149.                     t.classList.remove("active");
  150.                 });
  151.                 // すべてのコンテンツを非表示にする
  152.                 const tabPanels = document.querySelectorAll(".tab-panel");
  153.                 tabPanels.forEach((tabPanel) => {
  154.                     tabPanel.classList.remove("active");
  155.                 });
  156.                 // クリックされたタブをアクティブにする
  157.                 tabItem.classList.add("active");
  158.                 
  159.                 //アクティブになったタブのidを取得して、buttonのvalueにいれる
  160.                 activeTabId = document.querySelector(".tab-item.active").id;
  161.                 document.querySelector(".category-btn").value = activeTabId;
  162.                 // 対応するコンテンツを表示
  163.                 const tabIndex = Array.from(tabItems).indexOf(tabItem);
  164.                 tabPanels[tabIndex].classList.add("active");
  165.             });
  166.         });
  167.         
  168.         document.getElementById('category-form').addEventListener('submit', function(e) {
  169.             const selects = this.querySelectorAll('select[name="category_ids[]"]');
  170.             const nonActiveSelects = document.querySelectorAll('.tab-panel:not(.active) select');
  171.             selects.forEach(select => {
  172.                 if (select.value === '') {
  173.                     select.disabled = true; // 空なら無効にして送らない
  174.                 }
  175.             });
  176.             nonActiveSelects.forEach(select =>{
  177.                 select.disabled = true; //activeを親にactiveを持たないselectは無効
  178.             });
  179.         });
  180.     </script>
  181. {% endblock %}
  182. {% block main %}
  183.     <!-- カテゴリ検索 -->
  184.     {% set Categories = repository('Eccube\\Entity\\Category').getList() %}
  185.     {% set selected_categories = app.request.query.get('category_ids', []) %}
  186.     {% set parent_category = app.request.query.get('parent_category', []) %}
  187.     
  188.     {% if app.request.query.get('category_id') not in [7, 8] %}
  189.         <form action="{{ url('product_list') }}" method="get" class="tab" id="category-form">
  190.             <ul class="tab-list">
  191.                 {% for tab in Categories|slice(0, 3)%}
  192.                     {% set children_ids = [] %}
  193.                     {% for Child in tab.Children %}
  194.                         {% set children_ids = children_ids|merge([Child.id]) %}
  195.                     {% endfor %}
  196.                         {% if tab.id == app.request.query.get('category_id')
  197.                         or tab.id == app.request.query.get('search_parent_id')
  198.                         or app.request.query.get('category_id') in children_ids
  199.                         %}
  200.                             <li class="tab-item active" tabindex="0" id="{{tab.id}}">{{tab.name}}</li>
  201.                         {% else %}
  202.                             <li class="tab-item" tabindex="0" id="{{tab.id}}">{{tab.name}}</li>
  203.                         {% endif %}
  204.                 {% endfor %}
  205.             </ul>
  206.             <div class="tab-content">
  207.                 {% for Category in Categories|slice(0, 3)%}
  208.                     {% set children_ids = [] %}
  209.                     {% for Child in Category.Children %}
  210.                         {% set children_ids = children_ids|merge([Child.id]) %}
  211.                     {% endfor %}
  212.                     {% if Category.id == app.request.query.get('category_id')
  213.                     or Category.id == app.request.query.get('search_parent_id')
  214.                     or app.request.query.get('category_id') in children_ids
  215.                     %}
  216.                         <div class="tab-panel active">
  217.                                 {% for Child in Category.Children%}
  218.                                     <select name="category_ids[]">
  219.                                         <option value="">{{Child.name}}から選択</option>
  220.                                             {% for grandchild in Child.Children %}
  221.                                                 <option value="{{grandchild.id}}"
  222.                                                     {% if grandchild.id in selected_categories %}
  223.                                                         selected
  224.                                                     {% endif %}
  225.                                                 >{{grandchild.name}}</option>
  226.                                             {% endfor %}
  227.                                     </select>
  228.                                 {% endfor %}
  229.                         </div>
  230.                     {% else %}
  231.                         <div class="tab-panel">
  232.                             <div>
  233.                                 {% for Child in Category.Children%}
  234.                                     <select name="category_ids[]">
  235.                                         <option value="" selected>{{Child.name}}から選択</option>
  236.                                             {% for grandchild in Child.Children %}
  237.                                                 <option value="{{grandchild.id}}">{{grandchild.name}}</option>
  238.                                             {% endfor %}
  239.                                     </select>
  240.                                 {% endfor %}
  241.                             </div>
  242.                         </div>
  243.                     {% endif %}
  244.                 {% endfor %}
  245.                 <button type="submit" class="category-btn" name="search_parent_id" value="">
  246.                     <img src="{{ asset('/html/user_data/assets/icon/btn_ic_search.svg ', 'user_data') }}" alt="お気に入り">
  247.                     カテゴリ検索
  248.                 </button>
  249.             </div>
  250.         </form>
  251.     {% endif %}
  252. <section class="contents-list">
  253.     {#<form name="form1" id="form1" method="get" action="?">#}
  254.     {#    {% for item in search_form %}#}
  255.     {#        <input type="hidden" id="{{ item.vars.id }}"#}
  256.     {#               name="{{ item.vars.full_name }}"#}
  257.     {#               {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %}/>#}
  258.     {#    {% endfor %}#}
  259.     {#</form>#}
  260.     <!-- 商品リスト -->
  261.     <div class="list-view">
  262.         <div class="list-title">
  263.                 {% if Category is not null %}
  264.                 {% for Path in Category.path|slice(0, 1) %}
  265.                         <h2 class="ec-topicpath__item">{{ Path.name }}</h2>
  266.                 {% endfor %}
  267.                 {% endif %}
  268.                 {% if pagination.totalItemCount > 0 %}
  269.                     {{ '<p>%count%冊</p>'|trans({ '%count%': pagination.totalItemCount })|raw }}
  270.                 {% else %}
  271.                     <p>{{ 'お探しの商品は見つかりませんでした'|trans }}</p>
  272.                 {% endif %}
  273.         </div>
  274.         <!-- カテゴリ説明 -->
  275.         {#<p class="lead-sentence">テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト</p>#}
  276.         <!-- リストエリア -->
  277.         {% if pagination.totalItemCount > 0 %}
  278.             <div class="list-area">
  279.                 {% for Product in pagination %}
  280.                     <div class="card-1">
  281.                         <a href="{{ url('product_detail', {'id': Product.id}) }}">
  282.                             <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}" {% if loop.index > 5 %} loading="lazy"{% endif %}>
  283.                             <h3>{{ Product.name }}</h3>
  284.                             <p class="price02-default">
  285.                                 {{ Product.getPrice02IncTaxMin|price }}税込
  286.                             </p>
  287.                         </a>
  288.                     </div>
  289.                 {% endfor %}
  290.                 <!-- ページネーション -->
  291.                 {% set pages = pagination.paginationData %}
  292.                 {% if pages.pageCount > 1 %}
  293.                     <div class="ec-pager pagination">
  294.                         {# 前へ #}
  295.                         {% if pages.previous is defined %}
  296.                             <a class="page-return" href="{{ path(
  297.                             app.request.attributes.get('_route'),
  298.                             app.request.query.all|merge({'pageno': pages.previous})) }}">←</a>
  299.                         {% endif %}
  300.                         <div class="page-num">
  301.                             {% for page in pages.pagesInRange %}
  302.                                 {% if page == pages.current %}
  303.                                     <a class="active" href="{{ path(
  304.                                         app.request.attributes.get('_route'),
  305.                                         app.request.query.all|merge({'pageno': page})) }}"> {{ page }} </a>
  306.                                 {% else %}
  307.                                     <a href="{{ path(
  308.                                         app.request.attributes.get('_route'),
  309.                                         app.request.query.all|merge({'pageno': page})) }}"> {{ page }} </a>
  310.                                 {% endif %}
  311.                             {% endfor %}
  312.                         </div>
  313.                         {# 次へ #}
  314.                         {% if pages.next is defined %}
  315.                             <a class="page-advance" href="{{ path(
  316.                             app.request.attributes.get('_route'),
  317.                             app.request.query.all|merge({'pageno': pages.next})) }}">→</a>
  318.                         {% endif %}
  319.                     </div>
  320.                 {% endif %}
  321.             </div>
  322.         {% endif %}
  323.     </div>
  324.             
  325. </section>
  326. {% endblock %}