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