app/template/cosme41/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. {# ▼▼▼ カートボタン表示制限のON/OFFスイッチ ▼▼▼ #}
  10. {# true = 制限を有効にする, false = 制限を解除する(常にカートボタンを表示) #}
  11. {% set cart_restriction_enabled = false %}
  12. {% set body_class = 'product_page' %}
  13. {% block stylesheet %}
  14.     <style>
  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').html(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.         "gtin13": "{{ Product.code_min }}",
  241.         {% endif %}
  242.         "offers": {
  243.             "@type": "Offer",
  244.             "url": "{{ url('product_detail', {'id': Product.id}) }}",
  245.             "priceCurrency": "{{ eccube_config.currency }}",
  246.             "price": {{ Product.getPrice02IncTaxMin ? Product.getPrice02IncTaxMin : 0 }},
  247.             "availability": "{{ Product.stock_find ? "InStock" : "OutOfStock" }}"
  248.         }
  249.     }
  250.     </script>
  251. {% endblock %}
  252. {% block main %}
  253.     <div class="ec-productRole product_{{ Product.id }}">
  254.         <div class="ec-grid2">
  255.             <div class="ec-grid2__cell">
  256.                 <div class="ec-sliderItemRole">
  257.                     <div class="item_visual">
  258.                         {% for ProductImage in Product.ProductImage %}
  259.                             <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>
  260.                         {% else %}
  261.                             <div class="slide-item"><img src="{{ asset(''|no_image_product, 'save_image') }}" alt="{{ loop.first ? Product.name : '' }}" width="550" height="550"></div>
  262.                         {% endfor %}
  263.                     </div>
  264.                     <div class="item_nav">
  265.                         {% for ProductImage in Product.ProductImage %}
  266.                             <div class="slideThumb" data-index="{{ loop.index0 }}"><img src="{{ asset(ProductImage, 'save_image') }}" alt="" width="133" height="133" loading="lazy"></div>
  267.                         {% endfor %}
  268.                     </div>
  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.                     {# GTINコード #}
  322.                     {% if Product.code_min is not empty %}
  323.                         <div class="ec-productRole__code">
  324.                             {{ 'GTINコード'|trans }}: 
  325.                             <span class="product-code-default">{{ Product.code_min }}{% if Product.code_min != Product.code_max %} ~ {{ Product.code_max }}{% endif %}</span>
  326.                         </div>
  327.                     {% endif %}
  328.                     {# 関連カテゴリ #}
  329.                     {% if Product.ProductCategories is not empty %}
  330.                         <div class="ec-productRole__category">
  331.                             <div>{{ '関連カテゴリ'|trans }}</div>
  332.                             {% for ProductCategory in Product.ProductCategories %}
  333.                                 <ul>
  334.                                     <li>
  335.                                         {% for Category in ProductCategory.Category.path %}
  336.                                             <a href="{{ url('product_list') }}?category_id={{ Category.id }}">{{ Category.name }}</a> {%- if loop.last == false %}
  337.                                             <span>></span>{% endif -%}
  338.                                         {% endfor %}
  339.                                     </li>
  340.                                 </ul>
  341.                             {% endfor %}
  342.                         </div>
  343.                     {% endif %}
  344. <!--非会員カートボタン非表示-->    
  345. {# カートボタンを非表示にする商品IDのリストを定義します #}
  346. {% set hiddenProductIds = [8, 9, 10, 11, 12, 16, 18, 21, 26, 29, 30, 40, 42, 43, 52, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, 66, 67, 68, 69, 88, 94, 95, 96, 115, 116, 120, 123, 127, 128, 134, 135, 136, 138, 139, 140, 141, 143, 144, 145, 146, 148, 149, 150, 151, 154, 155, 156, 158, 159, 160, 161, 162, 163, 164, 165, 167, 168, 169, 188, 189, 190, 194, 198, 210, 211, 212, 213, 217, 218, 219, 220, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 303, 304] %}
  347. {# -- 日時と曜日の判定 -- #}
  348. {% set timezone = "Asia/Tokyo" %}
  349. {% set current_hour = "now"|date("H", timezone) %}
  350. {# 曜日を数値で取得 (0:日曜, 6:土曜) #}
  351. {% set day_of_week = "now"|date("w", timezone) %}
  352. {% set is_weekend = (day_of_week == 0 or day_of_week == 6) %}
  353. {#
  354. 下記の条件でカートボタンを表示します。
  355. 1. 会員である (is_granted('ROLE_USER'))
  356. 2. 非表示対象商品ではない (Product.id not in hiddenProductIds)
  357. 3. 非表示対象商品だが、以下のいずれかの条件を満たす
  358.    - 週末(土日)である
  359.    - 指定時間内(18:00~翌9:00)である
  360. #}
  361. {% if cart_restriction_enabled == false or (is_granted('ROLE_USER') or (Product.id not in hiddenProductIds) or (Product.id in hiddenProductIds and (is_weekend or current_hour >= 18 or current_hour < 9))) %}
  362. <div id="role_user_hyouzi" class="cart-button-area">
  363. <form action="{{ url('product_add_cart', {id:Product.id}) }}" method="post" id="form1" name="form1">
  364. {% if Product.stock_find %}
  365. <div class="ec-productRole__actions">
  366. {% if form.classcategory_id1 is defined %}
  367. <div class="ec-select">
  368. {{ form_row(form.classcategory_id1) }}
  369. {{ form_errors(form.classcategory_id1) }}
  370. </div>
  371. {% endif %}
  372. {% if form.classcategory_id2 is defined %}
  373. <div class="ec-select">
  374. {{ form_row(form.classcategory_id2) }}
  375. {{ form_errors(form.classcategory_id2) }}
  376. </div>
  377. {% endif %}
  378. <div class="ec-numberInput"><span>{{ '数量'|trans }}</span>
  379. <div class="ec-select">
  380. {{ form_widget(form.quantity) }}
  381. {{ form_errors(form.quantity) }}
  382. </div>
  383. <span class="small display">在庫数及び販売制限数を設定しています。表示以上の数量は選べません</span>
  384. <span class="small display-non">1種類につき1点ずつ</span>
  385. </div>
  386. </div>
  387. <div class="ec-productRole__btn">
  388. <button type="submit" class="ec-blockBtn--action add-cart">
  389. {{ 'カートに入れる'|trans }}
  390. </button>
  391. </div>
  392. {% else %}
  393. <div class="ec-productRole__btn">
  394. <button type="button" class="ec-blockBtn--action" disabled="disabled">
  395. {{ 'ただいま品切れ中です。'|trans }}
  396. </button>
  397. </div>
  398. {% endif %}
  399. {{ form_rest(form) }}
  400. </form>
  401. <div class="ec-modal">
  402. <div class="ec-modal-overlay">
  403. <div class="ec-modal-wrap">
  404. <span class="ec-modal-close"><span class="ec-icon"><img src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  405. <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  406. <div class="ec-modal-box">
  407. <div class="ec-role">
  408. <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  409. <a href="{{ url('cart') }}" class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  410. </div>
  411. </div>
  412. </div>
  413. </div>
  414. </div>
  415. {% if BaseInfo.option_favorite_product %}
  416. {% if is_favorite == false %}
  417. <form action="{{ url('product_add_favorite', {id:Product.id}) }}" method="post">
  418. <div class="ec-productRole__btn">
  419. <button type="submit" id="favorite" class="ec-blockBtn--cancel">
  420. {{ 'お気に入りに追加'|trans }}
  421. </button>
  422. </div>
  423. </form>
  424. {% else %}
  425. <form action="{{ url('refine_delete_favorite', {id:Product.id}) }}" method="post">
  426. <div class="ec-productRole__btn">
  427. <button type="submit" id="favorite" class="ec-blockBtn--cancel favorite_cancel">
  428. {{ 'お気に入りから削除'|trans }}
  429. </button>
  430. </div>
  431. </form>
  432. {% endif %}
  433. {% endif %}
  434. </div>
  435. {% else %}
  436. {# 非会員で、hiddenProductIdsに含まれており、かつ時間外/平日である場合はこちらのブロックが表示されます #}
  437. <div class="add-cart-hikaiin cart-button-area">
  438. <a href="/mypage/login">ログインして購入/会員登録</a>
  439. </div>
  440. {% endif %}
  441. <!--非会員カートボタン非表示ここまで-->                    
  442.                     <div class="ec-productRole__description">{{ Product.description_detail|raw|nl2br }}
  443.                     </div>
  444.                 </div>
  445.             </div>
  446.         </div>
  447.         {% if Product.freearea %}
  448.              <div class="ec-productRole__description">
  449.                  {{ include(template_from_string(Product.freearea)) }}
  450.             </div>
  451.         {% endif %}
  452.     </div>
  453.     
  454. {% endblock %}