app/template/tanzo/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.     </script>
  85.     <script >
  86.         $('img.check').on('error', function() {
  87.             console.log("画像が読み込まれませんでした");
  88.             $(this).addClass('d-none');
  89.         });
  90.     </script>
  91.     <script>
  92.         function getParam(name, url) {
  93.             if (!url) url = window.location.href;
  94.             name = name.replace(/[\[\]]/g, "\\$&");
  95.             var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  96.                 results = regex.exec(url);
  97.             if (!results) return null;
  98.             if (!results[2]) return '';
  99.             return decodeURIComponent(results[2].replace(/\+/g, " "));
  100.         }
  101.         $(function() {
  102.             var search_category = '<div class="ec-headerSearch__category d-none">';
  103.             search_category += '<div class="ec-select ec-select_search">';
  104.             search_category += '<select name="category_id" class="category_id">';
  105.             search_category += '<option value="">全ての商品</option>';
  106.             if(getParam('category_id')) {
  107.                 if(getParam('category_id') == 1) {
  108.                     search_category += '<option value="1" selected="selected">Marriage ring 結婚指輪</option>';
  109.                     search_category += '<option value="2">Engagement ring 婚約指輪</option>'; 
  110.                 } else if(getParam('category_id') == 2) {
  111.                     search_category += '<option value="1">Marriage ring 結婚指輪</option>';
  112.                     search_category += '<option value="2" selected="selected">Engagement ring 婚約指輪</option>'; 
  113.                 }
  114.             }
  115.             search_category += '</select></div></div>';
  116.             $('.ec-layoutRole__main .ec-headerSearch__keyword').before(search_category);
  117.         });
  118.     </script>
  119. {% endblock %}
  120. {% block main %}
  121.     {% if search_form.category_id.vars.errors|length > 0 %}
  122.         <div class="ec-searchnavRole">
  123.             <p class="errormsg text-danger">{{ 'ご指定のカテゴリは存在しません'|trans }}</p>
  124.         </div>
  125.     {% else %}
  126.         {# カテゴリページかつ検索欄にキーワードをいれていない場合 #}
  127.         {% if Category is not null and app.request.query.get('name') is null %}
  128.             <div class="ec-role">
  129.                 <div class="ec-pageHeader text-center">
  130.                     <h1 class="border-bottom-0 fw-normal d-inline-block">{{ Category.name }}</h1>
  131.                 </div>
  132.             </div>
  133.         {% endif %}
  134.         <div class="ec-searchnavRole">
  135.             <form name="form1" id="form1" method="get" action="?">
  136.                 {% for item in search_form %}
  137.                     <input type="hidden" id="{{ item.vars.id }}"
  138.                            name="{{ item.vars.full_name }}"
  139.                            {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %}/>
  140.                 {% endfor %}
  141.             </form>
  142.             <div class="ec-headerNaviRole__search">
  143.                 {{ render(path('block_search_product')) }}
  144.             </div>
  145.             <div class="ec-searchnavRole__topicpath">
  146.                 <ol class="ec-topicpath">
  147.                     <li class="ec-topicpath__item"><a href="{{ url('product_list') }}">{{ '全て'|trans }}</a>
  148.                     </li>
  149.                     {% if Category is not null %}
  150.                         {% for Path in Category.path %}
  151.                             <li class="ec-topicpath__divider">|</li>
  152.                             <li class="ec-topicpath__item{% if loop.last %}--active{% endif %}"><a
  153.                                         href="{{ url('product_list') }}?category_id={{ Path.id }}">{{ Path.name }}</a>
  154.                             </li>
  155.                         {% endfor %}
  156.                     {% endif %}
  157.                     {% if search_form.vars.value and search_form.vars.value.name %}
  158.                         <li class="ec-topicpath__divider">|</li>
  159.                         <li class="ec-topicpath__item">{{ '「%name%」の検索結果'|trans({ '%name%': search_form.vars.value.name }) }}</li>
  160.                     {% endif %}
  161.                 </ol>
  162.             </div>
  163.             <div class="ec-searchnavRole__infos">
  164.                 <div class="ec-searchnavRole__counter">
  165.                     {% if pagination.totalItemCount > 0 %}
  166.                         {{ '<span class="ec-font-bold">%count%件</span><span>の商品が見つかりました</span>'|trans({ '%count%': pagination.totalItemCount })|raw }}
  167.                     {% else %}
  168.                         <span>{{ 'お探しの商品は見つかりませんでした'|trans }}</span>
  169.                     {% endif %}
  170.                 </div>
  171.                 {% if pagination.totalItemCount > 0 %}
  172.                     <div class="ec-searchnavRole__actions">
  173.                         <div class="ec-select">
  174.                             {{ form_widget(search_form.disp_number, {'id': '', 'attr': {'class': 'disp-number'}}) }}
  175.                             {{ form_widget(search_form.orderby, {'id': '', 'attr': {'class': 'order-by'}}) }}
  176.                         </div>
  177.                     </div>
  178.                 {% endif %}
  179.             </div>
  180.         </div>
  181.         {% if pagination.totalItemCount > 0 %}
  182.             <div class="ec-shelfRole">
  183.                 <ul class="row flex-wrap ps-0">
  184.                     {# バナー表示用インデックス #}
  185.                     {% if pagination.paginationData.current == 1 %}
  186.                         {% set banner_index = 0 %}
  187.                     {% else %}
  188.                         {# 1ページあたりのバナー表示数 #}
  189.                         {% set banner_per_page = (pagination.paginationData.numItemsPerPage / 8)|round(0, 'floor') %}
  190.                         {# 既に何個のバナーを表示したか #}
  191.                         {% set banner_displayed = banner_per_page * pagination.paginationData.previous %}
  192.                         {% if banner_displayed < AddBanners|length %}
  193.                             {% set banner_index = banner_displayed %}
  194.                         {% elseif banner_displayed == AddBanners|length %}
  195.                             {% set banner_index = 0 %}
  196.                         {% else %}
  197.                             {% set banner_index = (banner_displayed % AddBanners|length) %}
  198.                         {% endif %}
  199.                     {% endif %}
  200.                     {% for Product in pagination %}
  201.                         <li class="col-6 col-md-3 mb-3">
  202.                             <a href="{{ url('product_detail', {'id': Product.id}) }}">
  203.                                 <p class="ec-shelfGrid__item-image">
  204.                                     <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}" {% if loop.index > 5 %} loading="lazy"{% endif %}>
  205.                                 </p>
  206.                                 <p>{{ Product.name }}</p>
  207.                                 {#{% if Product.description_list %}
  208.                                     <p>{{ Product.description_list|raw|nl2br }}</p>
  209.                                 {% endif %}#}
  210.                                 <p class="price02-default">
  211.                                     {% if Product.hasProductClass %}
  212.                                         {% if Product.getPrice02Min == Product.getPrice02Max %}
  213.                                             {{ Product.getPrice02IncTaxMin|price }}
  214.                                         {% else %}
  215.                                             {{ Product.getPrice02IncTaxMin|price }} ~ {#{{ Product.getPrice02IncTaxMax|price }}#}
  216.                                         {% endif %}
  217.                                     {% else %}
  218.                                         {{ Product.getPrice02IncTaxMin|price }}
  219.                                     {% endif %}
  220.                                 </p>
  221.                             </a>
  222.                             {# ここにあったカートボタンは削除 #}
  223.                         </li>
  224.                         {% if Category is null or (Category is not null and Category.id != 3) %}{# アニバーサリージュエリー以外の場合バナーを表示 #}
  225.                             {% if loop.index % 8 == 0 and AddBanners|length <= banner_index %}{# バナーが少ない場合 #}
  226.                                 {% set banner_index = 0 %} {# もう一度最初から表示する #}
  227.                             {% endif %}
  228.                             {% if loop.index % 8 == 0 and AddBanners|length > banner_index %}{# 8商品ごとにバナーを表示 #}
  229.                                 {% if Category is not null and Category.id == 2 %}
  230.                                     {# 婚約指輪の場合はid11のバナーは表示しない #}
  231.                                     {% if AddBanners[banner_index].id == 11 %}
  232.                                         {% set banner_index = banner_index + 1 %}
  233.                                     {% endif %}
  234.                                 {% endif %}
  235.                                 <li class="col-12 col-md-6 added_banner list-unstyled mb-4">
  236.                                     {% set style = "" %}
  237.                                     {% if AddBanners[banner_index].link_url %}
  238.                                         <a href="{{ AddBanners[banner_index].link_url }}" target="_blank" rel="noopener" class="d-flex flex-column justify-content-center h-100" {{ style ? style : "" }}>
  239.                                     {% else %}
  240.                                         <div class="d-flex flex-column h-100" {{ style ? style : "" }}>
  241.                                     {% endif %}
  242.                                         {#<h5>{{ AddBanners[banner_index].name }}</h5>#}{# 画像だけの場合もあるだろうから必須項目の「名称」は表示しない #}
  243.                                         {% if AddBanners[banner_index].bg_image %}
  244.                                             {% set filename = AddBanners[banner_index].bg_image|split('/') %}
  245.                                             <img src="{{ asset('addbanner' ,'save_image') ~ "/" ~ filename|last }}">
  246.                                         {% endif %}
  247.                                         {% if AddBanners[banner_index].description %}
  248.                                             <div class="add_banner_desc p-2">{{ AddBanners[banner_index].description|raw|nl2br }}</div>
  249.                                         {% endif %}
  250.                                     {% if AddBanners[banner_index].link_url %}
  251.                                         </a>
  252.                                     {% else %}
  253.                                         </div>
  254.                                     {% endif %}
  255.                                 </li>
  256.                                 {% set banner_index = banner_index + 1 %}
  257.                             {% endif %}
  258.                         {% endif %}
  259.                     {% endfor %}
  260.                     
  261.                     {# 最終ページでバナーが多かった場合、残りのバナーを表示する #}
  262.                     {% if pagination.paginationData.endPage == pagination.paginationData.current %}
  263.                         {% for AddBanner in AddBanners %}
  264.                             {% if (pagination.totalItemCount % 8 < AddBanners|length) and (loop.index == banner_index and AddBanners|length > banner_index) %}
  265.                                 <li class="col-12 col-md-6 added_banner list-unstyled mb-4">
  266.                                     {% if AddBanners[banner_index].link_url %}
  267.                                         <a href="{{ AddBanners[banner_index].link_url }}" target="_blank" rel="noopener" class="d-flex flex-column h-100">
  268.                                     {% else %}
  269.                                         <div class="d-flex flex-column h-100">
  270.                                     {% endif %}
  271.                                         {#<h5>{{ AddBanners[banner_index].name }}</h5>#}{# 画像だけの場合もあるだろうから必須項目の「名称」は表示しない #}
  272.                                         {% if AddBanners[banner_index].bg_image %}
  273.                                             {% set filename = AddBanners[banner_index].bg_image|split('/') %}
  274.                                             <img src="{{ asset('addbanner' ,'save_image') ~ "/" ~ filename|last }}">
  275.                                         {% endif %}
  276.                                         {% if AddBanners[banner_index].description %}
  277.                                             <div class="add_banner_desc p-2">{{ AddBanners[banner_index].description|raw|nl2br }}</div>
  278.                                         {% endif %}
  279.                                     {% if AddBanners[banner_index].link_url %}
  280.                                         </a>
  281.                                     {% else %}
  282.                                         </div>
  283.                                     {% endif %}
  284.                                 </li>
  285.                                 {% set banner_index = banner_index + 1 %}
  286.                             {% endif %}
  287.                         {% endfor %}
  288.                     {% endif %}
  289.                 </ul>
  290.             </div>
  291.             <div class="ec-modal">
  292.                 <div class="ec-modal-overlay">
  293.                     <div class="ec-modal-wrap">
  294.                         <span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  295.                         <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  296.                         <div class="ec-modal-box">
  297.                             <div class="ec-role">
  298.                                 <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  299.                                 <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  300.                             </div>
  301.                         </div>
  302.                     </div>
  303.                 </div>
  304.             </div>
  305.             <div class="ec-pagerRole">
  306.                 {% include "pager.twig" with {'pages': pagination.paginationData} %}
  307.             </div>
  308.         {% endif %}
  309.     {% endif %}
  310. {% endblock %}