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 = 'list_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.         // カートに追加ボタンのイベントハンドラ
  33.         $('.add-cart').on('click', function (e) {
  34.             // デフォルトのフォーム送信を必ず阻止する
  35.             e.preventDefault();
  36.             var $form = $(this).closest('form');
  37.             if (!$form.length) {
  38.                 $form = $('#productForm' + $(this).data('cartid'));
  39.             }
  40.             // 個数フォームのチェック
  41.             var $quantity = $form.find('.quantity');
  42.             if ($quantity.val() < 1) {
  43.                 $quantity[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  44.                 return true;
  45.             } else {
  46.                 $quantity[0].setCustomValidity('');
  47.             }
  48.             // ボタンを無効化して二重送信を防止
  49.             $('.add-cart').prop('disabled', true);
  50.             // デバッグ用 - フォームの内容確認
  51.             console.log('Form action:', $form.attr('action'));
  52.             console.log('Form data:', $form.serialize());
  53.             $.ajax({
  54.                 url: $form.attr('action'),
  55.                 type: $form.attr('method'),
  56.                 data: $form.serialize(),
  57.                 dataType: 'json'
  58.             }).done(function (data) {
  59.                 console.log('Success:', data);
  60.                 // レスポンス内のメッセージをモーダルに表示
  61.                 if (data.messages && data.messages.length > 0) {
  62.                     $('#ec-modal-header').text(data.messages[0]);
  63.                 } else {
  64.                     $('#ec-modal-header').text('{{ 'カートに追加しました。'|trans }}');
  65.                 }
  66.                 // モーダルを表示
  67.                 $('.ec-modal').show();
  68.                 // カートブロックを更新する
  69.                 $.ajax({
  70.                     url: '{{ url('block_cart') }}',
  71.                     type: 'GET',
  72.                     dataType: 'html'
  73.                 }).done(function (html) {
  74.                     $('.ec-headerRole__cart').html(html);
  75.                 });
  76.             }).fail(function (data) {
  77.                 console.error('Error:', data);
  78.                 alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  79.             }).always(function (data) {
  80.                 // Buttonを有効にする
  81.                 $('.add-cart').prop('disabled', false);
  82.             });
  83.         });
  84.         // モーダル関連のイベントハンドラ - ここに移動
  85.         $('.ec-modal-wrap').on('click', function (e) {
  86.             // モーダル内の処理は外側にバブリングさせない
  87.             e.stopPropagation();
  88.         });
  89.         $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function () {
  90.             $('.ec-modal').hide();
  91.         });
  92.     });
  93. </script>
  94. {% endblock %}
  95. {% block main %}
  96. {# 特定のカテゴリIDまたは商品IDの時に「Hello World」を表示 #}
  97. {% if Category is not null and Category.id == 10 %}
  98. <div class="ec-hello-message">
  99.     {#<p>Hello World</p>#}
  100. </div>
  101. {% endif %}
  102. {# パンくず #}
  103. {% include 'Block/breadcrumb.twig' %}
  104. {% if search_form.category_id.vars.errors|length > 0 %}
  105. <div class="ec-searchnavRole">
  106.     <p class="errormsg text-danger">{{ 'ご指定のカテゴリは存在しません'|trans }}</p>
  107. </div>
  108. {% else %}
  109. <div class="ec-searchnavRole">
  110.     <form name="form1" id="form1" method="get" action="?">
  111.         {% for item in search_form %}
  112.         <input type="hidden" id="{{ item.vars.id }}" name="{{ item.vars.full_name }}" {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %} />
  113.         {% endfor %}
  114.     </form>
  115.     <div class="ec-searchnavRole__topicpath">
  116.         <ol class="ec-topicpath">
  117.             {#<li class="ec-topicpath__item"><a href="{{ url('product_list') }}">{{ '全て'|trans }}</a>
  118.             </li>
  119.             {% if Category is not null %}
  120.             {% for Path in Category.path %}
  121.             <li class="ec-topicpath__divider">|</li>
  122.             <li class="ec-topicpath__item{% if loop.last %}--active{% endif %}"><a href="{{ url('product_list') }}?category_id={{ Path.id }}">{{ Path.name }}</a>
  123.             </li>
  124.             {% endfor %}
  125.             {% endif %}#}
  126.             {% if search_form.vars.value and search_form.vars.value.name %}
  127.             <li class="ec-topicpath__divider">|</li>
  128.             <li class="ec-topicpath__item">{{ '「%name%」の検索結果'|trans({ '%name%': search_form.vars.value.name }) }}</li>
  129.             {% endif %}
  130.         </ol>
  131.     </div>
  132.     <div class="ec-searchnavRole__infos">
  133.         <div class="ec-searchnavRole__counter">
  134.             {% if pagination.totalItemCount > 0 %}
  135.             {{ '<span class="ec-font-bold">%count%件</span><span>の商品が見つかりました</span>'|trans({ '%count%': pagination.totalItemCount })|raw }}
  136.             {% else %}
  137.             <span>{{ 'お探しの商品は見つかりませんでした'|trans }}</span>
  138.             {% endif %}
  139.         </div>
  140.         {% if pagination.totalItemCount > 0 %}
  141.         <div class="ec-searchnavRole__actions">
  142.             <div class="ec-select">
  143.                 {{ form_widget(search_form.disp_number, {'id': '', 'attr': {'class': 'disp-number'}}) }}
  144.                 {{ form_widget(search_form.orderby, {'id': '', 'attr': {'class': 'order-by'}}) }}
  145.             </div>
  146.         </div>
  147.         {% endif %}
  148.     </div>
  149. </div>
  150. {% if pagination.totalItemCount > 0 %}
  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.                 <div class="ec-shelfGrid__item-wrap">
  157.                     <div class="ec-shelfGrid__item-imageWrap">
  158.                         <p class="ec-shelfGrid__item-image">
  159.                             <img src="{{ asset(Product.main_list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}" {% if loop.index > 5 %} loading="lazy"{% endif %}>
  160.                             {# 商品タグの表示 #}
  161.                             {% if Product.Tags|length > 0 %}
  162.                             <ul class="ec-productRole__tags">
  163.                                 {% for Tag in Product.Tags %}
  164.                                 <li class="ec-productRole__tag tag_{{ Tag.id }}"></li>
  165.                                 {% endfor %}
  166.                             </ul>
  167.                             {% endif %}
  168.                         </p>
  169.                     </div>
  170.                     <div class="ec-shelfGrid__item-textWrap">
  171.                     <p class="ec-productRole__item-title">{{ Product.name }}</p>
  172.                     {% if Product.description_list %}
  173.                     <div class="ec-productRole__item-description">{{ Product.description_list|raw }}</div>
  174.                     {% endif %}
  175.                     <p class="ec-productRole__item-price">
  176.                         {% if Product.hasProductClass %}
  177.                             {% if Product.getPrice02Min == Product.getPrice02Max %}
  178.                                 {{ Product.getPrice02IncTaxMin|number_format }}円 <span class="ec-price__tax">(税込)</span>
  179.                             {% else %}
  180.                                 {{ Product.getPrice02IncTaxMin|number_format }}円 ~ {{ Product.getPrice02IncTaxMax|number_format }}円 <span class="ec-price__tax">(税込)</span>
  181.                             {% endif %}
  182.                         {% else %}
  183.                             {{ Product.getPrice02IncTaxMin|number_format }}円 <span class="ec-price__tax">(税込)</span>
  184.                         {% endif %}
  185.                     </p>
  186.                     </div>
  187.                 </div>
  188.             </a>
  189.             {% if Product.stock_find %}
  190.             {% set form = forms[Product.id] %}
  191.             <form name="form{{ Product.id }}" id="productForm{{ Product.id }}" action="{{ url('product_add_cart', {id:Product.id}) }}" method="post">
  192.                 <div class="ec-productRole__actions">
  193.                     {% if form.classcategory_id1 is defined %}
  194.                     <div class="ec-select">
  195.                         {{ form_widget(form.classcategory_id1) }}
  196.                         {{ form_errors(form.classcategory_id1) }}
  197.                     </div>
  198.                     {% if form.classcategory_id2 is defined %}
  199.                     <div class="ec-select">
  200.                         {{ form_widget(form.classcategory_id2) }}
  201.                         {{ form_errors(form.classcategory_id2) }}
  202.                     </div>
  203.                     {% endif %}
  204.                     {% endif %}
  205.                     <!-- 数量入力とボタンを一つのdivで囲む -->
  206.                     <div class="ec-productActions">
  207.                         <div class="ec-numberInput"><span>{{ '数量'|trans }}</span>
  208.                             {{ form_widget(form.quantity, {'attr': {'class': 'quantity'}}) }}
  209.                             {{ form_errors(form.quantity) }}
  210.                         </div>
  211.                         <div class="ec-productRole__btn">
  212.                             <button type="button" class="ec-blockBtn--action add-cart" data-cartid="{{ Product.id }}">
  213.                                 {{ 'カートに入れる'|trans }}
  214.                             </button>
  215.                         </div>
  216.                     </div>
  217.                 </div>
  218.                 {{ form_rest(form) }}
  219.             </form>
  220.             {% else %}
  221.             <div class="ec-productRole__btn">
  222.                 <button type="button" class="ec-blockBtn--action" disabled="disabled">
  223.                     {{ 'オンライン在庫なし'|trans }}
  224.                 </button>
  225.             </div>
  226.             {% endif %}
  227.         </li>
  228.         {% endfor %}
  229.     </ul>
  230. </div>
  231. <div class="ec-modal">
  232.     <div class="ec-modal-overlay">
  233.         <div class="ec-modal-wrap">
  234.             <span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt="" /></span></span>
  235.             <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  236.             <div class="ec-modal-box">
  237.                 <div class="ec-role">
  238.                     <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  239.                     <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  240.                 </div>
  241.             </div>
  242.         </div>
  243.     </div>
  244. </div>
  245. <div class="ec-pagerRole">
  246.     {% include "pager.twig" with {'pages': pagination.paginationData} %}
  247. </div>
  248. {% endif %}
  249. {% endif %}
  250. {% endblock %}