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