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 meta %}
  11.     {% set Maker = app.request.attributes.get('Maker') %}
  12.     {% if Maker %}
  13.         <meta name="robots" content="{{ Maker.noindexFlg ? 'noindex, nofollow' : 'index, follow' }}">
  14.         <title>{{ Maker.name }} 特集</title>
  15.         {% if Maker.metaDescription %}
  16.             <meta name="description" content="{{ Maker.metaDescription }}">
  17.         {% endif %}
  18.         {% if Maker.slug %}
  19.             <link rel="canonical" href="{{ url('product_maker', {'slug': Maker.slug}) }}">
  20.         {% endif %}
  21.     {% else %}
  22.         {% if app.request.query.all|length > 0 %}
  23.             <meta name="robots" content="noindex,follow">
  24.             <link rel="canonical" href="{{ url('product_list') }}">
  25.         {% elseif Page.meta_robots is not empty %}
  26.             <meta name="robots" content="{{ Page.meta_robots }}">
  27.         {% else %}
  28.             <link rel="canonical" href="{{ url('product_list') }}">
  29.         {% endif %}
  30.     {% endif %}
  31. {% endblock %}
  32. {% block javascript %}
  33.     {{ parent() }}
  34.     <script>
  35.         eccube.productsClassCategories = {
  36.             {% for Product in pagination %}
  37.             "{{ Product.id|escape('js') }}": {{ class_categories_as_json(Product)|raw }}{% if loop.last == false %}, {% endif %}
  38.             {% endfor %}
  39.         };
  40.         $(function() {
  41.             // 表示件数を変更
  42.             $('.disp-number').change(function() {
  43.                 var dispNumber = $(this).val();
  44.                 $('#disp_number').val(dispNumber);
  45.                 $('#pageno').val(1);
  46.                 $("#form1").submit();
  47.             });
  48.             // 並び順を変更
  49.             $('.order-by').change(function() {
  50.                 var orderBy = $(this).val();
  51.                 $('#orderby').val(orderBy);
  52.                 $('#pageno').val(1);
  53.                 $("#form1").submit();
  54.             });
  55.             // お気に入り追加
  56.             $('.add_favorite').on('click', function(e) {
  57.                 var data = $(this).data();
  58.                 if (confirm(data.product_name + '\r\n\r\n' + 'こちらの商品をお気に入りに登録しますか?') ) {
  59.                 } else {
  60.                     return false;
  61.                 }
  62.             });
  63.             
  64.             // ✅ classcategory_id1 のデフォルト設定
  65.            $('.add-cart').on('click', function(e) {
  66.                 var data = $(this).data();
  67.                 var $form = $('#productForm' + data.cartid);
  68.                 
  69.                 e.preventDefault();
  70.                 var formData = new FormData($form[0]);
  71.                 // ✅ `ProductClass` の値を確実にセット
  72.                 let productClassValue = $form.find('input[name="ProductClass"]').val();
  73.                 if (!productClassValue) {
  74.                     alert("商品規格が選択されていません");
  75.                     return;
  76.                 }
  77.                 formData.append('ProductClass', productClassValue);
  78.                 $.ajax({
  79.                     url: $form.attr('action'),
  80.                     type: $form.attr('method'),
  81.                     data: $form.serialize(),
  82.                     dataType: 'json',
  83.                     beforeSend: function(xhr, settings) {
  84.                         // Buttonを無効にする
  85.                         $('.add-cart').prop('disabled', true);
  86.                     }
  87.                 }).done(function(data) {
  88.                     // レスポンス内のメッセージをalertで表示
  89.                     $.each(data.messages, function() {
  90.                         $('#ec-modal-header').text(this);
  91.                     });
  92.                     $('.ec-modal').show()
  93.                     // カートブロックを更新する
  94.                     $.ajax({
  95.                         url: '{{ url('block_cart') }}',
  96.                         type: 'GET',
  97.                         dataType: 'html'
  98.                     }).done(function(html) {
  99.                         const $html = $('<div>').html(html);
  100.                         // ① ヘッダー用のカート部分を更新
  101.                         const $headerCart = $html.find('.ec-headerRole__cart');
  102.                         if ($headerCart.length) {
  103.                             $('.ec-headerRole__cart').replaceWith($headerCart);
  104.                         }
  105.                         // ② サイドカート(ec-cartNaviWrap)も更新
  106.                         const $sideCart = $html.find('.ec-cartNaviWrap');
  107.                         if ($sideCart.length) {
  108.                             $('.ec-cartNaviWrap').replaceWith($sideCart);
  109.                         }
  110.                     });
  111.                 }).fail(function(xhr, textStatus, errorThrown) {
  112.                     alert('{{ 'カートへの追加に失敗しました。' |trans }}');
  113.                 }).always(function(data) {
  114.                     // Buttonを有効にする
  115.                     $('.add-cart').prop('disabled', false);
  116.                 });
  117.             });
  118.         
  119.         $('.ec-modal-wrap').on('click', function(e) {
  120.             // モーダル内の処理は外側にバブリングさせない
  121.             e.stopPropagation();
  122.         });
  123.         $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  124.             $('.ec-modal').hide()
  125.         });
  126.     });
  127.     </script>
  128. {% endblock %}
  129. {% block main %}
  130.          
  131.         {% include 'Block/search_product.twig'  with {'form': search_form} %}
  132.          
  133.         <div class="ec-searchnavRole">
  134.             <form name="form1" id="form1" method="get" action="?">
  135.                 {% for item in search_form %}
  136.                     <input type="hidden" id="{{ item.vars.id }}"
  137.                            name="{{ item.vars.full_name }}"
  138.                            {% if item.vars.value is not empty %}value="{{ item.vars.value }}" {% endif %}/>
  139.                 {% endfor %}
  140.             </form>
  141.             <div class="ec-searchnavRole__topicpath">
  142.                 <ol class="ec-topicpath">
  143.                     <li class="ec-topicpath__item"><a href="{{ url('product_list') }}">{{ '全て'|trans }}</a>
  144.                     </li>
  145.                     {% if search_form.vars.value and search_form.vars.value.keyword %}
  146.                         <li class="ec-topicpath__divider">|</li>
  147.                         <li class="ec-topicpath__item">{{ '「%keyword%」の検索結果'|trans({ '%keyword%': search_form.vars.value.keyword }) }}</li>
  148.                     {% endif %}
  149.                 </ol>
  150.             </div>
  151.             <div class="ec-searchnavRole__infos">
  152.                 <div class="ec-searchnavRole__counter">
  153.                     {% if pagination.totalItemCount > 0 %}
  154.                         {{ '<span class="ec-font-bold">%count%件</span><span>の商品が見つかりました</span>'|trans({ '%count%': pagination.totalItemCount })|raw }}
  155.                     {% else %}
  156.                         <span>{{ 'お探しの商品は見つかりませんでした'|trans }}</span>
  157.                     {% endif %}
  158.                 </div>
  159.                 {% if pagination.totalItemCount > 0 %}
  160.                     <div class="ec-searchnavRole__actions">
  161.                         <div class="ec-select">
  162.                             {{ form_widget(search_form.disp_number, {'id': '', 'attr': {'class': 'disp-number'}}) }}
  163.                             {{ form_widget(search_form.orderby, {'id': '', 'attr': {'class': 'order-by'}}) }}
  164.                         </div>
  165.                     </div>
  166.                 {% endif %}
  167.             </div>
  168.         </div>
  169.         <style>
  170.             .product_page .ec-shelfGrid {
  171.                 justify-content: flex-start;
  172.                 gap: 12px;
  173.                 margin-left: 0 !important;
  174.                 margin-right: 0 !important;
  175.             }
  176.             @media only screen and (min-width: 1200px) {
  177.                 .product_page .ec-shelfGrid { gap: 16px; }
  178.                 /* PC版は改行なし */
  179.                 .product_page .ec-shelfGrid__item > div:first-child p { white-space: nowrap; }
  180.                 .product_page .ec-productRole__actions .ec-price { white-space: nowrap; }
  181.                 .product_page .add-cart-btn { white-space: nowrap; }
  182.             }
  183.             .product_page .ec-shelfGrid .ec-shelfGrid__item {
  184.                 box-sizing: border-box;
  185.                 display: flex;
  186.                 flex-direction: column;
  187.                 padding: 10px;
  188.                 margin: 0;
  189.                 width: auto;
  190.                 flex: 0 0 calc((100% - (12px * 1)) / 2);
  191.                 min-width: 0; /* 3列維持のため最小幅を許可 */
  192.             }
  193.             @media only screen and (min-width: 1200px) {
  194.                 .product_page .ec-shelfGrid .ec-shelfGrid__item {
  195.                     flex: 0 0 calc((100% - (16px * 3)) / 4);
  196.                 }
  197.             }
  198.             .product_page .ec-shelfGrid .ec-shelfGrid__item:nth-child(odd),
  199.             .product_page .ec-shelfGrid .ec-shelfGrid__item:nth-child(even) {
  200.                 padding-left: 0;
  201.                 padding-right: 0;
  202.             }
  203.             .product_page .ec-shelfGrid__item-image {
  204.                 width: 100%;
  205.                 overflow: hidden;
  206.             }
  207.             .product_page .ec-shelfGrid__item-image img {
  208.                 width: 100%;
  209.                 height: 100%;
  210.                 object-fit: cover;
  211.             }
  212.             .product_page .ec-shelfGrid__item-title h3 {
  213.                 margin: 8px 0 0;
  214.                 font-size: 0.9rem;
  215.                 line-height: 1.4;
  216.                 display: -webkit-box;
  217.                 -webkit-line-clamp: 3; /* 3行省略 */
  218.                 -webkit-box-orient: vertical;
  219.                 overflow: hidden;
  220.                 min-height: calc(1.4em * 3);
  221.             }
  222.             @media only screen and (min-width: 1200px) {
  223.                 .product_page .ec-shelfGrid__item-title h3 { font-size: 1rem; }
  224.             }
  225.             .product_page .ec-shelfGrid__item > div:first-child p {
  226.                 margin: 0 0 6px;
  227.                 font-size: 0.9rem;
  228.                 line-height: 1.2;
  229.             }
  230.             .product_page .ec-productRole__actions {
  231.                 display: flex;
  232.                 flex-direction: column;
  233.                 gap: 6px;
  234.                 margin-top: 10px; /* 商品名(ボタン)とプランの間を開ける */
  235.             }
  236.             .product_page .ec-productRole__actions dl {
  237.                 margin: 8px 0 6px; /* プラン直下の余白を縮小 */
  238.             }
  239.             .product_page .ec-productRole__actions .ec-select { margin: 4px 0; }
  240.             .product_page .ec-productRole__actions .ec-select select,
  241.             .product_page .ec-productRole__actions .ec-numberInput input { width: 100%; }
  242.             .product_page .ec-productRole__actions .ec-price {
  243.                 display: flex;
  244.                 align-items: baseline;
  245.                 gap: 6px;
  246.             }
  247.             .product_page .ec-productRole__actions .ec-price p { margin: 0; }
  248.             .product_page .ec-productRole__actions .ec-price .price02-default {
  249.                 font-weight: bold;
  250.                 font-size: 1rem;
  251.             }
  252.             @media only screen and (min-width: 1200px) {
  253.                 .product_page .ec-productRole__actions .ec-price .price02-default { font-size: 1.05rem; }
  254.             }
  255.             .product_page .product-detail-btn,
  256.             .product_page .add-cart-btn {
  257.                 font-size: 0.8rem;
  258.                 padding: 10px 12px;
  259.                 width: 100%;
  260.                 display: inline-block;
  261.             }
  262.             .product_page .ec-productRole__btn { margin-top: 8px; }
  263.             .product_page .ec-productRole__btn .ec-blockBtn--action,
  264.             .product_page .ec-productRole__btn .ec-blockBtn--cancel { width: 100%; }
  265.             /* =========================
  266.                SP専用の表示最適化
  267.                - 入荷日を1行
  268.                - 価格ラベルのみ縮小して1行
  269.                - カートボタン1行
  270.                - セレクトの内側余白/文字サイズ
  271.                ========================= */
  272.             @media screen and (max-width: 1199px) {
  273.                 /* グリッド間隔とカード内余白を少し詰める */
  274.                 .product_page .ec-shelfGrid { gap: 8px; }
  275.                 .product_page .ec-shelfGrid .ec-shelfGrid__item { padding: 8px; }
  276.                 /* 入荷日 1行化 */
  277.                 .product_page .ec-shelfGrid__item > div:first-child p {
  278.                     white-space: nowrap;
  279.                     font-size: 0.62rem;
  280.                     line-height: 1.1;
  281.                     letter-spacing: -0.02em;
  282.                 }
  283.                 /* 価格を1行に(値段は既存サイズのまま、ラベルのみ縮小) */
  284.                 .product_page .ec-productRole__actions .ec-price {
  285.                     white-space: nowrap;
  286.                     align-items: center;
  287.                     gap: 4px;
  288.                     line-height: 1.1;
  289.                 }
  290.                 .product_page .ec-productRole__actions .ec-price p:first-child {
  291.                     font-size: 0.6rem;
  292.                     letter-spacing: -0.02em;
  293.                     display: inline-block;
  294.                 }
  295.                 /* 「買い物かごに入れる」を1行に */
  296.                 .product_page .add-cart-btn {
  297.                     white-space: nowrap;
  298.                     font-size: 0.62rem;
  299.                     padding: 6px 6px;
  300.                     letter-spacing: -0.02em;
  301.                 }
  302.                 /* プランのセレクト調整 */
  303.                 .product_page .ec-productRole__actions .ec-select select {
  304.                     padding: 6px 3px;
  305.                     font-size: 14px;
  306.                 }
  307.                 /* タイトルはSPで少し小さく・行間詰め */
  308.                 .product_page .ec-shelfGrid__item-title h3 {
  309.                     font-size: 0.78rem;
  310.                     line-height: 1.3;
  311.                     min-height: calc(1.3em * 3);
  312.                 }
  313.                 /* プラン見出しのサイズ微調整 */
  314.                 .product_page .ec-productRole__actions dl dt { font-size: 0.8rem; }
  315.             }
  316.         </style>
  317.         {% if pagination.totalItemCount > 0 %}
  318.             <div class="ec-shelfRole">
  319.                 <ul class="ec-shelfGrid">
  320.                     {% for Product in pagination %}
  321.                         <li class="ec-shelfGrid__item">
  322.                             <div>
  323.                                 <p style="color:white;">入荷日:
  324.                                     {{ Product.ProductCategories|first.Category.name[:4] ~ '年' ~ Product.ProductCategories|first.Category.name[4:2] ~ '月' ~ Product.ProductCategories|first.Category.name[6:2] ~ '日' }}
  325.                                 </p>
  326.                             </div>
  327.                             <!--▼商品画像▼-->
  328.                             {# {{ dump(asset(Product.list_image, 'save_image')) }} #}
  329.                             <div class="ec-shelfGrid__item-image">
  330.                                 <a href="{{ url('product_detail', {'id': Product.id}) }}">
  331.                                     <img src="{{ asset(Product.list_image|no_image_product, 'save_image') }}" 
  332.                                          alt="{{ Product.name }}" 
  333.                                          width="300" 
  334.                                          height="300"
  335.                                          {% if loop.index <= 3 %}loading="eager"{% else %}loading="lazy"{% endif %}
  336.                                          sizes="(max-width: 768px) 33vw, (max-width: 1200px) 25vw, 20vw" />
  337.                                 </a>
  338.                             </div>
  339.                             <!--▼商品名▼-->
  340.                             <div class="ec-shelfGrid__item-title">
  341.                                 <a href="{{ url('product_detail', {'id': Product.id}) }}">
  342.                                     <h3>{{ Product.name }}</h3>
  343.                                 </a>
  344.                             </div>
  345.                             <!--▼商品詳細を見る▼-->
  346.                             <a class="product-detail-btn" href="{{ url('product_detail', {'id': Product.id}) }}">商品詳細を見る</a>
  347.                             
  348.                             <!--▼買い物かご▼-->
  349.                             {% if Product.stock_find %}
  350.                                 {% set form = forms[Product.id] %}
  351.                                 <form name="form{{ Product.id }}" id="productForm{{ Product.id }}" action="{{ url('product_add_cart', {id:Product.id}) }}" method="post">
  352.                                     <input type="hidden" name="ProductClass" value="{{ Product.getProductClasses().first().id }}">
  353.                                     <div class="ec-productRole__actions">
  354.                                       <dl>
  355.                                         <dt>▼プラン▼</dt>
  356.                                         <dd>
  357.                                           {% if form.classcategory_id1 is defined %}
  358.                                             <div class="ec-select">
  359.                                                 {{ form_widget(form.classcategory_id1) }}
  360.                                                 {{ form_errors(form.classcategory_id1) }}
  361.                                             </div>
  362.                                             {% if form.classcategory_id2 is defined %}
  363.                                                 <div class="ec-select">
  364.                                                     {{ form_widget(form.classcategory_id2) }}
  365.                                                     {{ form_errors(form.classcategory_id2) }}
  366.                                                 </div>
  367.                                             {% endif %}
  368.                                         {% endif %}
  369.                                         </dd>
  370.                                       </dl>
  371.                                       <div class="ec-numberInput">
  372.                                           {{ form_widget(form.quantity, { data: '1', type: 'hidden'} ) }}
  373.                                           {{ form_errors(form.quantity) }}
  374.                                       </div>
  375.                                       <div class="ec-price">
  376.                                         <p>価格(税込) :</p>
  377.                                         <p class="price02-default">
  378.                                             {{ Product.getPrice02IncTaxMin|price }}
  379.                                         </p>
  380.                                       </div>
  381.                                       <button class="add-cart-btn add-cart" data-cartid="{{ Product.id }}" form="productForm{{ Product.id }}" >買い物かごに入れる▶</button>
  382.                                       <!--
  383.                                       <div class="ec-productRole__btn">      
  384.                                             <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 }}" />
  385.                                       </div>
  386.                                       -->
  387.                                       {{ form_rest(form) }}
  388.                                    </div>
  389.                                 </form>
  390.                             {% else %}
  391.                                 <div class="ec-productRole__btn">
  392.                                     <button type="button" class="ec-blockBtn--action" disabled="disabled">
  393.                                         {{ 'ただいま品切れ中です。'|trans }}
  394.                                     </button>
  395.                                 </div>
  396.                             {% endif %}
  397.                             
  398.                             {#
  399.                             {% if BaseInfo.option_favorite_product %}
  400.                               <form action="{{ url('product_add_favorite', {id:Product.id}) }}" method="post">
  401.                                 <div class="ec-productRole__btn">
  402.                                   {% if favorite[Product.id] == false %}
  403.                                     <input type="image" class="ec-blockBtn--cancel add_favorite" src="{{ asset('assets/img/new/img_favorite-add.png') }}" alt="お気に入りに追加" data-product_name="{{ Product.name}}" />
  404.                                   {% else %}
  405.                                     <input type="image" class="ec-blockBtn--cancel" disabled="disabled" src="{{ asset('assets/img/new/img_favorite-added.png') }}" alt="お気に入りに追加済" />
  406.                                   {% endif %}
  407.                                 </div>
  408.                               </form>
  409.                             {% endif %}
  410.                             #}
  411.                         </li>
  412.                     {% endfor %}
  413.                 </ul>
  414.             </div>
  415.             <div class="ec-modal">
  416.                 <div class="ec-modal-overlay">
  417.                     <div class="ec-modal-wrap">
  418.                         <span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  419.                         <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  420.                         <div class="ec-modal-box">
  421.                             <div class="ec-role">
  422.                                 <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  423.                                 <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  424.                             </div>
  425.                         </div>
  426.                     </div>
  427.                 </div>
  428.             </div>
  429.             <div class="ec-pagerRole">
  430.                 {% include "pager.twig" with {'pages': pagination.paginationData} %}
  431.             </div>
  432.         {% endif %}
  433.     
  434. {% endblock %}