前一次的方法果然行不通
想一想老闆的要求是配套的選擇性商品都單一價錢
所以這次我把「セット組み合わせ」這一個規格改成0 1 2 3…代表搭配的數目
然後再加上一個oneprice的欄位當單價
然後新增一個setdetail.php的php檔
- 在\data\class_extends\page_extends\products\ 複製LC_Page_Products_Detail_Ex.php ->LC_Page_Products_SetDetail_Ex.php
- 在\data\class\pages\products\ 複製LC_Page_Products_Detail.php ->LC_Page_Products_SetDetail.php
- 在\html\user_data\packages\mystyle\ 複製detail.tpl ->setdetail.tpl
當然還有些小地方要改(如果要用cleanURL的話當然.htaccess也要動一下)
接下來我預設最多只能搭配4個單品(重複與沒重複的總數量)
多一件單品的折扣也先寫死(其實價格在輸入規格時就決定了這邊只是給使用者玩爽的^^”)
單品的種類則是從「推薦商品」讀過來
將子可以少寫另一個關連的db(而且搭配的單品放在推薦也很合理吧)
另外多加了兩個要送到購物車的參數:配套明細pstext(寫入db)setnum(判斷目前session中有沒有相同的套餐)
setdetail.tpl中主要加了一點code:
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | <script language="JavaScript"> <!-- arrcamara = new Array(<!--{section name=cnt loop=$arrRecommend}--><!--{if $arrRecommend[cnt].product_id}--><!--{$arrRecommend[cnt].product_id}-->,<!--{/if}--><!--{/section}-->0); id_arrcamara = new Array(<!--{section name=cnt loop=$arrRecommend}--><!--{if $arrRecommend[cnt].product_id}-->"<!--{$arrRecommend[cnt].product_code_min}-->",<!--{/if}--><!--{/section}-->0); setkumiarr_id = new Array(<!--{foreach key=key item=index from=$arrClassCat1}-->"<!--{$key}-->",<!--{/foreach}-->0); setkumiarr_num = new Array(<!--{foreach key=key item=index from=$arrClassCat1}-->"<!--{$index}-->",<!--{/foreach}-->0); waribikiarr = new Array(0,0.03,0.04,0.05,0.06); var basicPrice = <!--{$arrPriceCat[**]}-->;//基價 var onePrice = <!--{$arrPriceCat[**]}-->;//單價 function moption(i,s){ var tmp1 =new Array();//(商品編號,數量) var tmp2 =0;//總價 var tmp3 =0;//總數量 var m=s[s.selectedIndex].value;//各價 var n=s[s.selectedIndex].label;//各數量 eval("document.getElementById(\"PRICE_" + arrcamara[i] +"\").innerTEXT = '"+ n*m + "'"); eval("document.getElementById(\"NUM_" + arrcamara[i] +"\").innerTEXT = '"+ n + "'"); for(var j=0;j<arrcamara.length-1;j++){ eval("var tmpNUM = document.getElementById(\"NUM_" + arrcamara[j] +"\").innerTEXT"); if (tmpNUM==null) tmpNUM=0; tmp1.push(new Array(id_arrcamara[j],tmpNUM)); tmp3 += eval(tmpNUM);//總數量 eval("var tmpPRICE = document.getElementById(\"PRICE_" + arrcamara[j] +"\").innerTEXT"); if (tmpPRICE==null) tmpPRICE=0; tmp2 += eval(tmpPRICE); } if(tmp3<=4){ tmp4 = basicPrice+tmp2*(1-waribikiarr[tmp3]); checkset(tmp3,tmp1); eval("document.getElementById(\"TOTAL_Price\").innerHTML = '" + tmp4 + "'"); }else{ alert(" カメラ数をオーバーしています。\n再選択して下さい。"); for(var i=0;i<setkumiarr_id.length-1;i++){ eval("document.form2.set_id" + arrcamara[i] + ".selectedIndex = '" + 0 + "'"); eval("document.getElementById(\"PRICE_" + arrcamara[i] +"\").innerTEXT = '"+ 0 + "'"); eval("document.getElementById(\"NUM_" + arrcamara[i] +"\").innerTEXT = '"+ 0 + "'"); eval("document.getElementById(\"TOTAL_Price\").innerHTML = '" + basicPrice + "'"); } } } function checkset(t,arr){ var strtmp = ""; var numtmp = ""; for(var j=0;j<arr.length;j++){ numtmp += arr[j][1]; if(arr[j][1]!=0){ strtmp += arr[j][0]; strtmp += ":"; strtmp += arr[j][1]; strtmp += "台, "; } } form1.pstext.value = strtmp; form1.setnum.value = numtmp; for(var i=0;i<setkumiarr_id.length-1;i++){ if(setkumiarr_num[i] == t){ form1.classcategory_id1.value = setkumiarr_id[i]; } } } |
209 210 211 212 213 214 215 216 217 218 219 | <form name="form1" id="form1" method="post" action="<!--{$smarty.server.REQUEST_URI|escape}-->"> <input type="hidden" name="mode" value="cart" /> <input type="hidden" name="product_id" value="<!--{$tpl_product_id}-->" /> <input type="hidden" name="classcategory_id1" value="0" /> <input type="hidden" name="pstext" value="" /> <input type="hidden" name="setnum" value="" /> <!--{if $tpl_stock_find}--> <!--★カゴに入れる★--> <div class="detailbtn"> <div class="subdetailbtn" style="width:85px;">個数 <input type="text" name="quantity" class="box54" value="<!--{$arrForm.quantity.value|default:1}-->" maxlength="<!--{$smarty.const.INT_LEN}-->" style="<!--{$arrErr.quantity|sfGetErrorColor}-->" /> |
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | <div class="listareaset"> <table bgcolor="#8ab8cf" border="0" cellpadding="4" cellspacing="1" width="100%" style="margin-bottom:10px;"> <tr bgcolor="#ddebf0"> <td class="wtdn" align="center">1台</td> <td class="wtdn" align="center">2台</td> <td class="wtdn" align="center">3台</td> <td class="wtdn" align="center">4台</td> </tr> <tr bgcolor="#ffffff"> <td class="wtdw" align="center">3.0%割引</td> <td class="wtdw" align="center">4.0%割引</td> <td class="wtdw" align="center">5.0%割引</td> <td class="wtdw" align="center">6.0%割引</td> </tr> </table> <form name="form2" id="form2" method="post" action=""> <!--{section name=cnt loop=$arrRecommend}--> <!--{if $arrRecommend[cnt].product_id}--> <div class="listareasetsub"> <div class="listareasetsub_title"> <a href="/onlineshop/products/detail/<!--{$arrRecommend[cnt].product_id}-->"> <!--{$arrRecommend[cnt].name|escape}--> </a> </div> <div class="listphotoset"> <!--{if $arrRecommend[cnt].main_list_image != ""}--> <!--{assign var=image_path value="`$arrRecommend[cnt].main_list_image`"}--> <!--{else}--> <!--{assign var=image_path value="`$smarty.const.NO_IMAGE_DIR`"}--> <!--{/if}--> <a href="/onlineshop/products/detail/<!--{$arrRecommend[cnt].product_id}-->" class="over"> <img src="<!--{$smarty.const.SITE_URL}-->resize_image.php?image=<!--{$image_path|sfRmDupSlash}-->&width=65&height=65" alt="<!--{$arrRecommend[cnt].name|escape}-->" /></a></div> <div id="pro_codes">製品型番: <div id="pro_codes"> <!--{$arrRecommend[cnt].product_code_min}--> </div> </div> <div id="nowprice_lit"> <span class="pricebox"> 販売価格 <span class="mini">(税込)</span>:<br /> <span class="price"> <!--{$arrPriceCat[40]|number_format}--> 円</span></span></div> <font id="PRICE_<!--{$arrRecommend[cnt].product_id}-->"></font> <font id="NUM_<!--{$arrRecommend[cnt].product_id}-->"></font> <div class="to">個数: <select id="set_id<!--{$arrRecommend[cnt].product_id}-->" name="set_id<!--{$arrRecommend[cnt].product_id}-->" onchange="moption(<!--{$smarty.section.cnt.index}-->,this)"> <option value="<!--{$arrPriceCat[40]}-->" label="0">数量選択</option> <option value="<!--{$arrPriceCat[40]}-->" label="1">1</option> <option value="<!--{$arrPriceCat[40]}-->" label="2">2</option> <option value="<!--{$arrPriceCat[40]}-->" label="3">3</option> <option value="<!--{$arrPriceCat[40]}-->" label="4">4</option> <option value="<!--{$arrPriceCat[40]}-->" label="5">5</option> <option value="<!--{$arrPriceCat[40]}-->" label="6">6</option> <option value="<!--{$arrPriceCat[40]}-->" label="7">7</option> <option value="<!--{$arrPriceCat[40]}-->" label="8">8</option> </select> </div> </div> <!--{/if}--> <!--{/section}--> </form> </div> |
\data\class\pages\products\LC_Page_Products_SetDetail.php在process()跟mobileProcess()都加入
不過老闆其實不希望可以用手機購買啦
所以mobileProcess()可以省略….
155 | $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $this->objFormParam->getValue('quantity'),"",$_POST['pstext'], $_POST['setnum']); |
\data\class\SC_CartSession.php的addProduct()改成:
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | // カートへの商品追加 function addProduct($id, $quantity, $campaign_id = "", $pstext = "", $setnum = "") { $find = false; $max = $this->getMax(); for($i = 0; $i <= $max; $i++) { if($_SESSION[$this->key][$i]['id'] == $id && $_SESSION[$this->key][$i]['setnum'] == $setnum) { $val = $_SESSION[$this->key][$i]['quantity'] + $quantity; if(strlen($val) <= INT_LEN) { $_SESSION[$this->key][$i]['quantity']+= $quantity; if(!empty($campaign_id)){ $_SESSION[$this->key][$i]['campaign_id'] = $campaign_id; $_SESSION[$this->key][$i]['is_campaign'] = true; } } $find = true; } } if(!$find) { $_SESSION[$this->key][$max+1]['id'] = $id; $_SESSION[$this->key][$max+1]['quantity'] = $quantity; $_SESSION[$this->key][$max+1]['pstext'] = $pstext; $_SESSION[$this->key][$max+1]['setnum'] = $setnum; $_SESSION[$this->key][$max+1]['cart_no'] = $this->getNextCartID(); if(!empty($campaign_id)){ $_SESSION[$this->key][$max+1]['campaign_id'] = $campaign_id; $_SESSION[$this->key][$max+1]['is_campaign'] = true; } } } |
\data\class\helper\SC_Helper_DB.php加入:
337 | $objPage->arrProductsClass[$cnt]['pstext'] = $arrCart[$i]['pstext']; |
\data\Smarty\templates\mystyle\cart\index.tpl加入:
84 85 86 | <!--{if $arrProductsClass[cnt].pstext != ""}--> SET:<!--{$arrProductsClass[cnt].pstext}--> <!--{/if}--> |
\data\Smarty\templates\mystyle\shopping\confirm.tpl加入:
73 74 75 | <!--{if $arrProductsClass[cnt].pstext != ""}--> SET:<!--{$arrProductsClass[cnt].pstext}--> <!--{/if}--> |
然後在mySQL中的dtb_order_detail加一個欄位pstext
最後在\data\class\pages\shopping\LC_Page_Shopping_Complete.php加入:
513 | $sqlval['pstext'] = $arrCart[$i]['pstext']; |
目前就是可以安安穩穩的放入購物車了
再來還有些顯示上的後續
動到了再說吧…..