app/template/default/Product/detail.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 stylesheet %}
  11.     <style>
  12.     .ec-price .ec-price__price {
  13.     margin-top: 0!important;
  14. }
  15. span.ec-productRole__priceRegularPrice {
  16.     text-decoration: line-through;
  17. }
  18.         .slick-slider {
  19.             margin-bottom: 30px;
  20.         }
  21.         .slick-dots {
  22.             position: absolute;
  23.             bottom: -45px;
  24.             display: block;
  25.             width: 100%;
  26.             padding: 0;
  27.             list-style: none;
  28.             text-align: center;
  29.         }
  30.         .slick-dots li {
  31.             position: relative;
  32.             display: inline-block;
  33.             width: 20px;
  34.             height: 20px;
  35.             margin: 0 5px;
  36.             padding: 0;
  37.             cursor: pointer;
  38.         }
  39.         .slick-dots li button {
  40.             font-size: 0;
  41.             line-height: 0;
  42.             display: block;
  43.             width: 20px;
  44.             height: 20px;
  45.             padding: 5px;
  46.             cursor: pointer;
  47.             color: transparent;
  48.             border: 0;
  49.             outline: none;
  50.             background: transparent;
  51.         }
  52.         .slick-dots li button:hover,
  53.         .slick-dots li button:focus {
  54.             outline: none;
  55.         }
  56.         .slick-dots li button:hover:before,
  57.         .slick-dots li button:focus:before {
  58.             opacity: 1;
  59.         }
  60.         .slick-dots li button:before {
  61.             content: " ";
  62.             line-height: 20px;
  63.             position: absolute;
  64.             top: 0;
  65.             left: 0;
  66.             width: 12px;
  67.             height: 12px;
  68.             text-align: center;
  69.             opacity: .25;
  70.             background-color: black;
  71.             border-radius: 50%;
  72.         }
  73.         .slick-dots li.slick-active button:before {
  74.             opacity: .75;
  75.             background-color: black;
  76.         }
  77.         .slick-dots li button.thumbnail img {
  78.             width: 0;
  79.             height: 0;
  80.         }
  81.     </style>
  82. {% endblock %}
  83. {% block javascript %} <script>
  84.                     eccube.classCategories = {{ class_categories_as_json(Product)|raw }};
  85.             
  86.                     // 規格2に選択肢を割り当てる。
  87.                     function fnSetClassCategories(form, classcat_id2_selected) {
  88.                         var $form = $(form);
  89.                         var product_id = $form.find('input[name=product_id]').val();
  90.                         var $sele1 = $form.find('select[name=classcategory_id1]');
  91.                         var $sele2 = $form.find('select[name=classcategory_id2]');
  92.                         eccube.setClassCategories($form, product_id, $sele1, $sele2, classcat_id2_selected);
  93.                     }
  94.             
  95.                     {% if form.classcategory_id2 is defined %}
  96.                     fnSetClassCategories(
  97.                         $('#form1'), {{ form.classcategory_id2.vars.value|json_encode|raw }}
  98.                     );
  99.                     {% elseif form.classcategory_id1 is defined %}
  100.                     eccube.checkStock($('#form1'), {{ Product.id }}, {{ form.classcategory_id1.vars.value|json_encode|raw }}, null);
  101.                     {% endif %}
  102.                 </script>
  103.      <script>
  104.                     $(function() {
  105.                         // bfcache無効化
  106.                         $(window).bind('pageshow', function(event) {
  107.                             if (event.originalEvent.persisted) {
  108.                                 location.reload(true);
  109.                             }
  110.                         });
  111.             
  112.                         // Core Web Vital の Cumulative Layout Shift(CLS)対策のため
  113.                         // img タグに width, height が付与されている.
  114.                         // 630px 未満の画面サイズでは縦横比が壊れるための対策
  115.                         // see https://github.com/EC-CUBE/ec-cube/pull/5023
  116.                         $('.ec-grid2__cell').hide();
  117.                         var removeSize = function () {
  118.                             $('.slide-item').height('');
  119.                             $('.slide-item img')
  120.                                 .removeAttr('width')
  121.                                 .removeAttr('height')
  122.                                 .removeAttr('style');
  123.                         };
  124.                         var slickInitial = function(slick) {
  125.                             $('.ec-grid2__cell').fadeIn(1500);
  126.                             var baseHeight = $(slick.target).height();
  127.                             var baseWidth = $(slick.target).width();
  128.                             var rate = baseWidth / baseHeight;
  129.             
  130.                             $('.slide-item').height(baseHeight * rate); // 余白を削除する
  131.                             // transform を使用することでCLSの影響を受けないようにする
  132.                             $('.slide-item img')
  133.                                 .css(
  134.                                     {
  135.                                         'transform-origin': 'top left',
  136.                                         'transform': 'scaleY(' + rate + ')',
  137.                                         'transition': 'transform .1s'
  138.                                     }
  139.                                 );
  140.                             // 正しいサイズに近くなったら属性を解除する
  141.                             setTimeout(removeSize, 500);
  142.                         };
  143.                         $('.item_visual').on('init', slickInitial);
  144.                         // リサイズ時は CLS の影響を受けないため属性を解除する
  145.                         $(window).resize(removeSize);
  146.                         $('.item_visual').slick({
  147.                             dots: false,
  148.                             arrows: true,
  149.                             adaptiveHeight: true,
  150.                 prevArrow: '<img src="{{ asset('assets/img/icon-arrow-prev.png') }}" class="slide-arrow prev-arrow detail-arrow">',
  151.                 nextArrow: '<img src="{{ asset('assets/img/icon-arrow-next.png') }}" class="slide-arrow next-arrow detail-arrow">',
  152.            
  153.                             responsive: [{
  154.                                 breakpoint: 768,
  155.                                 settings: {
  156.                                     arrows: true,
  157.                                 }
  158.                             }]
  159.                         });
  160.             
  161.                         $('.slideThumb').on('click', function() {
  162.                             var index = $(this).attr('data-index');
  163.                             $('.item_visual').slick('slickGoTo', index, false);
  164.                         })
  165.                     });
  166.                 </script>
  167.      <script>
  168.                     $(function() {
  169.                         $('.add-cart').on('click', function(event) {
  170.                             {% if form.classcategory_id1 is defined %}
  171.                             // 規格1フォームの必須チェック
  172.                             if ($('#classcategory_id1').val() == '__unselected' || $('#classcategory_id1').val() == '') {
  173.                                 $('#classcategory_id1')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  174.                                 return true;
  175.                             } else {
  176.                                 $('#classcategory_id1')[0].setCustomValidity('');
  177.                             }
  178.                             {% endif %}
  179.             
  180.                             {% if form.classcategory_id2 is defined %}
  181.                             // 規格2フォームの必須チェック
  182.                             if ($('#classcategory_id2').val() == '__unselected' || $('#classcategory_id2').val() == '') {
  183.                                 $('#classcategory_id2')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  184.                                 return true;
  185.                             } else {
  186.                                 $('#classcategory_id2')[0].setCustomValidity('');
  187.                             }
  188.                             {% endif %}
  189.             
  190.                             // 個数フォームのチェック
  191.                             if ($('#quantity').val() < 1) {
  192.                                 $('#quantity')[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  193.                                 return true;
  194.                             } else {
  195.                                 $('#quantity')[0].setCustomValidity('');
  196.                             }
  197.             
  198.                             event.preventDefault();
  199.                             $form = $('#form1');
  200.                             $.ajax({
  201.                                 url: $form.attr('action'),
  202.                                 type: $form.attr('method'),
  203.                                 data: $form.serialize(),
  204.                                 dataType: 'json',
  205.                                 beforeSend: function(xhr, settings) {
  206.                                     // Buttonを無効にする
  207.                                     $('.add-cart').prop('disabled', true);
  208.                                 }
  209.                             }).done(function(data) {
  210.                                 // レスポンス内のメッセージをalertで表示
  211.                                 $.each(data.messages, function() {
  212.                                     $('#ec-modal-header').text(this);
  213.                                 });
  214.             
  215.                                 $('.ec-modal').show()
  216.             
  217.                                 // カートブロックを更新する
  218.                                 $.ajax({
  219.                                     url: "{{ url('block_cart') }}",
  220.                                     type: 'GET',
  221.                                     dataType: 'html'
  222.                                 }).done(function(html) {
  223.                                     $('.ec-headerRole__cart').html(html);
  224.                                 });
  225.                             }).fail(function(data) {
  226.                                 alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  227.                             }).always(function(data) {
  228.                                 // Buttonを有効にする
  229.                                 $('.add-cart').prop('disabled', false);
  230.                             });
  231.                         });
  232.                     });
  233.             
  234.                     $('.ec-modal-wrap').on('click', function(e) {
  235.                         // モーダル内の処理は外側にバブリングさせない
  236.                         e.stopPropagation();
  237.                     });
  238.                     $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  239.                         $('.ec-modal').hide()
  240.                     });
  241.                 </script>
  242.      <script type="application/ld+json">
  243.                 {
  244.                     "@context": "https://schema.org/",
  245.                     "@type": "Product",
  246.                     "name": "{{ Product.name }}",
  247.                     "image": [
  248.                         {% for img in Product.ProductImage %}
  249.                             "{{ app.request.schemeAndHttpHost }}{{ asset(img, 'save_image') }}"{% if not loop.last %},{% endif %}
  250.             
  251.                         {% else %}
  252.                             "{{ app.request.schemeAndHttpHost }}{{ asset(''|no_image_product, 'save_image') }}"
  253.                         {% endfor %}
  254.                     ],
  255.                     "description": "{{ Product.description_list | default(Product.description_detail) | replace({'\n': '', '\r': ''}) | slice(0,300) }}",
  256.                     {% if Product.code_min %}
  257.                     "sku": "{{ Product.code_min }}",
  258.                     {% endif %}
  259.                     "offers": {
  260.                         "@type": "Offer",
  261.                         "url": "{{ url('product_detail', {'id': Product.id}) }}",
  262.                         "priceCurrency": "{{ eccube_config.currency }}",
  263.                         "price": {{ Product.getPrice02IncTaxMin ? Product.getPrice02IncTaxMin : 0}},
  264.                         "availability": "{{ Product.stock_find ? "InStock" : "OutOfStock" }}"
  265.                     }
  266.                 }
  267.                 </script>
  268. {% endblock %}
  269. {% block main %}
  270.     <div class="ec-productRole">
  271.         <ol class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">
  272.             <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
  273.                 <a itemprop="item" href="/">
  274.                     <span itemprop="name">TOP</span>
  275.                 </a>
  276.                 <meta itemprop="position" content="1"/>
  277.             </li>
  278.             <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
  279.                         {# パンくずリストの中でカテゴリーのURLを表示 #}
  280.                 <a itemprop="item" href="{{ url('product_list') }}?category_id={{ Product.ProductCategories[0].Category.id }}">
  281.                     <span itemprop="name">{{ Product.ProductCategories[0].Category.name }}</span>
  282.                 </a>
  283.                 <meta itemprop="position" content="2"/>
  284.             </li>
  285.             <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
  286.                 {# <a itemprop="item" href="{{ url('product_list') }}?category_id={{ Product.ProductCategories[0].Category.id }}"> #}
  287.                     <span itemprop="name">{{ Product.name }}</span>
  288.                 {# </a> #}
  289.                 <meta itemprop="position" content="3"/>
  290.             </li>
  291.             {# <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
  292.                                                     <a itemprop="item" href="カテゴリー2のURL">
  293.                                                         <span itemprop="name">商品詳細</span>
  294.                                                     </a>
  295.                                                     <meta itemprop="position" content="3" />
  296.                                                 </li> #}
  297.         </ol>
  298.         <div class="ec-grid2">
  299.             <div class="ec-grid2__cell">
  300.                 <div class="ec-sliderItemRole">
  301.                     <div class="item_visual">
  302.                         {% for ProductImage in Product.ProductImage %}
  303.                             <div class="slide-item"><img src="{{ asset(ProductImage, 'save_image') }}" alt="{{ loop.first ? Product.name : '' }}" width="550" height="550" {% if loop.index > 1 %} loading="lazy" {% endif %}></div>
  304.                         {% else %}
  305.                             <div class="slide-item"><img src="{{ asset(''|no_image_product, 'save_image') }}" alt="{{ loop.first ? Product.name : '' }}" width="550" height="550"></div>
  306.                         {% endfor %}
  307.                     </div>
  308.                     <div class="item_nav">
  309.                         {% for ProductImage in Product.ProductImage %}
  310.                             <div class="slideThumb" data-index="{{ loop.index0 }}"><img src="{{ asset(ProductImage, 'save_image') }}" alt="" width="133" height="133" loading="lazy"></div>
  311.                         {% endfor %}
  312.                     </div>
  313.                 </div>
  314.             </div>
  315.             <div class="ec-grid2__cell">
  316.                 <div
  317.                     class="ec-productRole__profile ec-productRole__btn-relative">
  318.                     {# お気に入りボタン #}
  319.                     {% if BaseInfo.option_favorite_product %}
  320.                         <div class="ec-productRole__btn-wrapper">
  321.                             <form action="{{ url('product_add_favorite', {id:Product.id}) }}" method="post">
  322.                                 <div class="ec-productRole__btn favorite-btn-wrapper">
  323.                                     {% if is_favorite == false %}
  324.                                         <button type="submit" id="favorite" class="ec-blockBtn--favorite">
  325.                                              <img src="{{ asset('assets/img/Icon-heart.svg') }}" alt="お気に入りに追加">
  326.                                         </button>
  327.                                     {% else %}
  328.                                         <button type="submit" id="favorite" class="ec-blockBtn--favorite" disabled="disabled">
  329.                                              <img src="{{ asset('assets/img/Icon-heart-remove.svg') }}" alt="お気に入りから削除">
  330.                                         </button>
  331.                                     {% endif %}
  332.                                 </div>
  333.                             </form>
  334.                         </div>
  335.                     {% endif %}
  336.                     {# 商品名 #}
  337.                     <div class="ec-productRole__title">
  338.                         <h2 class="ec-headingTitle">{{ Product.name }}</h2>
  339.                     </div>
  340.                     {# タグ #}
  341.                     <ul class="ec-productRole__tags">
  342.                         {% for Tag in Product.Tags %}
  343.                             <li class="ec-productRole__tag tag_{{ Tag.id }}">{{ Tag }}</li>
  344.                         {% endfor %}
  345.                     </ul>
  346.                     {# 通常価格 #}
  347.                     {% if Product.hasProductClass -%}
  348.                                                                                     <div class="ec-productRole__priceRegular">
  349.                                                                                         {% if Product.getPrice01Min is not null and Product.getPrice01IncTaxMin == Product.getPrice01IncTaxMax %}
  350.                                                                                             <span class="ec-productRole__priceRegularPrice">{{ '通常価格'|trans }}:<span class="price01-default">{{ Product.getPrice01IncTaxMin|price }}</span></span>
  351.                                                                                             <span class="ec-productRole__priceRegularTax">({{ '税込'|trans }})</span>
  352.                                                                                         {% elseif Product.getPrice01Min is not null and Product.getPrice01Max is not null %}
  353.                                                                                             <span class="ec-productRole__priceRegularPrice">{{ '通常価格'|trans }}:<span class="price01-default">{{ Product.getPrice01IncTaxMin|price }}~ {{ Product.getPrice01IncTaxMax|price }}</span></span>
  354.                                                                                             <span class="ec-productRole__priceRegularTax">({{ '税込'|trans }})</span>
  355.                                                                                         {% endif %}
  356.                                                                                     </div>
  357.                                                                                 {% else %}
  358.                                                                                     {% if Product.getPrice01Max is not null %}
  359.                                                                                         <span class="ec-productRole__priceRegularPrice">{{ '通常価格'|trans }}:{{ Product.getPrice01IncTaxMin|price }}</span>
  360.                                                                                         <span class="ec-productRole__priceRegularTax">({{ '税込'|trans }})</span>
  361.                                                                                     {% endif %}
  362.                                                                                 {% endif %}
  363.                     {# 販売価格 #}
  364.                         <div class="ec-productRole__price"> {% if Product.hasProductClass -%}
  365.                             {% if Product.getPrice02IncTaxMin == Product.getPrice02IncTaxMax %}
  366.                                 <div class="ec-price">
  367.                                     <span class="ec-price__price price02-default">{{ Product.getPrice02IncTaxMin|price }}</span>
  368.                                     <span class="ec-price__tax">({{ '税込'|trans }})</span>
  369.                                 </div>
  370.                             {% else %}
  371.                                 <div class="ec-price">
  372.                                     <span class="ec-price__price price02-default">{{ Product.getPrice02IncTaxMin|price }}
  373.                                         ~
  374.                                         {{ Product.getPrice02IncTaxMax|price }}</span>
  375.                                     <span class="ec-price__tax">({{ '税込'|trans }})</span>
  376.                                 </div>
  377.                             {% endif %}
  378.                         {% else %}
  379.                             <div class="ec-price">
  380.                                 <span class="ec-price__price">{{ Product.getPrice02IncTaxMin|price }}</span>
  381.                                 <span class="ec-price__tax">({{ '税込'|trans }})</span>
  382.                             </div>
  383.                         {% endif %}
  384.                     </div>
  385.                     {# 商品コード #}
  386.                     {#{% if Product.code_min is not empty %}
  387.                                                                                     <div class="ec-productRole__code">
  388.                                                                                         {{ '商品コード'|trans }}: <span class="product-code-default">{{ Product.code_min }}{% if Product.code_min != Product.code_max %} ~ {{ Product.code_max }}{% endif %}</span>
  389.                                                                                     </div>
  390.                                                                                 {% endif %}#}
  391.                     {# 関連カテゴリ #}
  392.                     {#{% if Product.ProductCategories is not empty %}
  393.                                                                                     <div class="ec-productRole__category">
  394.                                                                                         <div>{{ '関連カテゴリ'|trans }}</div>
  395.                                                                                         {% for ProductCategory in Product.ProductCategories %}
  396.                                                                                             <ul>
  397.                                                                                                 <li>
  398.                                                                                                     {% for Category in ProductCategory.Category.path %}
  399.                                                                                                         <a href="{{ url('product_list') }}?category_id={{ Category.id }}">{{ Category.name }}</a> {%- if loop.last == false %}
  400.                                                                                                         <span>></span>{% endif -%}
  401.                                                                                                     {% endfor %}
  402.                                                                                                 </li>
  403.                                                                                             </ul>
  404.                                                                                         {% endfor %}
  405.                                                                                     </div>
  406.                                                                                 {% endif %}#}
  407.                         <form action="{{ url('product_add_cart', {id:Product.id}) }}" method="post" id="form1" name="form1"> {% if Product.stock_find %}
  408.                             <div class="ec-productRole__actions">
  409.                                 {% if form.classcategory_id1 is defined %}
  410.                                     <div class="ec-select">
  411.                                         {{ form_row(form.classcategory_id1) }}
  412.                                         {{ form_errors(form.classcategory_id1) }}
  413.                                     </div>
  414.                                     {% if form.classcategory_id2 is defined %}
  415.                                         <div class="ec-select">
  416.                                             {{ form_row(form.classcategory_id2) }}
  417.                                             {{ form_errors(form.classcategory_id2) }}
  418.                                         </div>
  419.                                     {% endif %}
  420.                                 {% endif %}
  421.                                 <div class="ec-numberInput">
  422.                                     <span>{{ '数量'|trans }}</span>
  423.                                     {{ form_widget(form.quantity) }}
  424.                                     {{ form_errors(form.quantity) }}
  425.                                 </div>
  426.                             </div>
  427.                             <div class="ec-productRole__btn">
  428.                                 <button type="submit" class="ec-blockBtn--action add-cart">
  429.                                     {{ 'カートに入れる'|trans }}
  430.                                 </button>
  431.                             </div>
  432.                         {% else %}
  433.                             <div class="ec-productRole__btn">
  434.                                 <button type="button" class="ec-blockBtn--action" disabled="disabled">
  435.                                     {{ 'ただいま品切れ中です。'|trans }}
  436.                                 </button>
  437.                             </div>
  438.                         {% endif %}
  439.                         {{ form_rest(form) }}
  440.                     </form>
  441.                     <div class="ec-modal">
  442.                         <div class="ec-modal-overlay">
  443.                             <div class="ec-modal-wrap">
  444.                                 <span class="ec-modal-close">
  445.                                     <span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span>
  446.                                 </span>
  447.                                 <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  448.                                 <div class="ec-modal-box">
  449.                                     <div class="ec-role">
  450.                                         <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  451.                                         <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  452.                                     </div>
  453.                                 </div>
  454.                             </div>
  455.                         </div>
  456.                     </div>
  457.                     {#{% if BaseInfo.option_favorite_product %}
  458.                                             <form action="{{ url('product_add_favorite', {id:Product.id}) }}" method="post">
  459.                                                 <div class="ec-productRole__btn">
  460.                                                     {% if is_favorite == false %}
  461.                                                         <button type="submit" id="favorite" class="ec-blockBtn--cancel">
  462.                                                             {{ 'お気に入りに追加'|trans }}
  463.                                                         </button>
  464.                                                     {% else %}
  465.                                                         <button type="submit" id="favorite" class="ec-blockBtn--cancel"
  466.                                                                 disabled="disabled">{{ 'お気に入りに追加済です。'|trans }}
  467.                                                         </button>
  468.                                                     {% endif %}
  469.                                                 </div>
  470.                                             </form>
  471.                                         {% endif %}#}
  472.                     <div class="ec-productRole__description">{{ Product.description_detail|raw|nl2br }}
  473.                     </div>
  474.                 </div>
  475.             </div>
  476.         </div>
  477.         {% if Product.freearea %}
  478.             <div class="ec-productRole__description">
  479.                 {{ include(template_from_string(Product.freearea), sandboxed = true) }}
  480.             </div>
  481.         {% endif %}
  482.     </div>
  483. {% endblock %}