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.     <style>
  12.         .slick-slider {
  13.             margin-bottom: 30px;
  14.         }
  15.         .slick-dots {
  16.             position: absolute;
  17.             bottom: -45px;
  18.             display: block;
  19.             width: 100%;
  20.             padding: 0;
  21.             list-style: none;
  22.             text-align: center;
  23.         }
  24.         .slick-dots li {
  25.             position: relative;
  26.             display: inline-block;
  27.             width: 20px;
  28.             height: 20px;
  29.             margin: 0 5px;
  30.             padding: 0;
  31.             cursor: pointer;
  32.         }
  33.         .slick-dots li button {
  34.             font-size: 0;
  35.             line-height: 0;
  36.             display: block;
  37.             width: 20px;
  38.             height: 20px;
  39.             padding: 5px;
  40.             cursor: pointer;
  41.             color: transparent;
  42.             border: 0;
  43.             outline: none;
  44.             background: transparent;
  45.         }
  46.         .slick-dots li button:hover,
  47.         .slick-dots li button:focus {
  48.             outline: none;
  49.         }
  50.         .slick-dots li button:hover:before,
  51.         .slick-dots li button:focus:before {
  52.             opacity: 1;
  53.         }
  54.         .slick-dots li button:before {
  55.             content: " ";
  56.             line-height: 20px;
  57.             position: absolute;
  58.             top: 0;
  59.             left: 0;
  60.             width: 12px;
  61.             height: 12px;
  62.             text-align: center;
  63.             opacity: .25;
  64.             background-color: black;
  65.             border-radius: 50%;
  66.         }
  67.         .slick-dots li.slick-active button:before {
  68.             opacity: .75;
  69.             background-color: black;
  70.         }
  71.         .slick-dots li button.thumbnail img {
  72.             width: 0;
  73.             height: 0;
  74.         }
  75.     </style>
  76. {% endblock %}
  77. {% block javascript %}
  78. <script>
  79.     eccube.classCategories = {{ class_categories_as_json(Product)|raw }};
  80.         // 規格2に選択肢を割り当てる。
  81.         function fnSetClassCategories(form, classcat_id2_selected) {
  82.             var $form = $(form);
  83.             var product_id = $form.find('input[name=product_id]').val();
  84.             var $sele1 = $form.find('select[name=classcategory_id1]');
  85.             var $sele2 = $form.find('select[name=classcategory_id2]');
  86.             eccube.setClassCategories($form, product_id, $sele1, $sele2, classcat_id2_selected);
  87.         }
  88.         {% if form.classcategory_id2 is defined %}
  89.         fnSetClassCategories(
  90.             $('#form1'), {{ form.classcategory_id2.vars.value|json_encode|raw }}
  91.         );
  92.         {% elseif form.classcategory_id1 is defined %}
  93.         eccube.checkStock($('#form1'), {{ Product.id }}, {{ form.classcategory_id1.vars.value|json_encode|raw }}, null);
  94.         {% endif %}
  95.     </script>
  96.     <script>
  97.         $(function() {
  98.             // bfcache無効化
  99.             $(window).bind('pageshow', function(event) {
  100.                 if (event.originalEvent.persisted) {
  101.                     location.reload(true);
  102.                 }
  103.             });
  104.             // Core Web Vital の Cumulative Layout Shift(CLS)対策のため
  105.             // img タグに width, height が付与されている.
  106.             // 630px 未満の画面サイズでは縦横比が壊れるための対策
  107.             // see https://github.com/EC-CUBE/ec-cube/pull/5023
  108.             // $('.ec-grid2__cell').hide();
  109.             var removeSize = function () {
  110.                 $('.slide-item').height('');
  111.                 $('.slide-item img')
  112.                     .removeAttr('width')
  113.                     .removeAttr('height')
  114.                     .removeAttr('style');
  115.             };
  116.             var slickInitial = function(slick) {
  117.                 $('.ec-grid2__cell').fadeIn(1500);
  118.                 var baseHeight = $(slick.target).height();
  119.                 var baseWidth = $(slick.target).width();
  120.                 var rate = baseWidth / baseHeight;
  121.                 $('.slide-item').height(baseHeight * rate); // 余白を削除する
  122.                 // transform を使用することでCLSの影響を受けないようにする
  123.                 $('.slide-item img')
  124.                     .css(
  125.                         {
  126.                             'transform-origin': 'top left',
  127.                             'transform': 'scaleY(' + rate + ')',
  128.                             'transition': 'transform .1s'
  129.                         }
  130.                     );
  131.                 // 正しいサイズに近くなったら属性を解除する
  132.                 setTimeout(removeSize, 500);
  133.             };
  134.             $('.item_visual').on('init', slickInitial);
  135.             // リサイズ時は CLS の影響を受けないため属性を解除する
  136.             $(window).resize(removeSize);
  137.             $('.item_visual').slick({
  138.                 dots: false,
  139.                 arrows: false,
  140.                 responsive: [{
  141.                     breakpoint: 768,
  142.                     settings: {
  143.                         dots: true
  144.                     }
  145.                 }]
  146.             });
  147.             $('.slideThumb').on('click', function() {
  148.                 var index = $(this).attr('data-index');
  149.                 $('.item_visual').slick('slickGoTo', index, false);
  150.             })
  151.         });
  152.     </script>
  153.     <script>
  154.         $(function() {
  155.             $('.add-cart').on('click', function(event) {
  156.                 {% if form.classcategory_id1 is defined %}
  157.                 // 規格1フォームの必須チェック
  158.                 if ($('#classcategory_id1').val() == '__unselected' || $('#classcategory_id1').val() == '') {
  159.                     $('#classcategory_id1')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  160.                     return true;
  161.                 } else {
  162.                     $('#classcategory_id1')[0].setCustomValidity('');
  163.                 }
  164.                 {% endif %}
  165.                 {% if form.classcategory_id2 is defined %}
  166.                 // 規格2フォームの必須チェック
  167.                 if ($('#classcategory_id2').val() == '__unselected' || $('#classcategory_id2').val() == '') {
  168.                     $('#classcategory_id2')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  169.                     return true;
  170.                 } else {
  171.                     $('#classcategory_id2')[0].setCustomValidity('');
  172.                 }
  173.                 {% endif %}
  174.                 // 個数フォームのチェック
  175.                 if ($('#quantity').val() < 1) {
  176.                     $('#quantity')[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  177.                     return true;
  178.                 } else {
  179.                     $('#quantity')[0].setCustomValidity('');
  180.                 }
  181.                 event.preventDefault();
  182.                 $form = $('#form1');
  183.                 $.ajax({
  184.                     url: $form.attr('action'),
  185.                     type: $form.attr('method'),
  186.                     data: $form.serialize(),
  187.                     dataType: 'json',
  188.                     beforeSend: function(xhr, settings) {
  189.                         // Buttonを無効にする
  190.                         $('.add-cart').prop('disabled', true);
  191.                     }
  192.                 }).done(function(data) {
  193.                     // レスポンス内のメッセージをalertで表示
  194.                     $.each(data.messages, function() {
  195.                         $('#ec-modal-header').text(this);
  196.                     });
  197.                     $('.ec-modal').show()
  198.                     // カートブロックを更新する
  199.                     $.ajax({
  200.                         url: "{{ url('block_cart') }}",
  201.                         type: 'GET',
  202.                         dataType: 'html'
  203.                     }).done(function(html) {
  204.                         $('.ec-headerRole__cart').html(html);
  205.                     });
  206.                 }).fail(function(data) {
  207.                     alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  208.                 }).always(function(data) {
  209.                     // Buttonを有効にする
  210.                     $('.add-cart').prop('disabled', false);
  211.                 });
  212.             });
  213.         });
  214.         $('.ec-modal-wrap').on('click', function(e) {
  215.             // モーダル内の処理は外側にバブリングさせない
  216.             e.stopPropagation();
  217.         });
  218.         $('.ec-modal-overlay, .ec-modal, .ec-modal-close, .ec-inlineBtn--cancel').on('click', function() {
  219.             $('.ec-modal').hide()
  220.         });
  221.     </script>
  222.     <script type="application/ld+json">
  223.     {
  224.         "@context": "https://schema.org/",
  225.         "@type": "Product",
  226.         "name": "{{ Product.name }}",
  227.         "image": [
  228.             {% for img in Product.ProductImage %}
  229.                 "{{ app.request.schemeAndHttpHost }}{{ asset(img, 'save_image') }}"{% if not loop.last %},{% endif %}
  230.             {% else %}
  231.                 "{{ app.request.schemeAndHttpHost }}{{ asset(''|no_image_product, 'save_image') }}"
  232.             {% endfor %}
  233.         ],
  234.         "description": "{{ Product.description_list | default(Product.description_detail) | replace({'\n': '', '\r': ''}) | slice(0,300) }}",
  235.         {% if Product.code_min %}
  236.         "sku": "{{ Product.code_min }}",
  237.         {% endif %}
  238.         "offers": {
  239.             "@type": "Offer",
  240.             "url": "{{ url('product_detail', {'id': Product.id}) }}",
  241.             "priceCurrency": "{{ eccube_config.currency }}",
  242.             "price": {{ Product.getPrice02IncTaxMin ? Product.getPrice02IncTaxMin : 0}},
  243.             "availability": "{{ Product.stock_find ? "InStock" : "OutOfStock" }}"
  244.         }
  245.     }
  246.     </script>
  247. {% endblock %}
  248. {% block main %}
  249.     <div class="ec-productRole">
  250.         <div class="ec-grid2">
  251.             <div class="ec-grid2__cell">
  252. {#                <div class="product-image">#}
  253. {#                    <div class="uchiwa_img_wrapper" style="width:50%;margin: 20px">#}
  254. {#                        <canvas id="uchiwaCanvas" class="img_canvas" height="512" width="512"></canvas>#}
  255. {#                    </div>#}
  256. {#                </div>#}
  257.                 <div class="ec-sliderItemRole">
  258.                     <div class="item_visual">
  259.                         {% for ProductImage in Product.ProductImage %}
  260.                             <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>
  261.                         {% else %}
  262.                             <div class="slide-item"><img src="{{ asset(''|no_image_product, 'save_image') }}" alt="{{ loop.first ? Product.name : '' }}" width="550" height="550"></div>
  263.                         {% endfor %}
  264.                     </div>
  265.                     <div class="item_nav">
  266.                         {% for ProductImage in Product.ProductImage %}
  267.                             <div class="slideThumb" data-index="{{ loop.index0 }}"><img src="{{ asset(ProductImage, 'save_image') }}" alt="" width="133" height="133" loading="lazy"></div>
  268.                         {% endfor %}
  269.                     </div>
  270.                 </div>
  271.             </div>
  272.             <div class="ec-grid2__cell">
  273.                 <div class="ec-productRole__profile">
  274.                     {# 商品名 #}
  275.                     <div class="ec-productRole__title">
  276.                         <h2 class="ec-headingTitle">{{ Product.name }}</h2>
  277.                     </div>
  278. {#                    <div style="width: 50%;margin: 20px;display:none;">#}
  279. {#                        <input type="text" id="uchiwa_up_text" name="uchiwa_up_text" value="未来"/><br/>#}
  280. {#                        <input type="text" id="uchiwa_main_text" name="uchiwa_main_text" value="看"#}
  281. {#                               style="width:100%;"/><br>#}
  282. {#                        <input type="text" id="uchiwa_low_text" name="uchiwa_lo_text" value="板"/><br/>#}
  283. {#                        <button id="uchiwa_set" type="button">再作画</button>#}
  284. {#                        <br/>#}
  285. {#                        一番外側の色:#}
  286. {#                        <select id="uchiwa_back_color1" name="back_color1">#}
  287. {#                        </select>#}
  288. {#                        <br/>#}
  289. {#                        フチの外枠:#}
  290. {#                        <select id="uchiwa_back_color2" name="back_color2">#}
  291. {#                        </select>#}
  292. {#                        <br/>#}
  293. {#                        フチの中:#}
  294. {#                        <select id="uchiwa_back_color3" name="back_color3">#}
  295. {#                        </select>#}
  296. {#                        <br/>#}
  297. {#                        文字の色:#}
  298. {#                        <select id="uchiwa_back_color4" name="back_color4">#}
  299. {#                        </select>#}
  300. {#                        <br/>#}
  301. {#                    </div>#}
  302.                     {# タグ #}
  303.                     <ul class="ec-productRole__tags">
  304.                         {% for Tag in Product.Tags %}
  305.                             <li class="ec-productRole__tag tag_{{ Tag.id }}">{{ Tag }}</li>
  306.                         {% endfor %}
  307.                     </ul>
  308.                     {# 通常価格 #}
  309.                     {% if Product.hasProductClass -%}
  310.                         <div class="ec-productRole__priceRegular">
  311.                             {% if Product.getPrice01Min is not null and Product.getPrice01IncTaxMin == Product.getPrice01IncTaxMax %}
  312.                                 <span class="ec-productRole__priceRegularPrice">{{ '通常価格'|trans }}:<span
  313.                                             class="price01-default">{{ Product.getPrice01IncTaxMin|price }}</span></span>
  314.                                 <span class="ec-productRole__priceRegularTax">{{ '税込'|trans }}</span>
  315.                             {% elseif Product.getPrice01Min is not null and Product.getPrice01Max is not null %}
  316.                                 <span class="ec-productRole__priceRegularPrice">{{ '通常価格'|trans }}:<span
  317.                                             class="price01-default">{{ Product.getPrice01IncTaxMin|price }}~ {{ Product.getPrice01IncTaxMax|price }}</span></span>
  318.                                 <span class="ec-productRole__priceRegularTax">{{ '税込'|trans }}</span>
  319.                             {% endif %}
  320.                         </div>
  321.                     {% else %}
  322.                         {% if Product.getPrice01Max is not null %}
  323.                             <span class="ec-productRole__priceRegularPrice">{{ '通常価格'|trans }}:{{ Product.getPrice01IncTaxMin|price }}</span>
  324.                             <span class="ec-productRole__priceRegularTax">{{ '税込'|trans }}</span>
  325.                         {% endif %}
  326.                     {% endif %}
  327.                     {# 販売価格 #}
  328.                     <div class="ec-productRole__price">
  329.                         {% if Product.hasProductClass -%}
  330.                             {% if Product.getPrice02IncTaxMin == Product.getPrice02IncTaxMax %}
  331.                                 <div class="ec-price">
  332.                                     <span class="ec-price__price price02-default">{{ Product.getPrice02IncTaxMin|price }}</span>
  333.                                     <span class="ec-price__tax">{{ '税込'|trans }}</span>
  334.                                 </div>
  335.                             {% else %}
  336.                                 <div class="ec-price">
  337.                                     <span class="ec-price__price price02-default">{{ Product.getPrice02IncTaxMin|price }} ~ {{ Product.getPrice02IncTaxMax|price }}</span>
  338.                                     <span class="ec-price__tax">{{ '税込'|trans }}</span>
  339.                                 </div>
  340.                             {% endif %}
  341.                         {% else %}
  342.                             <div class="ec-price">
  343.                                 <span class="ec-price__price">{{ Product.getPrice02IncTaxMin|price }}</span>
  344.                                 <span class="ec-price__tax">{{ '税込'|trans }}</span>
  345.                             </div>
  346.                         {% endif %}
  347.                     </div>
  348.                     {# 商品コード #}
  349.                     {% if Product.code_min is not empty %}
  350.                         <div class="ec-productRole__code">
  351.                             {{ '商品コード'|trans }}: <span
  352.                                     class="product-code-default">{{ Product.code_min }}{% if Product.code_min != Product.code_max %} ~ {{ Product.code_max }}{% endif %}</span>
  353.                         </div>
  354.                     {% endif %}
  355.                     {# 関連カテゴリ #}
  356.                     {% if Product.ProductCategories is not empty %}
  357.                         <div class="ec-productRole__category">
  358.                             <div>{{ '関連カテゴリ'|trans }}</div>
  359.                             {% for ProductCategory in Product.ProductCategories %}
  360.                                 <ul>
  361.                                     <li>
  362.                                         {% for Category in ProductCategory.Category.path %}
  363.                                             <a href="{{ url('product_list') }}?category_id={{ Category.id }}">{{ Category.name }}</a> {%- if loop.last == false %}
  364.                                             <span>></span>{% endif -%}
  365.                                         {% endfor %}
  366.                                     </li>
  367.                                 </ul>
  368.                             {% endfor %}
  369.                         </div>
  370.                     {% endif %}
  371.                     <form action="{{ url('product_add_cart', {id:Product.id}) }}" method="post" id="form1" name="form1">
  372.                         {% if Product.stock_find %}
  373.                             <div class="ec-productRole__actions">
  374.                                 {% if form.classcategory_id1 is defined %}
  375.                                     <div class="ec-select">
  376.                                         {{ form_row(form.classcategory_id1) }}
  377.                                         {{ form_errors(form.classcategory_id1) }}
  378.                                     </div>
  379.                                     {% if form.classcategory_id2 is defined %}
  380.                                         <div class="ec-select">
  381.                                             {{ form_row(form.classcategory_id2) }}
  382.                                             {{ form_errors(form.classcategory_id2) }}
  383.                                         </div>
  384.                                     {% endif %}
  385.                                 {% endif %}
  386. {#                                <div class="ec-numberInput"><span>文字</span>#}
  387. {#                                    {{ form_widget(form.order_text1) }}#}
  388. {#                                    {{ form_errors(form.order_text1) }}#}
  389. {#                                </div>#}
  390. {#                                <div class="ec-numberInput"><span>上文字</span>#}
  391. {#                                    {{ form_widget(form.order_text1) }}#}
  392. {#                                    {{ form_errors(form.order_text1) }}#}
  393. {#                                </div>#}
  394. {#                                <div class="ec-numberInput"><span>文字</span>#}
  395. {#                                    {{ form_widget(form.order_text2) }}#}
  396. {#                                    {{ form_errors(form.order_text2) }}#}
  397. {#                                </div>#}
  398. {#                                <div class="ec-numberInput"><span>下文字</span>#}
  399. {#                                    {{ form_widget(form.order_text3) }}#}
  400. {#                                    {{ form_errors(form.order_text3) }}#}
  401. {#                                </div>#}
  402. {#                                <div class="ec-numberInput"><span>外枠の色</span>#}
  403. {#                                    {{ form_widget(form.order_color1) }}#}
  404. {#                                    {{ form_errors(form.order_color1) }}#}
  405. {#                                </div>#}
  406. {#                                <div class="ec-numberInput"><span>文字の色</span>#}
  407. {#                                    {{ form_widget(form.order_color2) }}#}
  408. {#                                    {{ form_errors(form.order_color2) }}#}
  409. {#                                </div>#}
  410. {#                                <div class="ec-numberInput"><span>書体</span>#}
  411. {#                                    {{ form_widget(form.order_font) }}#}
  412. {#                                    {{ form_errors(form.order_font) }}#}
  413. {#                                </div>#}
  414. {#                                <div class="ec-numberInput"><span>{{ '数量'|trans }}</span>#}
  415. {#                                    {{ form_widget(form.quantity) }}#}
  416. {#                                    {{ form_errors(form.quantity) }}#}
  417. {#                                </div>#}
  418.                             </div>
  419.                             {{ form_rest(form) }}
  420.                             <div class="ec-productRole__btn">
  421.                                 <button type="submit" class="ec-blockBtn--action add-cart">
  422.                                     {{ 'カートに入れる'|trans }}
  423.                                 </button>
  424.                             </div>
  425.                         {% else %}
  426.                             <div class="ec-productRole__btn">
  427.                                 <button type="button" class="ec-blockBtn--action" disabled="disabled">
  428.                                     {{ 'ただいま品切れ中です。'|trans }}
  429.                                 </button>
  430.                             </div>
  431.                         {% endif %}
  432.                     </form>
  433.                     <div class="ec-modal">
  434.                         <div class="ec-modal-overlay">
  435.                             <div class="ec-modal-wrap">
  436.                                 <span class="ec-modal-close"><span class="ec-icon"><img
  437.                                                 src="{{ asset('assets/icon/cross-dark.svg') }}" alt=""/></span></span>
  438.                                 <div id="ec-modal-header" class="text-center">{{ 'カートに追加しました。'|trans }}</div>
  439.                                 <div class="ec-modal-box">
  440.                                     <div class="ec-role">
  441.                                         <span class="ec-inlineBtn--cancel">{{ 'お買い物を続ける'|trans }}</span>
  442.                                         <a href="{{ url('cart') }}"
  443.                                            class="ec-inlineBtn--action">{{ 'カートへ進む'|trans }}</a>
  444.                                     </div>
  445.                                 </div>
  446.                             </div>
  447.                         </div>
  448.                     </div>
  449.                     {% if BaseInfo.option_favorite_product %}
  450.                         <form action="{{ url('product_add_favorite', {id:Product.id}) }}" method="post">
  451.                             <div class="ec-productRole__btn">
  452.                                 {% if is_favorite == false %}
  453.                                     <button type="submit" id="favorite" class="ec-blockBtn--cancel">
  454.                                         {{ 'お気に入りに追加'|trans }}
  455.                                     </button>
  456.                                 {% else %}
  457.                                     <button type="submit" id="favorite" class="ec-blockBtn--cancel"
  458.                                             disabled="disabled">{{ 'お気に入りに追加済です。'|trans }}
  459.                                     </button>
  460.                                 {% endif %}
  461.                             </div>
  462.                         </form>
  463.                     {% endif %}
  464.                     <div class="ec-productRole__description">{{ Product.description_detail|raw|nl2br }}
  465.                     </div>
  466.                 </div>
  467.             </div>
  468.         </div>
  469.         {% if Product.freearea %}
  470.             <div class="ec-productRole__description">
  471.                 {{ include(template_from_string(Product.freearea)) }}
  472.             </div>
  473.         {% endif %}
  474.     </div>
  475.     <script>
  476.         // https://mirai-kanban.com/ecshop/html/user_data/assets/js/test2.html
  477.         const uchiwa_base_dir = 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/';
  478.         let uchiwa_pattern;
  479.         let uchiwaCtx;
  480.         let uchiwaSelected_index;
  481.         let uchiwaCanvasHeight = 512;
  482.         const uchiwa_gritter_file = ['red.png', 'pink.png', 'orange.png'];
  483.         const uchiwa_color_list = [
  484.             {
  485.                 'name': '白',
  486.                 'type': 'solid',
  487.                 'code': '#ffffff',
  488.             },
  489.             {
  490.                 'name': '黒',
  491.                 'type': 'solid',
  492.                 'code': '#000000',
  493.             },
  494.             {
  495.                 'name': '赤',
  496.                 'type': 'solid',
  497.                 'code': '#ff0000',
  498.             },
  499.             {
  500.                 'name': '緑',
  501.                 'type': 'solid',
  502.                 'code': '#00ff00',
  503.             },
  504.             {
  505.                 'name': '青',
  506.                 'type': 'solid',
  507.                 'code': '#0000ff',
  508.             },
  509.             {
  510.                 'name': 'メタル赤',
  511.                 'type': 'glitter',
  512.                 'code': '0',
  513.             },
  514.             {
  515.                 'name': 'メタルピンク',
  516.                 'type': 'glitter',
  517.                 'code': '1',
  518.             },
  519.             {
  520.                 'name': 'メタルオレンジ',
  521.                 'type': 'glitter',
  522.                 'code': '2',
  523.             },
  524.         ];
  525.         function uchiwaSearchColorIndex(idx) {
  526.             let nowSelect = uchiwa_color_list[idx];
  527.             if (nowSelect.type === 'solid') {
  528.                 return nowSelect.code;
  529.             } else if (nowSelect.type === 'glitter') {
  530.                 return uchiwa_pattern[Number(nowSelect.code)];
  531.             }
  532.             return '#000000;'
  533.         }
  534.         function UchiwaInitSelector() {
  535.             const elements = [
  536.                 'uchiwa_back_color1',
  537.                 'uchiwa_back_color2',
  538.                 'uchiwa_back_color3',
  539.                 'uchiwa_back_color4',
  540.             ];
  541.             uchiwaSelected_index = [7, 1, 0, 2]; // default select
  542.             elements.forEach(function (name, index) {
  543.                 let elem = document.getElementById(name);
  544.                 uchiwa_color_list.forEach(function (item, c_index) {
  545.                     let addOption = document.createElement("option")
  546.                     addOption.value = c_index.toString();
  547.                     addOption.text = item.name;
  548.                     elem.add(addOption);
  549.                 })
  550.                 elem.selectedIndex = uchiwaSelected_index[index];
  551.             })
  552.         }
  553.         async function UchiwaInitCanvas() {
  554.             // const c = document.getElementById('c');
  555.             uchiwaCtx = document.getElementById('uchiwaCanvas').getContext('2d');
  556.             await uchiwaSetPatterns(uchiwaCtx);
  557.             await uchiwaGetFont("M PLUS Rounded 1c");
  558.             uchiwaWriteCanvas();
  559.         }
  560.         async function uchiwaGetFont(fontName) {
  561.             const urlFamilyName = fontName.replace(/ /g, "+");
  562.             const googleApiUrl = `https://fonts.googleapis.com/css?family=${urlFamilyName}`;
  563.             const response = await fetch(googleApiUrl);
  564.             if (response.ok) {
  565.                 // url()の中身のURLだけ抽出
  566.                 const cssFontFace = await response.text();
  567.                 const matchUrls = cssFontFace.match(/url\(.+?\)/g);
  568.                 if (!matchUrls) throw new Error("フォントが見つかりませんでした");
  569.                 for (const url of matchUrls) {
  570.                     const font = new FontFace(fontName, url);
  571.                     await font.load();
  572.                     document.fonts.add(font);
  573.                 }
  574.             } else {
  575.                 console.log('error get font fetch', response);
  576.             }
  577.         }
  578.         function uchiwaChangeFont(uchiwaCtx, size, width, font_size = 400) {
  579.             if (size === 'large') {
  580.                 uchiwaCtx.font = "normal normal 900 " + font_size + "px 'M PLUS Rounded 1c'";
  581.             } else {
  582.                 uchiwaCtx.font = "normal normal 900 " + font_size + "px 'M PLUS Rounded 1c'";
  583.             }
  584.             uchiwaCtx.lineWidth = width;
  585.         }
  586.         function uchiwaDrawLargeText(uchiwaCtx, text, small_lo = '', small_up = '') {
  587.             const canvas_height = document.getElementById('uchiwaCanvas').height;
  588.             const main_scale_base = canvas_height / 512;
  589.             // base
  590.             const main_size = 400 * main_scale_base; // 400
  591.             const main_x = 50;
  592.             const main_y = main_scale_base * 410; // 410 // main_size + 5
  593.             const main_round_width = [100 * main_scale_base, 40 * main_scale_base, 30 * main_scale_base, 0];
  594.             const small_size = 60 * main_scale_base;
  595.             let small_width = 0;
  596.             let small_x = 50;
  597.             const small_y = 450 * main_scale_base;
  598.             const small_x_up = 30;
  599.             const small_y_up = main_scale_base * 100;
  600.             const small_round_width = [60 * main_scale_base, 20 * main_scale_base, 10 * main_scale_base, 0];
  601.             let main_scale = (512 / canvas_height) / countGrapheme(text); // 512 / canvas_height
  602.             console.log('main_size:', main_size);
  603.             console.log('main_y:', main_y);
  604.             uchiwaCtx.scale(main_scale, 1);
  605.             uchiwaChangeFont(uchiwaCtx, 'large', main_round_width[0], main_size);
  606.             uchiwaCtx.lineJoin = "round";
  607.             uchiwaCtx.miterLimit = "5";
  608.             // uchiwaCtx.strokeStyle = "#00ff00";
  609.             uchiwaCtx.strokeStyle = uchiwaSearchColorIndex(uchiwaSelected_index[0]);
  610.             uchiwaCtx.strokeText(text, main_x, main_y);
  611.             uchiwaCtx.setTransform(1, 0, 0, 1, 0, 0);
  612.             if (small_lo !== '') {
  613.                 uchiwaChangeFont(uchiwaCtx, 'small', small_round_width[0], small_size);
  614.                 // uchiwaCtx.strokeStyle = "#00ff00";
  615.                 small_width = uchiwaCtx.measureText(small_lo);
  616.                 small_x = 450 - small_width.width
  617.                 uchiwaCtx.strokeText(small_lo, small_x, small_y);
  618.             }
  619.             if (small_up !== '') {
  620.                 uchiwaChangeFont(uchiwaCtx, 'small', small_round_width[0], small_size);
  621.                 // uchiwaCtx.strokeStyle = "#00ff00";
  622.                 uchiwaCtx.strokeText(small_up, small_x_up, small_y_up);
  623.             }
  624.             // outer line
  625.             uchiwaCtx.scale(main_scale, 1);
  626.             // for( let i = 1; i <= 3; i++ ) {
  627.             //     uchiwaChangeFont(uchiwaCtx, 'large', main_round_width[i], main_size);
  628.             //     uchiwaCtx.strokeStyle = uchiwaSearchColorIndex(uchiwaSelected_index[i]);
  629.             //     uchiwaCtx.strokeText(text, main_x, main_y);
  630.             // }
  631.             uchiwaChangeFont(uchiwaCtx, 'large', main_round_width[1], main_size);
  632.             uchiwaCtx.strokeStyle = uchiwaSearchColorIndex(uchiwaSelected_index[1]);
  633.             uchiwaCtx.strokeText(text, main_x, main_y);
  634.             // inner white
  635.             uchiwaChangeFont(uchiwaCtx, 'large', main_round_width[2], main_size);
  636.             uchiwaCtx.strokeStyle = uchiwaSearchColorIndex(uchiwaSelected_index[2]);
  637.             uchiwaCtx.strokeText(text, main_x, main_y);
  638.             // text
  639.             uchiwaChangeFont(uchiwaCtx, 'large', main_round_width[3], main_size);
  640.             uchiwaCtx.fillStyle = uchiwaSearchColorIndex(uchiwaSelected_index[3]);
  641.             uchiwaCtx.fillText(text, main_x, main_y);
  642.             uchiwaCtx.setTransform(1, 0, 0, 1, 0, 0);
  643.             if (small_lo !== '') {
  644.                 uchiwaChangeFont(uchiwaCtx, 'small', small_round_width[1], small_size);
  645.                 uchiwaCtx.strokeStyle = uchiwaSearchColorIndex(uchiwaSelected_index[1]);
  646.                 uchiwaCtx.strokeText(small_lo, small_x, small_y);
  647.                 uchiwaChangeFont(uchiwaCtx, 'small', small_round_width[2], small_size);
  648.                 uchiwaCtx.strokeStyle = uchiwaSearchColorIndex(uchiwaSelected_index[2]);
  649.                 uchiwaCtx.strokeText(small_lo, small_x, small_y);
  650.                 uchiwaChangeFont(uchiwaCtx, 'small', small_round_width[3], small_size);
  651.                 uchiwaCtx.fillStyle = uchiwaSearchColorIndex(uchiwaSelected_index[3]);
  652.                 uchiwaCtx.fillText(small_lo, small_x, small_y);
  653.             }
  654.             if (small_up !== '') {
  655.                 uchiwaChangeFont(uchiwaCtx, 'small', small_round_width[1], small_size);
  656.                 uchiwaCtx.strokeStyle = uchiwaSearchColorIndex(uchiwaSelected_index[1]);
  657.                 uchiwaCtx.strokeText(small_up, small_x_up, small_y_up);
  658.                 uchiwaChangeFont(uchiwaCtx, 'small', small_round_width[2], small_size);
  659.                 uchiwaCtx.strokeStyle = uchiwaSearchColorIndex(uchiwaSelected_index[2]);
  660.                 uchiwaCtx.strokeText(small_up, small_x_up, small_y_up);
  661.                 uchiwaChangeFont(uchiwaCtx, 'small', small_round_width[3], small_size);
  662.                 uchiwaCtx.fillStyle = uchiwaSearchColorIndex(uchiwaSelected_index[3]);
  663.                 uchiwaCtx.fillText(small_up, small_x_up, small_y_up);
  664.             }
  665.         }
  666.         function uchiwaLoadImages(list) {
  667.             async function load(src) {
  668.                 const img = new Image()
  669.                 img.src = uchiwa_base_dir + src
  670.                 await img.decode()
  671.                 return img
  672.             }
  673.             return Promise.all(list.map(src => load(src)))
  674.         }
  675.         async function uchiwaSetPatterns(uchiwaCtx) {
  676.             const images = await uchiwaLoadImages(uchiwa_gritter_file);
  677.             uchiwa_pattern = images.map(await function (img) {
  678.                 return uchiwaCtx.createPattern(img, "repeat");
  679.             })
  680.         }
  681.         function uchiwaWriteCanvas() {
  682.             const c = document.getElementById('uchiwaCanvas');
  683.             // const element = document.getElementById('uchiwa_main_text');
  684.             const text = document.getElementById('uchiwa_main_text').value.toString();
  685.             const up_text = document.getElementById('uchiwa_up_text').value.toString();
  686.             const lo_text = document.getElementById('uchiwa_low_text').value.toString();
  687.             uchiwaCtx.setTransform(1, 0, 0, 1, 0, 0);
  688.             uchiwaCtx.clearRect(0, 0, c.width, c.height);
  689.             uchiwaCtx.fillStyle = "#cccccc";
  690.             uchiwaCtx.fillRect(0, 0, c.width, c.height);
  691.             if (text !== '') {
  692.                 uchiwaDrawLargeText(uchiwaCtx, text, lo_text, up_text);
  693.             }
  694.         }
  695.         function countGrapheme(string) {
  696.             const segmenter = new Intl.Segmenter("ja", {granularity: "grapheme"});
  697.             return [...segmenter.segment(string)].length;
  698.         }
  699.         window.addEventListener("load", () => {
  700.             UchiwaInitSelector();
  701.             console.log("ページが完全に読み込まれました");
  702.             UchiwaInitCanvas();
  703.             const button = document.getElementById("uchiwa_set");
  704.             button.addEventListener("click", uchiwaWriteCanvas);
  705.             const base_select = document.getElementById('uchiwa_back_color1');
  706.             base_select.addEventListener("change", function () {
  707.                 uchiwaSelected_index[0] = Number(base_select.value);
  708.                 uchiwaWriteCanvas();
  709.             });
  710.             const base_select2 = document.getElementById('uchiwa_back_color2');
  711.             base_select2.addEventListener("change", function () {
  712.                 uchiwaSelected_index[1] = Number(base_select2.value);
  713.                 uchiwaWriteCanvas();
  714.             });
  715.             const base_select3 = document.getElementById('uchiwa_back_color3');
  716.             base_select3.addEventListener("change", function () {
  717.                 uchiwaSelected_index[2] = Number(base_select3.value);
  718.                 uchiwaWriteCanvas();
  719.             });
  720.             const base_select4 = document.getElementById('uchiwa_back_color4');
  721.             base_select4.addEventListener("change", function () {
  722.                 uchiwaSelected_index[3] = Number(base_select4.value);
  723.                 uchiwaWriteCanvas();
  724.             });
  725.             $('select[name=classcategory_id1]').on('change', function (data) {
  726.                 let size_select = $(this).val();
  727.                 const canvasElement = document.getElementById('uchiwaCanvas');
  728.                 switch (Number(size_select)) {
  729.                     case 7:
  730.                         // uchiwaCtx.height = 512;
  731.                         canvasElement.height = 512;
  732.                         break;
  733.                     case 8:
  734.                         canvasElement.height = 256;
  735.                         // uchiwaCtx.height = 256;
  736.                         break;
  737.                     case 9:
  738.                         canvasElement.height = 170;
  739.                         // uchiwaCtx.height = 170;
  740.                         break;
  741.                 }
  742.                 uchiwaWriteCanvas();
  743.             })
  744.         });
  745.     </script>
  746. {#    <script>#}
  747. {#        const item_product_color_type1 = "{{ Product.product_color_type1 }}";#}
  748. {#        const item_product_color_type2 = "{{ Product.product_color_type2 }}";#}
  749. {#        const gritter_array = [#}
  750. {#            'レッド','パステルピンク','オレンジ','パープル',#}
  751. {#            'ブルー','アクアブルー','イエロー','パステルグリーン',#}
  752. {#            'ブラック','ゴールド',#}
  753. {#        ];#}
  754. {#        const solid_array = [#}
  755. {#            '1:mono','2:mono','3:mono','4:mono',#}
  756. {#            '5:レッド','6:レッド','7:レッド',#}
  757. {#            '8:パープル','9:パープル','10:パープル','11:パープル',#}
  758. {#            '12:ピンク','13:ピンク','14:ピンク','15:ピンク',#}
  759. {#            '16:オレンジ','17:オレンジ','18:オレンジ',#}
  760. {#            '19:イエロー','20:イエロー',#}
  761. {#            '21:グリーン','22:グリーン','23:グリーン','24:グリーン',#}
  762. {#            '25:ブルー','26:ブルー','27:ブルー','28:ブルー','30:ブルー',#}
  763. {#            '31:エメラルド','32:エメラルド','33:エメラルド','34:エメラルド',#}
  764. {#            '35:ビビッド','36:ビビッド','37:ビビッド',#}
  765. {#        ]#}
  766. {#        let color1_array = gritter_array;#}
  767. {#        let color2_array = gritter_array;#}
  768. {#        if( item_product_color_type1 === 'ソリッド') {#}
  769. {#            color1_array = solid_array;#}
  770. {#        }#}
  771. {#        if( item_product_color_type2 === 'ソリッド') {#}
  772. {#            color2_array = solid_array;#}
  773. {#        }#}
  774. {#        $('form #order_color1').empty();#}
  775. {#        $('form #order_color2').empty();#}
  776. {#        color1_array.forEach( item => {#}
  777. {#            $('form #order_color1').append('<option value="' + item + '">' + item + '</option>');#}
  778. {#        })#}
  779. {#        color2_array.forEach( item => {#}
  780. {#            $('form #order_color2').append('<option value="' + item + '">' + item + '</option>');#}
  781. {#        })#}
  782. {#    </script>#}
  783.     <script>
  784.         const item_product_color_type1 = "{{ Product.product_color_type1 }}";
  785.         const item_product_color_type2 = "{{ Product.product_color_type2 }}";
  786.         const gritter_array = [
  787.             { 'label': 'レッド', 'url': 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/pink.png' },
  788.             { 'label': 'パステルピンク', 'url': 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/pink.png' },
  789.             { 'label': 'オレンジ', 'url': 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/pink.png' },
  790.             { 'label': 'パープル', 'url': 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/pink.png' },
  791.             { 'label': 'ブルー', 'url': 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/pink.png' },
  792.             { 'label': 'アクアブルー', 'url': 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/pink.png' },
  793.             { 'label': 'イエロー', 'url': 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/pink.png' },
  794.             { 'label': 'パステルグリーン', 'url': 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/pink.png' },
  795.             { 'label': 'ブラック', 'url': 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/pink.png' },
  796.             { 'label': 'ゴールド', 'url': 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/pink.png' },
  797.             { 'label': 'シルバー', 'url': 'https://mirai-kanban.com/ecshop/html/user_data/assets/js/pink.png' }
  798.         ];
  799.         const solid_array = [
  800.             { 'label': '1:mono', 'color': '#FFFFFF' },
  801.             { 'label': '2:mono', 'color': '#C9CACA' },
  802.             { 'label': '3:mono', 'color': '#797A7A' },
  803.             { 'label': '4:mono', 'color': '#231815' },
  804.             { 'label': '5:レッド', 'color': '#C30D23' },
  805.             { 'label': '6:レッド', 'color': '#E83828' },
  806.             { 'label': '7:レッド', 'color': '#DC4F48' },
  807.             { 'label': '8:パープル', 'color': '#A3127F' },
  808.             { 'label': '9:パープル', 'color': '#C02D8B' },
  809.             { 'label': '10:パープル', 'color': '#DE83B3' },
  810.             { 'label': '11:パープル', 'color': '#B1A1CB' },
  811.             { 'label': '12:ピンク', 'color': '#E4007F' },
  812.             { 'label': '13:ピンク', 'color': '#E7397A' },
  813.             { 'label': '14:ピンク', 'color': '#EB6BA4' },
  814.             { 'label': '15:ピンク', 'color': '#F0A6C7' },
  815.             { 'label': '16:オレンジ', 'color': '#EE761C' },
  816.             { 'label': '17:オレンジ', 'color': '#F49E15' },
  817.             { 'label': '18:オレンジ', 'color': '#F8B62D' },
  818.             { 'label': '19:イエロー', 'color': '#F6E123' },
  819.             { 'label': '20:イエロー', 'color': '#F0EB79' },
  820.             { 'label': '21:グリーン', 'color': '#22AC38' },
  821.             { 'label': '22:グリーン', 'color': '#8FC31F' },
  822.             { 'label': '23:グリーン', 'color': '#B4D23E' },
  823.             { 'label': '24:グリーン', 'color': '#E1D841' },
  824.             { 'label': '25:ブルー', 'color': '#0067B6' },
  825.             { 'label': '26:ブルー', 'color': '#00A0E9' },
  826.             { 'label': '27:ブルー', 'color': '#43B9DF' },
  827.             { 'label': '28:ブルー', 'color': '#8FD2ED' },
  828.             { 'label': '29:ブルー', 'color': '#C1E5F1' },
  829.             { 'label': '30:エメラルド', 'color': '#4CB787' },
  830.             { 'label': '31:エメラルド', 'color': '#3DB79F' },
  831.             { 'label': '32:エメラルド', 'color': '#7BC8B9' },
  832.             { 'label': '33:エメラルド', 'color': '#9BD3CA' },
  833.             { 'label': '34:ビビッドカラー', 'color': '#0091DB' },
  834.             { 'label': '35:ビビッドカラー', 'color': '#FFF100' },
  835.             { 'label': '36:ビビッドカラー', 'color': '#E61673' }
  836.         ];
  837.         let color1_array = gritter_array;
  838.         let color2_array = gritter_array;
  839.         if( item_product_color_type1 === 'ソリッド') {
  840.             color1_array = solid_array;
  841.         }
  842.         if( item_product_color_type2 === 'ソリッド') {
  843.             color2_array = solid_array;
  844.         }
  845.         $('form #order_color1').empty();
  846.         $('form #order_color2').empty();
  847.         color1_array.forEach( item => {
  848.             $('form #order_color1').append('<option value="' + item.color + '">' + item.label + '</option>');
  849.         })
  850.         color2_array.forEach( item => {
  851.             $('form #order_color2').append('<option value="' + item.color + '">' + item.label + '</option>');
  852.         })
  853.     </script>
  854. {% endblock %}