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