app/Plugin/ProductOption42/Resource/template/admin/Order/search_product_js.twig line 1

Open in your IDE?
  1. {#
  2. * Plugin Name : ProductOption
  3. *
  4. * Copyright (C) BraTech Co., Ltd. All Rights Reserved.
  5. * http://www.bratech.co.jp/
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. #}
  10. {% block css %}
  11. <link rel="stylesheet" href="{{ asset('assets/css/tempusdominus-bootstrap-4.min.css', 'admin') }}">
  12. <style type="text/css">
  13.     .datepicker-days th.dow:first-child,
  14.     .datepicker-days td:first-child {
  15.         color: #f00;
  16.     }
  17.     .datepicker-days th.dow:last-child,
  18.     .datepicker-days td:last-child {
  19.         color: #00f;
  20.     }
  21. </style>
  22. {% endblock %}
  23. {% block javascript %}
  24. <script>
  25.     $(function() {
  26.         if ($('[type="date"]').prop('type') != 'date' && $('[type="date"]').prop('name').match(/productoption\d+/) != null) {
  27.             // input type属性でdateが利用できるかどうか(カレンダー表示できないブラウザ対応)
  28.             $.when(
  29.                 $.getScript("{{ asset('assets/js/vendor/moment.min.js', 'admin') }}"),
  30.                 $.getScript("{{ asset('assets/js/vendor/moment-with-locales.min.js', 'admin') }}"),
  31.                 $.getScript("{{ asset('assets/js/vendor/tempusdominus-bootstrap-4.min.js', 'admin') }}")
  32.             ).done(function() {
  33.                 $('input[type=date]').datetimepicker({
  34.                     locale: '{{ eccube_config.locale }}',
  35.                     format: 'YYYY-MM-DD',
  36.                     useCurrent: false,
  37.                     buttons: {
  38.                         showToday: true,
  39.                         showClose: true
  40.                     }
  41.                 });
  42.             });
  43.         }
  44.     });
  45.     optionPrices = {{ optionPrices|json_encode|raw }};
  46.     optionMultiples = {{ optionMultiples|json_encode|raw }};
  47.     optionDefaults = {{ optionDefaults|json_encode|raw }};
  48.     // 受注明細行を追加する.
  49.     function fnAddOrderItemOption($row, product_id, type, product_name) {
  50.         // 規格1の要素を取得
  51.         var $sele1 = $row.find('select[name=classcategory_id1]');
  52.         // 規格2の要素を取得
  53.         var $sele2 = $row.find('select[name=classcategory_id2]');
  54.         var product_class_id = null;
  55.         var price = 0;
  56.         var quantity = 1;
  57.         // 規格なし商品の場合
  58.         if (!$sele1.length && !$sele2.length) {
  59.             var product = productsClassCategories[product_id]['__unselected2']['#'];
  60.             product_class_id = product['product_class_id'];
  61.             price = product['price02'];
  62.             // 規格が登録されている商品の場合
  63.         } else if ($sele1.length) {
  64.             if ($sele2.length) {
  65.                 var class_category_id1 = $sele1.val();
  66.                 var class_cateogry_id2 = $sele2.val();
  67.                 if (class_category_id1 == '__unselected' || !class_cateogry_id2) {
  68.                     alert('{{'admin.product.unselected_class'|trans}}');
  69.                     return;
  70.                 }
  71.                 var product = productsClassCategories[product_id][class_category_id1]['#' + class_cateogry_id2];
  72.                 product_class_id = product['product_class_id'];
  73.                 price = product['price02'];
  74.             } else {
  75.                 var class_category_id1 = $sele1.val();
  76.                 if (class_category_id1 == '__unselected') {
  77.                     alert('{{ 'admin.product.unselected_class'|trans }}');
  78.                     return;
  79.                 }
  80.                 var product = productsClassCategories[product_id][class_category_id1]['#'];
  81.                 product_class_id = product['product_class_id'];
  82.                 price = product['price02'];
  83.             }
  84.         }
  85.         // オプション情報の取得
  86.         var option_id = null;
  87.         var options = {};
  88.         price = parseFloat(price.replace(/,/g,''));
  89.         $form = $("form[name=product_form"+product_id+"]");
  90.         $form.next().find("[name^=productoption]").each(function(){
  91.             var option_id = $(this).attr('name').replace(/productoption/ig,'');
  92.             var id = $(this).prop("id");
  93.             if(id.match(/^productoption\d[\d_]*\d$/)){
  94.                 var type = $(this).attr('type');
  95.                 var kind = $(this).prop('tagName');
  96.                 var value = null;
  97.                 if(type == 'radio'){
  98.                     if($(this).prop('checked')){
  99.                         value = parseFloat($(this).val());
  100.                         if(!optionDefaults[product_id][option_id][value])options[option_id] = value;
  101.                         price += parseFloat(optionPrices[product_id][option_id][value]);
  102.                     }
  103.                 }else if(type == 'checkbox'){
  104.                     option_id = option_id.replace('[]','');
  105.                     if($(this).prop('checked')){
  106.                         if(options[option_id] == undefined){
  107.                             options[option_id] = [];
  108.                         }
  109.                         value = parseFloat($(this).val());
  110.                         options[option_id].push(value);
  111.                         price += parseFloat(optionPrices[product_id][option_id][value]);
  112.                     }
  113.                 }else{
  114.                     value = $(this).val();
  115.                     if(value.length > 0){
  116.                         var kind = $(this).prop('tagName');
  117.                         if(kind == 'SELECT'){
  118.                             if(!optionDefaults[product_id][option_id][value])options[option_id] = value;
  119.                             price += parseFloat(optionPrices[product_id][option_id][value]);
  120.                         }else{
  121.                             var multi = 1;
  122.                             if(type == 'number'){
  123.                                 if(optionMultiples[product_id][option_id]){
  124.                                     multi = parseFloat(value);
  125.                                 }
  126.                             }
  127.                             price += parseFloat(optionPrices[product_id][option_id][0]*multi);
  128.                             options[option_id] = value;
  129.                         }
  130.                     }
  131.                 }
  132.             }
  133.         });
  134.         var prototype = $collectionHolder.data('prototype');
  135.         index++;
  136.         var newForm = prototype.replace(/__name__/g, index);
  137.         $collectionHolder.children('tbody').append(newForm);
  138.         var $lastRow = $collectionHolder.children('tbody').children('tr').last();
  139.         $($lastRow).find(formIdPrefix + index + '_ProductClass').val(product_class_id);
  140.         $($lastRow).find(formIdPrefix + index + '_price').val(price);
  141.         $($lastRow).find(formIdPrefix + index + '_quantity').val(quantity);
  142.         $($lastRow).find(formIdPrefix + index + '_order_item_type').val(type);
  143.         $($lastRow).find(formIdPrefix + index + '_product_name').val(product_name);
  144.         $($lastRow).find(formIdPrefix + index + '_option_serial').val(JSON.stringify(options));
  145.         // モーダル閉じる.
  146.         $('#searchProductModal').modal('hide');
  147.         // 再計算のためsubmit.
  148.         $('#form1').submit();
  149.         return false;
  150.     }
  151. </script>
  152. {% endblock %}