# 在ec-cube的規格select中加上價錢

- URL: https://justfly.idv.tw/%e5%9c%a8ec-cube%e7%9a%84%e8%a6%8f%e6%a0%bcselect%e4%b8%ad%e5%8a%a0%e4%b8%8a%e5%83%b9%e9%8c%a2/
- 日期: 2008-09-03
- 分類: WEB&amp;RIA
- 標籤: ec-cube, php, select

因為不同的規格有不同的價錢

如果不放的話實在很不親切

首先知道有兩張頁面有這東東:

list.php

detail.php

分別是對應到:

\data\class\pages\LC_Page_Products_List.php+\html\user_data\packages\mystyle\list.tpl

\data\class\pages\LC_Page_Products_Detail.php+\html\user_data\packages\mystyle\detail.tpl

再加上輸出用的:

\data\module\Smarty\libs\plugins\function.html_options.php

一共要改5張

\data\class\pages\LC_Page_Products_List.php的function lfMakeSelect():

 只改加了//ブラス値段的地方

```
$arrSele = array();
        $arrList = array();
	//ブラス値段
	$arrPrice = array();

        $list_id = 0;
        $arrList[0] = "\tlist". $product_id. "_0 = new Array('選択してください'";
        $arrVal[0] = "\tval". $product_id. "_0 = new Array(''";

        for ($i = 0; $i < $count; $i++) {
            // 在庫のチェック
            if($arrProductsClass[$i]['stock'] arrClassCat1[$product_id] = $arrSele;
	//ブラス値段
	$this->arrPriceCat[$product_id] = $arrPrice;
.............................................................
```

function lfGetProductsClass():

 只加了price02

```
/* 商品規格情報の取得 */
    function lfGetProductsClass($product_id) {
        $arrRet = array();
        if(SC_Utils_Ex::sfIsInt($product_id)) {
            // 商品規格取得
            $objQuery = new SC_Query();
            $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited, price02";
            $table = "vw_product_class AS prdcls";
            $where = "product_id = ?";
            $objQuery->setorder("rank1 DESC, rank2 DESC");
            $arrRet = $objQuery->select($col, $table, $where, array($product_id));
        }
        return $arrRet;
    }
```

\data\class\pages\LC_Page_Products_Detail.php的function lfMakeSelect():

 只改加了//ブラス値段的地方

```
// すべての組み合わせ数
        $count = count($arrProductsClass);

        $classcat_id1 = "";

        $arrSele = array();
        $arrList = array();
	//ブラス値段
	$arrPrice = array();

        $list_id = 0;
        $arrList[0] = "\tlist0 = new Array('選択してください'";
        $arrVal[0] = "\tval0 = new Array(''";

        for ($i = 0; $i < $count; $i++) {
            // 在庫のチェック
            if($arrProductsClass[$i]['stock'] arrClassCat1 = $arrSele;
	//ブラス値段
	$this->arrPriceCat = $arrPrice;
```

function lfGetProductsClass():

 只加了price02

```
/* 商品規格情報の取得 */
    function lfGetProductsClass($product_id) {
        $arrRet = array();
        if(SC_Utils_Ex::sfIsInt($product_id)) {
            // 商品規格取得
            $objQuery = new SC_Query();
            $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited,price02";
            $table = "vw_product_class AS prdcls";
            $where = "product_id = ?";
            $objQuery->setorder("rank1 DESC, rank2 DESC");
            $arrRet = $objQuery->select($col, $table, $where, array($product_id));
        }
        return $arrRet;
    }
```

detail.tpl跟list.tpl都只改一行

detail.tpl:

```

```

list.tpl:

```

```

最後\data\module\Smarty\libs\plugins\function.html_options.php:

function smarty_function_html_options()加上:

```
case 'price': 
				$$_key = (array)$_val;
				break;
```

同一函事後免面改一下…

```
$_html_result = '';

    if (isset($options)) {
       	 foreach ($options as $_key=>$_val)
         $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected,$level[$_key],$price[$_key]);
		 
    } else {
        
        foreach ($values as $_i=>$_key) {
            $_val = isset($output[$_i]) ? $output[$_i] : '';
            $_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected,$level[$_key],$price[$_key]);
        }

    }

    if(!empty($name)) {
        $_html_result = '' . "\n" . $_html_result . '' . "\n";
    }

    return $_html_result;
```

後面輸出用的函式變成:

```
function smarty_function_html_options_optoutput($key, $value, $selected,$level,$price) {
    if(!is_array($value)) {
		if($price > 0){
       		 $_html_result = '
```
