app/template/BlackCherry/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.     {{ parent() }}
  12.     <script>
  13.         eccube.productsClassCategories = {
  14.             {% for Product in pagination %}
  15.             "{{ Product.id|escape('js') }}": {{ class_categories_as_json(Product)|raw }}{% if loop.last == false %}, {% endif %}
  16.             {% endfor %}
  17.         };
  18.         $(function() {
  19.             // 表示件数を変更
  20.             $('.disp-number').change(function() {
  21.                 var dispNumber = $(this).val();
  22.                 $('#disp_number').val(dispNumber);
  23.                 $('#pageno').val(1);
  24.                 $("#form1").submit();
  25.             });
  26.             // 並び順を変更
  27.             $('.order-by').change(function() {
  28.                 var orderBy = $(this).val();
  29.                 $('#orderby').val(orderBy);
  30.                 $('#pageno').val(1);
  31.                 $("#form1").submit();
  32.             });
  33.             // お気に入り追加
  34.             $('.add_favorite').on('click', function(e) {
  35.                 var data = $(this).data();
  36.                 if (confirm(data.product_name + '\r\n\r\n' + 'こちらの商品をお気に入りに登録しますか?') ) {
  37.                 } else {
  38.                     return false;
  39.                 }
  40.             });
  41.             
  42.             // ✅ classcategory_id1 のデフォルト設定
  43.            $('.add-cart').on('click', function(e) {
  44.                 var data = $(this).data();
  45.                 var $form = $('#productForm' + data.cartid);
  46.                 
  47.                 e.preventDefault();
  48.                 var formData = new FormData($form[0]);
  49.                 // ✅ `ProductClass` の値を確実にセット
  50.                 let productClassValue = $form.find('input[name="ProductClass"]').val();
  51.                 if (!productClassValue) {
  52.                     alert("商品規格が選択されていません");
  53.                     return;
  54.                 }
  55.                 formData.append('ProductClass', productClassValue);
  56.                 $.ajax({
  57.                     url: $form.attr('action'),
  58.                     type: $form.attr('method'),
  59.                     data: $form.serialize(),
  60.                     dataType: 'json',
  61.                     beforeSend: function(xhr, settings) {
  62.                         // Buttonを無効にする
  63.                         $('.add-cart').prop('disabled', true);
  64.                     }
  65.                 }).done(function(data) {
  66.                     // レスポンス内のメッセージをalertで表示
  67.                     $.each(data.messages, function() {
  68.                         $('#ec-modal-header').text(this);
  69.                     });
  70.                     $('.ec-modal').show()
  71.                     // カートブロックを更新する
  72.                     $.ajax({
  73.                         url: '{{ url('block_cart') }}',
  74.                         type: 'GET',
  75.                         dataType: 'html'
  76.                     }).done(function(html) {
  77.                         const $html = $('<div>').html(html);
  78.                         // ① ヘッダー用のカート部分を更新
  79.                         const $headerCart = $html.find('.ec-headerRole__cart');
  80.                         if ($headerCart.length) {
  81.                             $('.ec-headerRole__cart').replaceWith($headerCart);
  82.                         }
  83.                         // ② サイドカート(ec-cartNaviWrap)も更新
  84.                         const $sideCart = $html.find('.ec-cartNaviWrap');
  85.                         if ($sideCart.length) {
  86.                             $('.ec-cartNaviWrap').replaceWith($sideCart);
  87.                         }
  88.                     });
  89.                 }).fail(function(xhr, textStatus, errorThrown) {
  90.                     alert('{{ 'カートへの追加に失敗しました。' |trans }}');
  91.                 }).always(function(data) {
  92.                     // Buttonを有効にする
  93.                     $('.add-cart').prop('disabled', false);
  94.                 });
  95.             });
  96.         
  97.         $('.ec-modal-wrap').on('click', function(e) {
  98.             // モーダル内の処理は外側にバブリングさせない
  99.             e.stopPropagation();
  100.         });
  101.         $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  102.             $('.ec-modal').hide()
  103.         });
  104.     });
  105.     </script>
  106. {% endblock %}
  107. {% block main %}
  108.          
  109.         {% include 'Block/search_product.twig'  with {'form': search_form} %}
  110.          
  111.         <div class="ec-searchnavRole">
  112.             <form name="form1" id="form1" method="get" action="?">
  113.                 {% for item in search_form %}
  114.                     <input type="hidden" id="{{ item.vars.id }}"
  115.                            name="{{ item.vars.full_name }}"
  116.                            {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %}/>
  117.                 {% endfor %}
  118.             </form>
  119.             <div class="ec-searchnavRole__topicpath">
  120.                 <ol class="ec-topicpath">
  121.                     <li class="ec-topicpath__item"><a href="{{ url('product_list') }}">{{ '全て'|trans }}</a>
  122.                     </li>
  123.                     {% if search_form.vars.value and search_form.vars.value.keyword %}
  124.                         <li class="ec-topicpath__divider">|</li>
  125.                         <li class="ec-topicpath__item">{{ '「%keyword%」の検索結果'|trans({ '%keyword%': search_form.vars.value.keyword }) }}</li>
  126.                     {% endif %}
  127.                 </ol>
  128.             </div>
  129.             <div class="ec-searchnavRole__infos">
  130.                 <div class="ec-searchnavRole__counter">
  131.                     {% if pagination.totalItemCount > 0 %}
  132.                         {{ '<span class="ec-font-bold">%count%件</span><span>の商品が見つかりました</span>'|trans({ '%count%': pagination.totalItemCount })|raw }}
  133.                     {% else %}
  134.                         <span>{{ 'お探しの商品は見つかりませんでした'|trans }}</span>
  135.                     {% endif %}
  136.                 </div>
  137.                 {% if pagination.totalItemCount > 0 %}
  138.                     <div class="ec-searchnavRole__actions">
  139.                         <div class="ec-select">
  140.                             {{ form_widget(search_form.disp_number, {'id': '', 'attr': {'class': 'disp-number'}}) }}
  141.                             {{ form_widget(search_form.orderby, {'id': '', 'attr': {'class': 'order-by'}}) }}
  142.                         </div>
  143.                     </div>
  144.                 {% endif %}
  145.             </div>
  146.         </div>
  147.         {% if pagination.totalItemCount > 0 %}
  148.             <div class="ec-shelfRole">
  149.                 <ul class="ec-shelfGrid">
  150.                     {% for Product in pagination %}
  151.                         <li class="ec-shelfGrid__item">
  152.                             <div>
  153.                                 <p style="color:white;">入荷日:
  154.                                     {{ Product.ProductCategories|first.Category.name[:4] ~ '年' ~ Product.ProductCategories|first.Category.name[4:2] ~ '月' ~ Product.ProductCategories|first.Category.name[6:2] ~ '日' }}
  155.                                 </p>
  156.                             </div>
  157.                             <!--▼商品画像▼-->
  158.                             {# {{ dump(asset(Product.list_image, 'save_image')) }} #}
  159.                             <div class="ec-shelfGrid__item-image">
  160.                                 <a href="{{ url('product_detail', {'id': Product.id}) }}">
  161.                                     <img src="{{ asset(Product.list_image|no_image_product, 'save_image') }}" alt="{{ Product.name }}" {% if loop.index > 5 %} loading="lazy"{% endif %}>
  162.                                 </a>
  163.                             </div>
  164.                             <!--▼商品名▼-->
  165.                             <div class="ec-shelfGrid__item-title">
  166.                                 <a href="{{ url('product_detail', {'id': Product.id}) }}">
  167.                                      <h3>{{ Product.name | length > 50 ? Product.name|slice(0, 50) ~ '…' : Product.name }}</h3>
  168.                                 </a>
  169.                             </div>
  170.                             <!--▼商品詳細を見る▼-->
  171.                             <a class="product-detail-btn" href="{{ url('product_detail', {'id': Product.id}) }}">商品詳細を見る</a>
  172.                             
  173.                             <!--▼買い物かご▼-->
  174.                             {% if Product.stock_find %}
  175.                                 {% set form = forms[Product.id] %}
  176.                                 <form name="form{{ Product.id }}" id="productForm{{ Product.id }}" action="{{ url('product_add_cart', {id:Product.id}) }}" method="post">
  177.                                     <input type="hidden" name="ProductClass" value="{{ Product.getProductClasses().first().id }}">
  178.                                     <div class="ec-productRole__actions">
  179.                                       <dl>
  180.                                         <dt>▼プラン▼</dt>
  181.                                         <dd>
  182.                                           {% if form.classcategory_id1 is defined %}
  183.                                             <div class="ec-select">
  184.                                                 {{ form_widget(form.classcategory_id1) }}
  185.                                                 {{ form_errors(form.classcategory_id1) }}
  186.                                             </div>
  187.                                             {% if form.classcategory_id2 is defined %}
  188.                                                 <div class="ec-select">
  189.                                                     {{ form_widget(form.classcategory_id2) }}
  190.                                                     {{ form_errors(form.classcategory_id2) }}
  191.                                                 </div>
  192.                                             {% endif %}
  193.                                         {% endif %}
  194.                                         </dd>
  195.                                       </dl>
  196.                                       <div class="ec-numberInput">
  197.                                           {{ form_widget(form.quantity, { data: '1', type: 'hidden'} ) }}
  198.                                           {{ form_errors(form.quantity) }}
  199.                                       </div>
  200.                                       <div class="ec-price">
  201.                                         <p>価格(税込) :</p>
  202.                                         <p class="price02-default">
  203.                                             {{ Product.getPrice02IncTaxMin|price }}
  204.                                         </p>
  205.                                       </div>
  206.                                       <button class="add-cart-btn add-cart" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}" >買い物かごに入れる▶</button>
  207.                                       <!--
  208.                                       <div class="ec-productRole__btn">      
  209.                                             <input type="image" src="{{ asset('assets/img/new/img_cart-add.png') }}" alt="カートに入れる" class="ec-blockBtn--action add-cart" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}" />
  210.                                       </div>
  211.                                       -->
  212.                                       {{ form_rest(form) }}
  213.                                    </div>
  214.                                 </form>
  215.                             {% else %}
  216.                                 <div class="ec-productRole__btn">
  217.                                     <button type="button" class="ec-blockBtn--action" disabled="disabled">
  218.                                         {{ 'ただいま品切れ中です。'|trans }}
  219.                                     </button>
  220.                                 </div>
  221.                             {% endif %}
  222.                             
  223.                             {#
  224.                             {% if BaseInfo.option_favorite_product %}
  225.                               <form action="{{ url('product_add_favorite', {id:Product.id}) }}" method="post">
  226.                                 <div class="ec-productRole__btn">
  227.                                   {% if favorite[Product.id] == false %}
  228.                                     <input type="image" class="ec-blockBtn--cancel add_favorite" src="{{ asset('assets/img/new/img_favorite-add.png') }}" alt="お気に入りに追加" data-product_name="{{ Product.name}}" />
  229.                                   {% else %}
  230.                                     <input type="image" class="ec-blockBtn--cancel" disabled="disabled" src="{{ asset('assets/img/new/img_favorite-added.png') }}" alt="お気に入りに追加済" />
  231.                                   {% endif %}
  232.                                 </div>
  233.                               </form>
  234.                             {% endif %}
  235.                             #}
  236.                         </li>
  237.                     {% endfor %}
  238.                 </ul>
  239.             </div>
  240.             <div class="ec-modal">
  241.                 <div class="ec-modal-overlay">
  242.                     <div class="ec-modal-wrap">
  243.                         <span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  244.                         <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  245.                         <div class="ec-modal-box">
  246.                             <div class="ec-role">
  247.                                 <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  248.                                 <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  249.                             </div>
  250.                         </div>
  251.                     </div>
  252.                 </div>
  253.             </div>
  254.             <div class="ec-pagerRole">
  255.                 {% include "pager.twig" with {'pages': pagination.paginationData} %}
  256.             </div>
  257.         {% endif %}
  258.     
  259. {% endblock %}