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