Changeset 18875


Ignore:
Timestamp:
2010/10/29 21:00:06 (13 years ago)
Author:
nanasess
bzr:base-revision:
svn-v4:1e3b908f-19a9-db11-a64c-001125224ba8:branches/version-2_5-dev:18874
bzr:committer:
Kentaro Ohkouchi <ohkouchi@loop-az.jp>
bzr:file-ids:

data/Smarty/templates/admin/order/product_select.tpl 17293@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Fcomu-ver2%2Fdata%2FSmarty%2Ftemplates%2Fdefault%2Fadmin%2Forder%2Fproduct_select.tpl
data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php 15594@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Ffeature-module-update%2Fdata%2Fclass%2Fpages%2Fadmin%2Forder%2FLC_Page_Admin_Order_Edit.php
data/class/pages/admin/order/LC_Page_Admin_Order_ProductSelect.php 17293@1e3b908f-19a9-db11-a64c-001125224ba8:branches%2Fcomu-ver2%2Fdata%2Fclass%2Fpages%2Fadmin%2Forder%2FLC_Page_Admin_Order_ProductSelect.php
bzr:mapping-version:
v4
bzr:repository-uuid:
1e3b908f-19a9-db11-a64c-001125224ba8
bzr:revision-id:
ohkouchi@loop-az.jp-20101029120001-3vgqckvbr2quqhw1
bzr:revno:
2355
bzr:revprop:branch-nick:
branches/version-2_5-dev
bzr:root:
branches/version-2_5-dev
bzr:timestamp:
2010-10-29 21:00:01.309999943 +0900
bzr:user-agent:
bzr2.2.0+bzr-svn1.0.3
svn:original-date:
2010-10-29T12:00:01.310000Z
Message:

規格のデータベースを木構造に(#781)

  • 商品追加時の規格のプルダウンを修正
  • 追加商品検索時のパフォーマンス改善
Location:
branches/version-2_5-dev/data
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_5-dev/data/Smarty/templates/admin/order/product_select.tpl

    r18873 r18875  
    2828self.moveTo(20,20);self.focus(); 
    2929 
    30 function func_submit(product_id, class_name1, class_name2) { 
     30function func_submit(product_id, class_name1, class_name2, product_class_id) { 
    3131  var err_text = ''; 
    3232  var fm = window.opener.document.form1; 
     
    4040  <!--{if $tpl_no != ''}--> 
    4141  var opner_product_id = 'edit_product_id'; 
    42   var opner_classcategory_id1 = 'edit_classcategory_id1'; 
    43   var opner_classcategory_id2 = 'edit_classcategory_id2'; 
     42  var opner_product_class_id = 'edit_product_class_id'; 
    4443  fm1.getElementById("no").value = <!--{$tpl_no}-->; 
    4544  <!--{else}--> 
    4645  var opner_product_id = 'add_product_id'; 
    47   var opner_classcategory_id1 = 'add_classcategory_id1'; 
    48   var opner_classcategory_id2 = 'add_classcategory_id2'; 
     46  var opner_product_class_id = 'add_product_class_id'; 
    4947  <!--{/if}--> 
    5048 
     
    6159 
    6260  fm1.getElementById(opner_product_id).value = product_id; 
    63   if (class1_id != '') { 
    64     fm1.getElementById(opner_classcategory_id1).value = class1_id; 
    65   } 
    66   if (class2_id != '') { 
    67     fm1.getElementById(opner_classcategory_id2).value = class2_id; 
    68   } 
     61  fm1.getElementById(opner_product_class_id).value = product_class_id; 
    6962 
    7063  fm.mode.value = 'select_product_detail'; 
     
    7871</script> 
    7972 
     73 
    8074<script type="text/javascript">//<![CDATA[ 
    81 // セレクトボックスに項目を割り当てる。 
    82 function lnSetSelect(name1, name2, id, val) { 
    83         sele1 = document.form1[name1]; 
    84         sele2 = document.form1[name2]; 
    85         lists = eval('lists' + id); 
    86         vals = eval('vals' + id); 
    87  
    88         if(sele1 && sele2) { 
    89                 index = sele1.selectedIndex; 
    90  
    91                 // セレクトボックスのクリア 
    92                 count = sele2.options.length; 
    93                 for(i = count; i >= 0; i--) { 
    94                         sele2.options[i] = null; 
     75// 規格2に選択肢を割り当てる。 
     76function fnSetClassCategories(form, classcat_id2_selected) { 
     77    sele1 = form.classcategory_id1; 
     78    sele2 = form.classcategory_id2; 
     79    product_id = form.product_id.value; 
     80 
     81    if (sele1) { 
     82        if (sele2) { 
     83            // 規格2の選択肢をクリア 
     84            count = sele2.options.length; 
     85            for(i = count; i >= 0; i--) { 
     86                sele2.options[i] = null; 
     87            } 
     88 
     89            // 規格2に選択肢を割り当てる 
     90            classcats = productsClassCategories[product_id][sele1.value]; 
     91            i = 0; 
     92            for (var classcat_id2_key in classcats) { 
     93                sele2.options[i] = new Option(classcats[classcat_id2_key].name, classcat_id2_key); 
     94                if (classcat_id2_key == classcat_id2_selected) { 
     95                    sele2.options[i].selected = true; 
    9596                } 
    96  
    97                 // セレクトボックスに値を割り当てる 
    98                 len = lists[index].length; 
    99                 for(i = 0; i < len; i++) { 
    100                         sele2.options[i] = new Option(lists[index][i], vals[index][i]); 
    101                         if(val != "" && vals[index][i] == val) { 
    102                                 sele2.options[i].selected = true; 
    103                         } 
    104                 } 
     97                i++; 
     98            } 
    10599        } 
     100        fnCheckStock(form); 
     101    } 
    106102} 
    107 //]]> 
    108 </script> 
    109  
    110  
    111 <script type="text/javascript">//<![CDATA[ 
    112     <!--{$tpl_javascript}--> 
     103 
     104function fnCheckStock(form) { 
     105    product_id = form.product_id.value; 
     106    classcat_id1 = form.classcategory_id1.value; 
     107    classcat_id2 = form.classcategory_id2 ? form.classcategory_id2.value : 0; 
     108    classcat2 = productsClassCategories[product_id][classcat_id1][classcat_id2]; 
     109    // 商品規格 
     110    eleDynamic = document.getElementById('product_class_id' + product_id); 
     111    if ( 
     112           classcat2 
     113        && typeof classcat2.product_class_id != 'undefined' 
     114        && String(classcat2.product_class_id).length >= 1 
     115    ) { 
     116        eleDynamic.value = classcat2.product_class_id; 
     117    } else { 
     118        eleDynamic.value = '' 
     119    } 
     120} 
    113121//]]> 
    114122</script> 
     
    142150  <button type="submit"><span>検索を開始</span></button> 
    143151</div> 
    144  
     152</form> 
    145153<!--▼検索結果表示--> 
    146154<!--{if $tpl_linemax}--> 
     
    160168  <!--{section name=cnt loop=$arrProducts}--> 
    161169  <!--{assign var=id value=$arrProducts[cnt].product_id}--> 
     170  <form name="product_form<!--{$id|escape}-->" action="?" onsubmit="return false;"> 
    162171  <!--▼商品<!--{$smarty.section.cnt.iteration}-->--> 
    163172  <tr> 
     
    183192      <dt><!--{$tpl_class_name1[$id]|escape}-->:</dt> 
    184193      <dd> 
    185         <select name="<!--{$class1}-->" id="<!--{$class1}-->" style="<!--{$arrErr[$class1]|sfGetErrorColor}-->"  <!--{if $tpl_classcat_find2[$id]}--> onchange="lnSetSelect('<!--{$class1}-->', '<!--{$class2}-->', '<!--{$id}-->','');"<!--{/if}-->> 
    186           <option value="">選択してください</option> 
     194        <select name="classcategory_id1" id="<!--{$class1}-->" style="<!--{$arrErr[$class1]|sfGetErrorColor}-->"  onchange="fnSetClassCategories(this.form);"> 
    187195          <!--{html_options options=$arrClassCat1[$id] selected=$arrForm[$class1]}--> 
    188196        </select> 
     
    197205      <dt><!--{$tpl_class_name2[$id]|escape}-->:</dt> 
    198206      <dd> 
    199         <select name="<!--{$class2}-->" id="<!--{$class2}-->" style="<!--{$arrErr[$class2]|sfGetErrorColor}-->"> 
    200           <option value="">選択してください</option> 
    201         </select> 
     207        <select name="classcategory_id2" id="<!--{$class2}-->" style="<!--{$arrErr[$class2]|sfGetErrorColor}-->" onchange="fnCheckStock(this.form);"></select> 
    202208        <!--{if $arrErr[$class2] != ""}--> 
    203209        <br /><span class="attention">※ <!--{$tpl_class_name2[$id]}-->を入力して下さい。</span> 
     
    207213      <input type="hidden" name="<!--{$class2}-->" id="<!--{$class2}-->" value="" /> 
    208214      <!--{/if}--> 
     215      <input type="hidden" name="product_id" value="<!--{$id|escape}-->" /> 
     216      <input type="hidden" name="product_class_id<!--{$id|escape}-->" id="product_class_id<!--{$id|escape}-->" value="<!--{$tpl_product_class_id[$id]}-->" /> 
     217      <input type="hidden" name="product_type" id="product_type<!--{$id|escape}-->" value="<!--{$tpl_product_type[$id]}-->" /> 
    209218    </td> 
    210     <td class="center"><a href="" onclick="return func_submit('<!--{$arrProducts[cnt].product_id}-->', '<!--{$tpl_class_name1[$id]}-->', '<!--{$tpl_class_name2[$id]}-->')">決定</a></td> 
     219    <td class="center"><a href="javascript:;" onclick="return func_submit('<!--{$arrProducts[cnt].product_id}-->', '<!--{$tpl_class_name1[$id]}-->', '<!--{$tpl_class_name2[$id]}-->', '<!--{$tpl_product_class_id[$id]}-->')">決定</a></td> 
    211220  </tr> 
    212221  <!--▲商品<!--{$smarty.section.cnt.iteration}-->--> 
     222</form> 
    213223  <!--{sectionelse}--> 
    214224  <tr> 
     
    220230<!--▲検索結果表示--> 
    221231 
    222 </form> 
    223232 
    224233<!--{include file="`$smarty.const.TEMPLATE_ADMIN_DIR`admin_popup_footer.tpl"}--> 
  • branches/version-2_5-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php

    r18872 r18875  
    214214            // POST情報で上書き 
    215215            $this->objFormParam->setParam($_POST); 
    216             if (!empty($_POST['add_product_id'])) { 
    217                 $this->lfInsertProduct($_POST['add_product_id'], $_POST['add_classcategory_id1'], $_POST['add_classcategory_id2']); 
    218             } elseif (!empty($_POST['edit_product_id'])) { 
    219                 $this->lfUpdateProduct($_POST['edit_product_id'], $_POST['edit_classcategory_id1'], $_POST['edit_classcategory_id2'], $_POST['no']); 
     216            if (!empty($_POST['add_product_class_id'])) { 
     217                $this->lfInsertProduct($_POST['add_product_class_id']); 
     218            } elseif (!empty($_POST['edit_product_class_id'])) { 
     219                $this->lfUpdateProduct($_POST['edit_product_class_id'], $_POST['no']); 
    220220            } 
    221221            $arrData = $_POST; 
     
    695695    } 
    696696 
    697     function lfInsertProduct($product_id, $classcategory_id1, $classcategory_id2) { 
    698         $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2); 
     697    function lfInsertProduct($product_class_id) { 
     698        $objProduct = new SC_Product(); 
     699        $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id)); 
    699700        $this->arrForm = $this->objFormParam->getFormParamList(); 
    700701        $existes = false; 
     
    704705            foreach ($this->arrForm['product_class_id']['value'] AS $key=>$val) { 
    705706                // 既に同じ商品がある場合 
    706                 if ($val == $product_id && $this->arrForm['product_id']['classcategory_id1'][$key] == $classcategory_id1 && $this->arrForm['product_id']['classcategory_id2'][$key] == $classcategory_id2) { 
     707                if ($val == $product_class_id) { 
    707708                    $existes = true; 
    708709                    $existes_key = $key; 
     
    720721    } 
    721722 
    722     function lfUpdateProduct($product_id, $classcategory_id1, $classcategory_id2, $no) { 
    723         $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2); 
     723    function lfUpdateProduct($product_class_id, $no) { 
     724        $objProduct = new SC_Product(); 
     725        $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id)); 
    724726        $this->arrForm = $this->objFormParam->getFormParamList(); 
    725727        $this->lfSetProductData($arrProduct, $no); 
     
    732734            } 
    733735            if ($no === null) { 
    734                 $this->arrForm[$key]['value'][] = $arrProduct[$key]; 
     736                $this->arrForm[$key]['value'][] = $val; 
    735737            } else { 
    736                 $this->arrForm[$key]['value'][$no] = $arrProduct[$key]; 
    737             } 
    738         } 
    739     } 
    740  
    741     function lfGetProductsClass($product_class_id) { 
    742         $objDb = new SC_Helper_DB_Ex(); 
    743         $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); 
    744         $arrRet = $objDb->sfGetProductsClass(array($product_class_id), true); 
    745  
    746         $arrProduct['price'] = $arrRet['price02']; 
     738                $this->arrForm[$key]['value'][$no] = $val; 
     739            } 
     740        } 
     741    } 
     742 
     743    function lfGetProductsClass($productsClass) { 
     744        $arrProduct['price'] = $productsClass['price02']; 
    747745        $arrProduct['quantity'] = 1; 
    748         $arrProduct['product_id'] = $arrRet['product_id']; 
    749         $arrProduct['product_class_id'] = $arrRet['product_class_id']; 
    750         $arrProduct['point_rate'] = $arrRet['point_rate']; 
    751         $arrProduct['product_code'] = $arrRet['product_code']; 
    752         $arrProduct['product_name'] = $arrRet['name']; 
    753         $arrProduct['classcategory_name1'] = $arrClassCatName[$arrRet['classcategory_id1']]; 
    754         $arrProduct['classcategory_name2'] = $arrClassCatName[$arrRet['classcategory_id2']]; 
     746        $arrProduct['product_id'] = $productsClass['product_id']; 
     747        $arrProduct['product_class_id'] = $productsClass['product_class_id']; 
     748        $arrProduct['point_rate'] = $productsClass['point_rate']; 
     749        $arrProduct['product_code'] = $productsClass['product_code']; 
     750        $arrProduct['product_name'] = $productsClass['name']; 
     751        $arrProduct['classcategory_name1'] = $productsClass['classcategory_name1']; 
     752        $arrProduct['classcategory_name2'] = $productsClass['classcategory_name2']; 
    755753 
    756754        return $arrProduct; 
    757755    } 
     756 
    758757 
    759758    /** 
  • branches/version-2_5-dev/data/class/pages/admin/order/LC_Page_Admin_Order_ProductSelect.php

    r18872 r18875  
    2525// {{{ requires 
    2626require_once(CLASS_PATH . "pages/LC_Page.php"); 
     27require_once(DATA_PATH . 'module/Services/JSON.php'); 
    2728 
    2829/** 
     
    111112            } 
    112113 
    113             /* 
    114              * FIXME パフォーマンスに問題があるため SC_Product::lists() を使用する 
    115              */ 
    116114            $objProduct = new SC_Product(); 
    117115            $productIds = $objProduct->findProductIds($objQuery, $arrval); 
     
    142140            $this->arrProducts = $objProduct->lists($objQuery, $arrval); 
    143141            $objProduct->setProductsClassByProductIds($productIds); 
     142            $objJson = new Services_JSON(); 
     143            $this->tpl_javascript .= 'productsClassCategories = ' . $objJson->encode($objProduct->classCategories) . '; '; 
     144 
     145            foreach ($this->arrProducts as $arrProduct) { 
     146                $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});\n"; 
     147            } 
     148 
     149            $this->tpl_javascript .= 'function fnOnLoad(){' . $js_fnOnLoad . '}'; 
     150            $this->tpl_onload .= 'fnOnLoad(); '; 
     151 
    144152            // 規格1クラス名 
    145153            $this->tpl_class_name1 = $objProduct->className1; 
     
    155163            // 規格2が設定されている 
    156164            $this->tpl_classcat_find2 = $objProduct->classCat2_find; 
    157  
     165            $this->tpl_product_class_id = $objProduct->product_class_id; 
    158166            $this->tpl_stock_find = $objProduct->stock_find; 
    159             $this->tpl_product_class_id = $objProduct->product_class_id; 
    160             $this->tpl_product_type = $objProduct->product_type; 
    161  
    162             // FIXME 規格のプルダウンを要修正 
    163             $this->tpl_javascript = ""; 
    164167        } 
    165168 
     
    201204        } 
    202205    } 
    203  
    204     // FIXME SC_Product クラスを使用する 
    205     /* 規格セレクトボックスの作成 */ 
    206     function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) { 
    207  
    208         $classcat_find1 = false; 
    209         $classcat_find2 = false; 
    210         // 在庫ありの商品の有無 
    211         $stock_find = false; 
    212  
    213         // 商品規格情報の取得 
    214         $arrProductsClass = $this->lfGetProductsClass($product_id); 
    215  
    216         // 規格1クラス名の取得 
    217         $this->tpl_class_name1[$product_id] = 
    218             isset($arrClassName[$arrProductsClass[0]['class_id1']]) 
    219             ? $arrClassName[$arrProductsClass[0]['class_id1']] 
    220             : ""; 
    221  
    222         // 規格2クラス名の取得 
    223         $this->tpl_class_name2[$product_id] = 
    224             isset($arrClassName[$arrProductsClass[0]['class_id2']]) 
    225             ? $arrClassName[$arrProductsClass[0]['class_id2']] 
    226             : ""; 
    227  
    228         // すべての組み合わせ数 
    229         $count = count($arrProductsClass); 
    230  
    231         $classcat_id1 = ""; 
    232  
    233         $arrSele = array(); 
    234         $arrList = array(); 
    235  
    236         $list_id = 0; 
    237         $arrList[0] = "\tlist". $product_id. "_0 = new Array('選択してください'"; 
    238         $arrVal[0] = "\tval". $product_id. "_0 = new Array(''"; 
    239  
    240         for ($i = 0; $i < $count; $i++) { 
    241             // 在庫のチェック 
    242             if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') { 
    243                 continue; 
    244             } 
    245  
    246             $stock_find = true; 
    247  
    248             // 規格1のセレクトボックス用 
    249             if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){ 
    250                 $arrList[$list_id].=");\n"; 
    251                 $arrVal[$list_id].=");\n"; 
    252                 $classcat_id1 = $arrProductsClass[$i]['classcategory_id1']; 
    253                 $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1]; 
    254                 $list_id++; 
    255  
    256                 $arrList[$list_id] = ""; 
    257                 $arrVal[$list_id] = ""; 
    258             } 
    259  
    260             // 規格2のセレクトボックス用 
    261             $classcat_id2 = $arrProductsClass[$i]['classcategory_id2']; 
    262  
    263             // セレクトボックス表示値 
    264             if($arrList[$list_id] == "") { 
    265                 $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('選択してください', '". $arrClassCatName[$classcat_id2]. "'"; 
    266             } else { 
    267                 $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'"; 
    268             } 
    269  
    270             // セレクトボックスPOST値 
    271             if($arrVal[$list_id] == "") { 
    272                 $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'"; 
    273             } else { 
    274                 $arrVal[$list_id].= ", '".$classcat_id2."'"; 
    275             } 
    276         } 
    277  
    278         $arrList[$list_id].=");\n"; 
    279         $arrVal[$list_id].=");\n"; 
    280  
    281         // 規格1 
    282         $this->arrClassCat1[$product_id] = $arrSele; 
    283  
    284         $lists = "\tlists".$product_id. " = new Array("; 
    285         $no = 0; 
    286         foreach($arrList as $val) { 
    287             $this->tpl_javascript.= $val; 
    288             if ($no != 0) { 
    289                 $lists.= ",list". $product_id. "_". $no; 
    290             } else { 
    291                 $lists.= "list". $product_id. "_". $no; 
    292             } 
    293             $no++; 
    294         } 
    295         $this->tpl_javascript.= $lists.");\n"; 
    296  
    297         $vals = "\tvals".$product_id. " = new Array("; 
    298         $no = 0; 
    299         foreach($arrVal as $val) { 
    300             $this->tpl_javascript.= $val; 
    301             if ($no != 0) { 
    302                 $vals.= ",val". $product_id. "_". $no; 
    303             } else { 
    304                 $vals.= "val". $product_id. "_". $no; 
    305             } 
    306             $no++; 
    307         } 
    308         $this->tpl_javascript.= $vals.");\n"; 
    309  
    310         // 選択されている規格2ID 
    311         $classcategory_id = "classcategory_id". $product_id; 
    312  
    313         $classcategory_id_2 = $classcategory_id . "_2"; 
    314         if (!isset($classcategory_id_2)) $classcategory_id_2 = ""; 
    315         if (!isset($_POST[$classcategory_id_2])) $_POST[$classcategory_id_2] = ""; 
    316  
    317         $this->tpl_onload .= "lnSetSelect('" . $classcategory_id ."_1', " 
    318             . "'" . $classcategory_id_2 . "'," 
    319             . "'" . $product_id . "'," 
    320             . "'" . $_POST[$classcategory_id_2] ."'); "; 
    321  
    322         // 規格1が設定されている 
    323         if($arrProductsClass[0]['classcategory_id1'] != '0') { 
    324             $classcat_find1 = true; 
    325         } 
    326  
    327         // 規格2が設定されている 
    328         if($arrProductsClass[0]['classcategory_id2'] != '0') { 
    329             $classcat_find2 = true; 
    330         } 
    331  
    332         $this->tpl_classcat_find1[$product_id] = $classcat_find1; 
    333         $this->tpl_classcat_find2[$product_id] = $classcat_find2; 
    334         $this->tpl_stock_find[$product_id] = $stock_find; 
    335     } 
    336  
    337     /* 商品規格情報の取得 */ 
    338     function lfGetProductsClass($product_id) { 
    339         $arrRet = array(); 
    340         if(SC_Utils_Ex::sfIsInt($product_id)) { 
    341             // 商品規格取得 
    342             $objQuery = new SC_Query(); 
    343             $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited"; 
    344             $table = "vw_product_class AS prdcls"; 
    345             $where = "product_id = ?"; 
    346             $objQuery->setOrder("rank1 DESC, rank2 DESC"); 
    347             $arrRet = $objQuery->select($col, $table, $where, array($product_id)); 
    348         } 
    349         return $arrRet; 
    350     } 
    351206} 
    352207?> 
Note: See TracChangeset for help on using the changeset viewer.