app/template/default/Product/detail.twig line 1

Open in your IDE?
  1. {% extends 'default_frame.twig' %}
  2. {% set body_class = 'product_page' %}
  3. {% block stylesheet %}
  4.     <style>
  5.         /* カスタム画像表示用CSS */
  6.         @media (min-width: 768px) {
  7.             .min-width768-hide{
  8.                 display:none;
  9.             }
  10.         }
  11.         @media (max-width: 768px) {
  12.             .max-width768-hide{
  13.                 display:none;         
  14.             }
  15.         }
  16.         .description-sp{
  17.             font-size:14px;
  18.             
  19.         }
  20.         .ec-headingTitle{
  21.         font-weight: 700;
  22.         color: #654231;
  23.         font-size: 24px;
  24.         padding:4px;
  25.         border-bottom: 2px solid #654231;
  26.         letter-spacing: 1px;
  27.         position: relative;
  28.         text-align: left;
  29. ]        }
  30.         
  31.         .custom-product-images {
  32.             margin-bottom: 30px;
  33.         }
  34.         
  35.         .custom-main-image {
  36.             width: 100%;
  37.             max-width: 550px;
  38.             margin-bottom: 20px;
  39.             position: relative;
  40.             aspect-ratio: 1;
  41.             overflow: hidden;
  42.             border-radius: 8px;
  43.             box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  44.         }
  45.         
  46.         .custom-main-image img {
  47.             width: 100%;
  48.             height: 100%;
  49.             object-fit: cover;
  50.             display: block;
  51.             transition: opacity 0.3s ease;
  52.         }
  53.         
  54.         .custom-thumbnails {
  55.             display: flex;
  56.             gap: 10px;
  57.             flex-wrap: wrap;
  58.             justify-content: flex-start;
  59.         }
  60.         
  61.         .custom-thumbnail {
  62.             width: 80px;
  63.             height: 80px;
  64.             border-radius: 4px;
  65.             overflow: hidden;
  66.             cursor: pointer;
  67.             border: 2px solid transparent;
  68.             transition: border-color 0.3s ease, transform 0.2s ease;
  69.         }
  70.         
  71.         .custom-thumbnail:hover {
  72.             border-color: #007bff;
  73.             transform: scale(1.05);
  74.         }
  75.         
  76.         .custom-thumbnail.active {
  77.             border-color: #007bff;
  78.         }
  79.         
  80.         .custom-thumbnail img {
  81.             width: 100%;
  82.             height: 100%;
  83.             object-fit: cover;
  84.             display: block;
  85.         }
  86.         
  87.         /* レスポンシブ対応 */
  88.         @media (max-width: 768px) {
  89.             .custom-main-image {
  90.                 max-width: 100%;
  91.             }
  92.             
  93.             .custom-thumbnail {
  94.                 width: 60px;
  95.                 height: 60px;
  96.             }
  97.             
  98.             .custom-thumbnails {
  99.                 justify-content: center;
  100.             }
  101.         }
  102.         
  103.         /* フェードイン効果 */
  104.         .fade-in {
  105.             animation: fadeIn 0.3s ease-in;
  106.         }
  107.         
  108.         @keyframes fadeIn {
  109.             from { opacity: 0; }
  110.             to { opacity: 1; }
  111.         }
  112.     </style>
  113. {% endblock %}
  114. {% block javascript %}
  115.     <script>
  116.         eccube.classCategories = {{ class_categories_as_json(Product)|raw }};
  117.         // 規格2に選択肢を割り当てる。
  118.         function fnSetClassCategories(form, classcat_id2_selected) {
  119.             var $form = $(form);
  120.             var product_id = $form.find('input[name=product_id]').val();
  121.             var $sele1 = $form.find('select[name=classcategory_id1]');
  122.             var $sele2 = $form.find('select[name=classcategory_id2]');
  123.             eccube.setClassCategories($form, product_id, $sele1, $sele2, classcat_id2_selected);
  124.         }
  125.         {% if form.classcategory_id2 is defined %}
  126.         fnSetClassCategories(
  127.             $('#form1'), {{ form.classcategory_id2.vars.value|json_encode|raw }}
  128.         );
  129.         {% elseif form.classcategory_id1 is defined %}
  130.         eccube.checkStock($('#form1'), {{ Product.id }}, {{ form.classcategory_id1.vars.value|json_encode|raw }}, null);
  131.         {% endif %}
  132.     </script>
  133.     
  134.     <script>
  135.         $(function() {
  136.             // bfcache無効化
  137.             $(window).bind('pageshow', function(event) {
  138.                 if (event.originalEvent.persisted) {
  139.                     location.reload(true);
  140.                 }
  141.             });
  142.             // カスタム画像表示の処理
  143.             $('.custom-thumbnail').on('click', function() {
  144.                 var newSrc = $(this).find('img').attr('src');
  145.                 var newAlt = $(this).find('img').attr('alt');
  146.                 
  147.                 // アクティブ状態の切り替え
  148.                 $('.custom-thumbnail').removeClass('active');
  149.                 $(this).addClass('active');
  150.                 
  151.                 // メイン画像の切り替え
  152.                 var $mainImg = $('.custom-main-image img');
  153.                 $mainImg.fadeOut(200, function() {
  154.                     $mainImg.attr('src', newSrc).attr('alt', newAlt);
  155.                     $mainImg.fadeIn(200);
  156.                 });
  157.             });
  158.             
  159.             // 初期状態で最初のサムネイルをアクティブに
  160.             $('.custom-thumbnail').first().addClass('active');
  161.         });
  162.     </script>
  163.     
  164.     <script>
  165.         $(function() {
  166.             $('.add-cart').on('click', function(event) {
  167.                 {% if form.classcategory_id1 is defined %}
  168.                 // 規格1フォームの必須チェック
  169.                 if ($('#classcategory_id1').val() == '__unselected' || $('#classcategory_id1').val() == '') {
  170.                     $('#classcategory_id1')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  171.                     return true;
  172.                 } else {
  173.                     $('#classcategory_id1')[0].setCustomValidity('');
  174.                 }
  175.                 {% endif %}
  176.                 {% if form.classcategory_id2 is defined %}
  177.                 // 規格2フォームの必須チェック
  178.                 if ($('#classcategory_id2').val() == '__unselected' || $('#classcategory_id2').val() == '') {
  179.                     $('#classcategory_id2')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  180.                     return true;
  181.                 } else {
  182.                     $('#classcategory_id2')[0].setCustomValidity('');
  183.                 }
  184.                 {% endif %}
  185.                 // 個数フォームのチェック
  186.                 if ($('#quantity').val() < 1) {
  187.                     $('#quantity')[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  188.                     return true;
  189.                 } else {
  190.                     $('#quantity')[0].setCustomValidity('');
  191.                 }
  192.                 event.preventDefault();
  193.                 $form = $('#form1');
  194.                 $.ajax({
  195.                     url: $form.attr('action'),
  196.                     type: $form.attr('method'),
  197.                     data: $form.serialize(),
  198.                     dataType: 'json',
  199.                     beforeSend: function(xhr, settings) {
  200.                         // Buttonを無効にする
  201.                         $('.add-cart').prop('disabled', true);
  202.                     }
  203.                 }).done(function(data) {
  204.                     // レスポンス内のメッセージをalertで表示
  205.                     $.each(data.messages, function() {
  206.                         $('#ec-modal-header').html(this);
  207.                     });
  208.                     $('.ec-modal').show()
  209.                     // カートブロックを更新する
  210.                     $.ajax({
  211.                         url: "{{ url('block_cart') }}",
  212.                         type: 'GET',
  213.                         dataType: 'html'
  214.                     }).done(function(html) {
  215.                         $('.ec-headerRole__cart').html(html);
  216.                     });
  217.                 }).fail(function(data) {
  218.                     alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  219.                 }).always(function(data) {
  220.                     // Buttonを有効にする
  221.                     $('.add-cart').prop('disabled', false);
  222.                 });
  223.             });
  224.         });
  225.         $('.ec-modal-wrap').on('click', function(e) {
  226.             // モーダル内の処理は外側にバブリングさせない
  227.             e.stopPropagation();
  228.         });
  229.         $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  230.             $('.ec-modal').hide()
  231.         });
  232.     </script>
  233.     
  234.     <script type="application/ld+json">
  235.     {
  236.         "@context": "https://schema.org/",
  237.         "@type": "Product",
  238.         "name": "{{ Product.name }}",
  239.         "image": [
  240.             {% for img in Product.ProductImage %}
  241.                 "{{ app.request.schemeAndHttpHost }}{{ asset(img, 'save_image') }}"{% if not loop.last %},{% endif %}
  242.             {% else %}
  243.                 "{{ app.request.schemeAndHttpHost }}{{ asset(''|no_image_product, 'save_image') }}"
  244.             {% endfor %}
  245.         ],
  246.         "description": "{{ Product.description_list | default(Product.description_detail) | replace({'\n': '', '\r': ''}) | slice(0,300) }}",
  247.         {% if Product.code_min %}
  248.         "sku": "{{ Product.code_min }}",
  249.         {% endif %}
  250.         "offers": {
  251.             "@type": "Offer",
  252.             "url": "{{ url('product_detail', {'id': Product.id}) }}",
  253.             "priceCurrency": "{{ eccube_config.currency }}",
  254.             "price": {{ Product.getPrice02IncTaxMin ? Product.getPrice02IncTaxMin : 0}},
  255.             "availability": "{{ Product.stock_find ? "InStock" : "OutOfStock" }}"
  256.         }
  257.     }
  258.     </script>
  259. {% endblock %}
  260. {% block main %}
  261.     <div class="ec-productRole">
  262.         <div class="ec-productRole__title min-width768-hide">
  263.                         <h2 class="ec-headingTitle">{{ Product.name }}</h2>
  264.                     </div>
  265.         <div class="ec-grid2">
  266.             <div class="ec-grid2__cell">
  267.                 <!-- カスタム画像表示部分 -->
  268.                 <div class="custom-product-images">
  269.                     <div class="custom-main-image">
  270.                         {% set first_image = Product.ProductImage|first %}
  271.                         {% if first_image %}
  272.                             <img src="{{ asset(first_image, 'save_image') }}" alt="{{ Product.name }}" loading="eager">
  273.                         {% else %}
  274.                             <img src="{{ asset(''|no_image_product, 'save_image') }}" alt="{{ Product.name }}" loading="eager">
  275.                         {% endif %}
  276.                     </div>
  277.                     
  278.                     <!-- サムネイル画像(複数画像がある場合のみ表示) -->
  279.                     {% if Product.ProductImage|length > 1 %}
  280.                         <div class="custom-thumbnails">
  281.                             {% for ProductImage in Product.ProductImage %}
  282.                                 <div class="custom-thumbnail">
  283.                                     <img src="{{ asset(ProductImage, 'save_image') }}" alt="商品画像 {{ loop.index }}" loading="lazy">
  284.                                 </div>
  285.                             {% endfor %}
  286.                         </div>
  287.                     {% endif %}
  288.                 </div>
  289.             </div>
  290.             <div class="ec-grid2__cell">
  291.                 <div class="ec-productRole__profile">
  292.                     {# 商品名 #}
  293.                     <div class="ec-productRole__title max-width768-hide">
  294.                         <h2 class="ec-headingTitle">{{ Product.name }}</h2>
  295.                     </div>
  296.                     
  297.                     {#商品説明 #}
  298.                     <div style="padding-top:1rem;">
  299.                         <div class="ec-productRole__description">{{ Product.description_detail|raw|nl2br }}
  300.                         </div>
  301.                         {% if Product.freearea %}
  302.                              <div class="ec-productRole__description description-sp">
  303.                                  {{ include(template_from_string(Product.freearea)) }}
  304.                             </div>
  305.                         {% endif %}
  306.                     </div>
  307.                     {# タグ #}
  308.                     <ul class="ec-productRole__tags">
  309.                         {% for Tag in Product.Tags %}
  310.                             <li class="ec-productRole__tag tag_{{ Tag.id }}">{{ Tag }}</li>
  311.                         {% endfor %}
  312.                     </ul>
  313.                     {# 通常価格 #}
  314.                     {% if Product.hasProductClass -%}
  315.                         <div class="ec-productRole__priceRegular">
  316.                             {% if Product.getPrice01Min is not null and Product.getPrice01IncTaxMin == Product.getPrice01IncTaxMax %}
  317.                                 <span class="ec-productRole__priceRegularPrice">{{ '通常価格'|trans }}:<span class="price01-default">{{ Product.getPrice01IncTaxMin|price }}</span></span>
  318.                                 <span class="ec-productRole__priceRegularTax">{{ '税込'|trans }}</span>
  319.                             {% elseif Product.getPrice01Min is not null and Product.getPrice01Max is not null %}
  320.                                 <span class="ec-productRole__priceRegularPrice">{{ '通常価格'|trans }}:<span class="price01-default">{{ Product.getPrice01IncTaxMin|price }}~ {{ Product.getPrice01IncTaxMax|price }}</span></span>
  321.                                 <span class="ec-productRole__priceRegularTax">{{ '税込'|trans }}</span>
  322.                             {% endif %}
  323.                         </div>
  324.                     {% else %}
  325.                         {% if Product.getPrice01Max is not null %}
  326.                             <span class="ec-productRole__priceRegularPrice">{{ '通常価格'|trans }}:{{ Product.getPrice01IncTaxMin|price }}</span>
  327.                             <span class="ec-productRole__priceRegularTax">{{ '税込'|trans }}</span>
  328.                         {% endif %}
  329.                     {% endif %}
  330.                     {# 販売価格 #}
  331.                     <div class="ec-productRole__price">
  332.                         {% if Product.hasProductClass -%}
  333.                             {% if Product.getPrice02IncTaxMin == Product.getPrice02IncTaxMax %}
  334.                                 <div class="ec-price">
  335.                                     <span class="ec-price__price price02-default">{{ Product.getPrice02IncTaxMin|price }}</span>
  336.                                     <span class="ec-price__tax">{{ '税込'|trans }}</span>
  337.                                 </div>
  338.                             {% else %}
  339.                                 <div class="ec-price">
  340.                                     <span class="ec-price__price price02-default">{{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}</span>
  341.                                     <span class="ec-price__tax">{{ '税込'|trans }}</span>
  342.                                 </div>
  343.                             {% endif %}
  344.                         {% else %}
  345.                             <div class="ec-price">
  346.                                 <span class="ec-price__price">{{ Product.getPrice02IncTaxMin|price }}</span>
  347.                                 <span class="ec-price__tax">{{ '税込'|trans }}</span>
  348.                             </div>
  349.                         {% endif %}
  350.                     </div>
  351.                     {# 商品コード #}
  352.                     {# 関連カテゴリ #}
  353.                     
  354.                     {# コメントアウト  
  355.                         {% if Product.ProductCategories is not empty %}
  356.                         <div class="ec-productRole__category">
  357.                             <div>{{ '関連カテゴリ'|trans }}</div>
  358.                             {% for ProductCategory in Product.ProductCategories %}
  359.                                 <ul>
  360.                                     <li>
  361.                                         {% for Category in ProductCategory.Category.path %}
  362.                                             <a href="{{ url('product_list') }}?category_id={{ Category.id }}">{{ Category.name }}</a> {%- if loop.last == false %}
  363.                                             <span>></span>{% endif -%}
  364.                                         {% endfor %}
  365.                                     </li>
  366.                                 </ul>
  367.                             {% endfor %}
  368.                         </div>
  369.                         {% endif %}
  370.                         #}
  371.                     <form action="{{ url('product_add_cart', {id:Product.id}) }}" method="post" id="form1" name="form1">
  372.                         {% if Product.stock_find %}
  373.                             <div class="ec-productRole__actions">
  374.                                 {% if form.classcategory_id1 is defined %}
  375.                                     <div class="ec-select">
  376.                                         {{ form_row(form.classcategory_id1) }}
  377.                                         {{ form_errors(form.classcategory_id1) }}
  378.                                     </div>
  379.                                     {% if form.classcategory_id2 is defined %}
  380.                                         <div class="ec-select">
  381.                                             {{ form_row(form.classcategory_id2) }}
  382.                                             {{ form_errors(form.classcategory_id2) }}
  383.                                         </div>
  384.                                     {% endif %}
  385.                                 {% endif %}
  386.                                 <div class="ec-numberInput"><span>{{ '数量'|trans }}</span>
  387.                                     {{ form_widget(form.quantity) }}
  388.                                     {{ form_errors(form.quantity) }}
  389.                                 </div>
  390.                             </div>
  391.                             <div class="ec-productRole__btn">
  392.                                 <button type="submit" class="ec-blockBtn--action add-cart">
  393.                                     {{ 'カートに入れる'|trans }}
  394.                                 </button>
  395.                             </div>
  396.                         {% else %}
  397.                             <div class="ec-productRole__btn">
  398.                                 <button type="button" class="ec-blockBtn--action" disabled="disabled">
  399.                                     {{ 'ただいま品切れ中です。'|trans }}
  400.                                 </button>
  401.                             </div>
  402.                         {% endif %}
  403.                         {{ form_rest(form) }}
  404.                     </form>
  405.                     <div class="ec-modal">
  406.                         <div class="ec-modal-overlay">
  407.                             <div class="ec-modal-wrap">
  408.                                 <span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  409.                                 <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  410.                                 <div class="ec-modal-box">
  411.                                     <div class="ec-role">
  412.                                         <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  413.                                         <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  414.                                     </div>
  415.                                 </div>
  416.                             </div>
  417.                         </div>
  418.                     </div>
  419.                     {% if BaseInfo.option_favorite_product %}
  420.                         <form action="{{ url('product_add_favorite', {id:Product.id}) }}" method="post">
  421.                             <div class="ec-productRole__btn">
  422.                                 {% if is_favorite == false %}
  423.                                     <button type="submit" id="favorite" class="ec-blockBtn--cancel">
  424.                                         {{ 'お気に入りに追加'|trans }}
  425.                                     </button>
  426.                                 {% else %}
  427.                                     <button type="submit" id="favorite" class="ec-blockBtn--cancel"
  428.                                             disabled="disabled">{{ 'お気に入りに追加済です。'|trans }}
  429.                                     </button>
  430.                                 {% endif %}
  431.                             </div>
  432.                         </form>
  433.                     {% endif %}
  434.                 </div>
  435.             </div>
  436.         </div>
  437.     </div>
  438. {% endblock %}