src/Eccube/Resource/template/admin/Order/search_product.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. <script>
  9.     // 商品規格情報. 規格2のプルダウンリストの設定に利用する,
  10.     var productsClassCategories = {
  11.         {% for Product in pagination %}
  12.         "{{ Product.id|escape('js') }}": {{ class_categories_as_json(Product, false)|raw }}{% if loop.last == false %}, {% endif %}
  13.         {% endfor %}
  14.     };
  15.     // 規格1が選択された際に, 規格2のプルダウンリストを設定する,
  16.     function fnSetClassCategory2(select, product_id) {
  17.         // 規格1の要素を取得
  18.         var $sele1 = $(select);
  19.         // 規格2の要素を取得
  20.         var $sele2 = $sele1.parents(".align-middle").find('select[name=classcategory_id2]');
  21.         // 規格1の選択肢
  22.         var classcat_id1 = $sele1.val() ? $sele1.val() : '';
  23.         // 規格2がある場合は選択肢を書き換える
  24.         if ($sele2 && $sele2.length) {
  25.             // 規格2の選択肢をクリア
  26.             $sele2.children().remove();
  27.             var classcat2 = productsClassCategories[product_id][classcat_id1];
  28.             // 規格2の要素を設定
  29.             for (var key in classcat2) {
  30.                 if (classcat2.hasOwnProperty(key)) {
  31.                     var id = classcat2[key].classcategory_id2;
  32.                     var name = classcat2[key].name;
  33.                     var option = $('<option />').val(id ? id : '').text(name);
  34.                     $sele2.append(option);
  35.                 }
  36.             }
  37.         }
  38.     }
  39.     // 受注明細行を追加する.
  40.     function fnAddOrderItem($row, product_id, type, product_name) {
  41.         // 規格1の要素を取得
  42.         var $sele1 = $row.find('select[name=classcategory_id1]');
  43.         // 規格2の要素を取得
  44.         var $sele2 = $row.find('select[name=classcategory_id2]');
  45.         var product_class_id = null;
  46.         var price = 0;
  47.         var quantity = 1;
  48.         // 規格なし商品の場合
  49.         if (!$sele1.length && !$sele2.length) {
  50.             var product = productsClassCategories[product_id]['__unselected2']['#'];
  51.             product_class_id = product['product_class_id'];
  52.             price = product['price02'];
  53.             // 規格が登録されている商品の場合
  54.         } else if ($sele1.length) {
  55.             if ($sele2.length) {
  56.                 var class_category_id1 = $sele1.val();
  57.                 var class_cateogry_id2 = $sele2.val();
  58.                 if (class_category_id1 == '__unselected' || !class_cateogry_id2) {
  59.                     alert('{{'admin.product.unselected_class'|trans}}');
  60.                     return;
  61.                 }
  62.                 var product = productsClassCategories[product_id][class_category_id1]['#' + class_cateogry_id2];
  63.                 product_class_id = product['product_class_id'];
  64.                 price = product['price02'];
  65.             } else {
  66.                 var class_category_id1 = $sele1.val();
  67.                 if (class_category_id1 == '__unselected') {
  68.                     alert('{{ 'admin.product.unselected_class'|trans }}');
  69.                     return;
  70.                 }
  71.                 var product = productsClassCategories[product_id][class_category_id1]['#'];
  72.                 product_class_id = product['product_class_id'];
  73.                 price = product['price02'];
  74.             }
  75.         }
  76.         // 既存の受注明細のポイント付与率を取得する. 取得できない場合は店舗基本情報の付与率を設定する.
  77.         var point_rate = $('input[type=hidden][id$=point_rate]').first().val();
  78.         if (point_rate === undefined) {
  79.             point_rate = '{{ BaseInfo.basic_point_rate }}';
  80.         }
  81.         var prototype = $collectionHolder.data('prototype');
  82.         index++;
  83.         var newForm = prototype.replace(/__name__/g, index);
  84.         $collectionHolder.children('tbody').append(newForm);
  85.         var $lastRow = $collectionHolder.children('tbody').children('tr').last();
  86.         $($lastRow).find(formIdPrefix + index + '_ProductClass').val(product_class_id);
  87.         $($lastRow).find(formIdPrefix + index + '_price').val(price);
  88.         $($lastRow).find(formIdPrefix + index + '_quantity').val(quantity);
  89.         $($lastRow).find(formIdPrefix + index + '_order_item_type').val(type);
  90.         $($lastRow).find(formIdPrefix + index + '_product_name').val(product_name);
  91.         $($lastRow).find(formIdPrefix + index + '_point_rate').val(point_rate);
  92.         // モーダル閉じる.
  93.         $('#searchProductModal').modal('hide');
  94.         // 再計算のためsubmit.
  95.         $('#form1').submit();
  96.         return false;
  97.     }
  98.     // 商品検索
  99.     $('#product_pagination a').on('click', function(event) {
  100.         if (!$(this).parent().is('.active')) {
  101.             var list = $('#searchProductModalList');
  102.             list.children().remove();
  103.             $.ajax({
  104.                 url: $(this).attr('href'),
  105.                 type: 'GET',
  106.                 dataType: 'html'
  107.             }).done(function(data) {
  108.                 $('#searchProductModalList').html(data);
  109.             }).fail(function(data) {
  110.                 alert('search product failed.');
  111.             });
  112.         }
  113.         event.preventDefault();
  114.     });
  115. </script>
  116. <table class="table table-striped table-sm mb-3">
  117.     <thead class="table-active">
  118.     <tr>
  119.         <th class="pt-2 pb-2 ps-3">{{ 'admin.product.product_id'|trans }}</th>
  120.         <th class="pt-2 pb-2 ps-3">{{ 'admin.product.product_name_and_code'|trans }}</th>
  121.         <th class="pt-2 pb-2">{{ 'admin.product.product_class__short'|trans }}</th>
  122.         <th class="pt-2 pb-2 pe-3"></th>
  123.     </tr>
  124.     </thead>
  125.     <tbody>
  126.     {% for Product in pagination %}
  127.         <form name="product_form{{ Product.id }}">
  128.             {% set form = forms[Product.id] %}
  129.             <tr>
  130.                 <td class="align-middle ps-3">
  131.                     {{ Product.id }}
  132.                 </td>
  133.                 <td class="align-middle ps-3">
  134.                     <p class="m-0"> {{ Product.name }}</p>
  135.                     <span>
  136.                         {% if Product.hasProductClass %}
  137.                             {{ Product.code_min }}~{{ Product.code_max }}
  138.                         {% else %}
  139.                             {{ Product.code_min }}
  140.                         {% endif %}
  141.                     </span>
  142.                 </td>
  143.                 <td class="align-middle">
  144.                     {% if form.classcategory_id1 is defined %}
  145.                         <div class="row mb-2">
  146.                             <div class="col-4 pe-0"><span>{{ form_label(form.classcategory_id1) }}</span></div>
  147.                             <div class="col-8 text-start ps-0">
  148.                                 {{ form_widget(form.classcategory_id1, { attr : { 'onchange' : "fnSetClassCategory2(this," ~ Product.id ~ ")" } } ) }}
  149.                             </div>
  150.                         </div>
  151.                     {% endif %}
  152.                     {% if form.classcategory_id2 is defined %}
  153.                         <div class="row">
  154.                             <div class="col-4 pe-0"><span>{{ form_label(form.classcategory_id2) }}</span></div>
  155.                             <div class="col-8 text-start ps-0">
  156.                                 {{ form_widget(form.classcategory_id2, {'id': ''}) }}
  157.                             </div>
  158.                         </div>
  159.                     {% endif %}
  160.                 </td>
  161.                 {% if Product.stock_find %}
  162.                     <td class="align-middle pe-3 text-end">
  163.                         <button type="button" class="btn btn-ec-actionIcon" onclick="fnAddOrderItem($(this).parent().parent(), {{ Product.id }}, {{ constant('Eccube\\Entity\\Master\\OrderItemType::PRODUCT') }}, '{{ Product.name|escape('js') }}')" name="mode" value="modal">
  164.                             <i class="fa fa-plus fa-lg fw-bold text-secondary"></i>
  165.                         </button>
  166.                     </td>
  167.                 {% else %}
  168.                     <td class="align-middle pe-3 text-end">
  169.                         {{ 'front.product.out_of_stock_label'|trans }}
  170.                     </td>
  171.                 {% endif %}
  172.             </tr>
  173.         </form>
  174.     {% endfor %}
  175.     </tbody>
  176. </table>
  177. {% if pagination.totalItemCount > 0 %}
  178.     <div id="product_pagination" class="row justify-content-md-center mb-4">
  179.         {% include "@admin/pager.twig" with {'pages': pagination.paginationData, 'routes': 'admin_order_search_product_page'} %}
  180.     </div>
  181. {% endif %}