app/template/default/JoolenDisplayPoints4/Resource/template/default/Product/list_js.twig line 1

Open in your IDE?
  1. {#
  2. Plugin Name: JoolenDisplayPoints4
  3. Copyright(c) joolen inc. All Rights Reserved.
  4. https://www.joolen.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. {% block javascript %}
  9. <script>
  10.     $(function () {
  11.         eccube.displayPoints = {{ display_point_json | raw }};
  12.         // 設定>店舗設定>基本設定のポイント機能の有効/無効を取得する
  13.         let is_option_point = '{{ BaseInfo.isOptionPoint }}';
  14.         // -----------------------------------
  15.         // 画面描画時に獲得予定ポイントを表示する
  16.         // -----------------------------------
  17.         // ポイント機能が有効の場合のみ以下の処理を実行する
  18.         if ( is_option_point ) {
  19.             $('[id^=productForm]').each(function() {
  20.                 let product_id = $(this).find('input[name=product_id]').val();
  21.                 let point_display_container = $(this).find('.point-display-container');
  22.                 let min_point = eccube.displayPoints[product_id]['min_point'];
  23.                 let max_point = eccube.displayPoints[product_id]['max_point'];
  24.                 let is_no_point_flag = eccube.displayPoints[product_id]['is_no_point_flag'];
  25.                 if(is_no_point_flag) {
  26.                     point_display_container.html(`<span class="ec-color-red">{{ 'joolendisplaypoints4.front.no_point_flag.message' | trans }}</span>`);
  27.                     point_display_container.show();
  28.                     return;
  29.                 }
  30.                 if( min_point !== 0 && max_point !== 0){
  31.                     let point;
  32.                     if (min_point === max_point) {
  33.                         point =  min_point;
  34.                     } else {
  35.                         point = min_point + ' 〜 ' + max_point;
  36.                     }
  37.                     point_display_container.data('dafault-point', point);
  38.                     setPointContainer(point_display_container, ':' + point + 'pt', '.point-display');
  39.                 }
  40.             });
  41.         }
  42.         // -----------------------------------
  43.         // 規格1選択時
  44.         // -----------------------------------
  45.         $('select[name=classcategory_id1]')
  46.             .change(function() {
  47.                 if ( !is_option_point ) {
  48.                     return;
  49.                 }
  50.                 let $form = $(this).parents('form');
  51.                 let product_id = $form.find('input[name=product_id]').val();
  52.                 let $sele1 = $(this);
  53.                 let $sele2 = $form.find('select[name=classcategory_id2]');
  54.                 let classcat_id1 = $sele1.val();
  55.                 let classcat_id2 = $sele2.val() ? $sele2.val() : '';
  56.                 let point_display_container = $form.find('.point-display-container');
  57.                 let is_no_point_flag = eccube.displayPoints[product_id]['is_no_point_flag'];
  58.                 // 規格1が未選択状態に戻った場合
  59.                 if (classcat_id1 === '__unselected') {
  60.                     let point = point_display_container.data('dafault-point');
  61.                     setPointContainer(point_display_container, ':' + point + 'pt', '.point-display');
  62.                     return;
  63.                 }
  64.                 // ポイント付与が無効の場合
  65.                 if(is_no_point_flag) {
  66.                     let message = `<span class="ec-color-red">{{ 'joolendisplaypoints4.front.no_point_flag.message' | trans }}</span>`;
  67.                     setPointContainer(point_display_container, message);
  68.                     return;
  69.                 }
  70.                 // 規格1のみの場合だけ獲得可能ポイントを表示する
  71.                 if (!$sele2.length) {
  72.                     let point = eccube.displayPoints[product_id][classcat_id1]['#' + classcat_id2]['point'];
  73.                     setPointContainer(point_display_container, ':' + point + 'pt', '.point-display');
  74.                 } else {
  75.                     // 規格2が未選択の場合
  76.                     let message = `<span class="ec-color-red">{{ 'joolendisplaypoints4.front.no_select_class_category2.message' | trans }}。</span>`;
  77.                     setPointContainer(point_display_container, message, '.point-display');
  78.                 }
  79.             });
  80.         // -----------------------------------
  81.         // 規格2選択時
  82.         // -----------------------------------
  83.         $('select[name=classcategory_id2]')
  84.             .change(function () {
  85.                 if ( !is_option_point ) {
  86.                     return;
  87.                 }
  88.                 let $form = $(this).parents('form');
  89.                 let product_id = $form.find('input[name=product_id]').val();
  90.                 let $sele1 = $form.find('select[name=classcategory_id1]');
  91.                 let $sele2 = $(this);
  92.                 let point_display_container = $form.find('.point-display-container');
  93.                 let eccube = window.eccube;
  94.                 let classcat_id1 = $sele1.val();
  95.                 let classcat_id2 = $sele2.val() ? $sele2.val() : '';
  96.                 let is_no_point_flag = eccube.displayPoints[product_id]['is_no_point_flag'];
  97.                 // ポイント付与が無効の場合
  98.                 if(is_no_point_flag) {
  99.                     let message = `<span class="ec-color-red">{{ 'joolendisplaypoints4.front.no_point_flag.message' | trans }}</span>`;
  100.                     setPointContainer(point_display_container, message);
  101.                     return;
  102.                 }
  103.                 // 規格2が未選択の場合
  104.                 if (!classcat_id2 ) {
  105.                     let message = `<span class="ec-color-red">{{ 'joolendisplaypoints4.front.no_select_class_category2.message' | trans }}。</span>`;
  106.                     setPointContainer(point_display_container, message, '.point-display');
  107.                     return;
  108.                 }
  109.                 let classcat2 = eccube.displayPoints[product_id][classcat_id1]['#' + classcat_id2];
  110.                 let point = classcat2['point'];
  111.                 setPointContainer(point_display_container, ':' + point + 'pt', '.point-display');
  112.             });
  113.         function setPointContainer(point_display_container, container_data, children_class_name = null,)
  114.         {
  115.             if(!children_class_name) {
  116.                 point_display_container.html(container_data);
  117.             } else {
  118.                 point_display_container.children(children_class_name).html(container_data);
  119.             }
  120.             point_display_container.show();
  121.         }
  122.     });
  123. </script>
  124. {% endblock %}