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