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