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

LINEで送る
[`evernote` not found]

因為不同的規格有不同的價錢
如果不放的話實在很不親切
首先知道有兩張頁面有這東東:
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'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
                continue;
            }
 
            $stock_find = true;
 
            // 規格1のセレクトボックス用
            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
                $arrList[$list_id].=");\n";
                $arrVal[$list_id].=");\n";
                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
                $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
		//ブラス値段
		$arrPrice[$classcat_id1] = $arrProductsClass[$i]['price02'];
                $list_id++;
 
                $arrList[$list_id] = "";
                $arrVal[$list_id] = "";
            }
 
            // 規格2のセレクトボックス用
            $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
 
            // セレクトボックス表示値
            if($arrList[$list_id] == "") {
                $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('選択してください', '". $arrClassCatName[$classcat_id2]. "'";
            } else {
                $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
            }
 
            // セレクトボックスPOST値
            if($arrVal[$list_id] == "") {
                $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'";
            } else {
                $arrVal[$list_id].= ", '".$classcat_id2."'";
            }
        }
 
        $arrList[$list_id].=");\n";
        $arrVal[$list_id].=");\n";
 
        // 規格1
        $this->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'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
                continue;
            }
 
            $stock_find = true;
 
            // 規格1のセレクトボックス用
            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
                $arrList[$list_id].=");\n";
                $arrVal[$list_id].=");\n";
                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
                $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
		//ブラス値段
		$arrPrice[$classcat_id1] = $arrProductsClass[$i]['price02'];
                $list_id++;
            }
 
            // 規格2のセレクトボックス用
            $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
 
            // セレクトボックス表示値
            if (!isset($arrList[$list_id])) $arrList[$list_id] = "";
            if($arrList[$list_id] == "") {
                $arrList[$list_id] = "\tlist".$list_id." = new Array('選択してください', '".$arrClassCatName[$classcat_id2]."'";
            } else {
                $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
            }
 
            // セレクトボックスPOST値
            if (!isset($arrVal[$list_id])) $arrVal[$list_id] = "";
            if($arrVal[$list_id] == "") {
                $arrVal[$list_id] = "\tval".$list_id." = new Array('', '".$classcat_id2."'";
            } else {
                $arrVal[$list_id].= ", '".$classcat_id2."'";
            }
        }
 
        $arrList[$list_id].=");\n";
        $arrVal[$list_id].=");\n";
 
        // 規格1
        $this->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:

 <!--{html_options options=$arrClassCat1 selected=$arrForm.classcategory_id1.value price=$arrPriceCat}-->

list.tpl:

<!--{html_options options=$arrClassCat1[$id] selected=$arrForm[$class1] price=$arrPriceCat[$id]}-->

最後\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 = '<select name="' . $name . '"' . $extra . '>' . "\n" . $_html_result . '</select>' . "\n";
    }
 
    return $_html_result;

後面輸出用的函式變成:

function smarty_function_html_options_optoutput($key, $value, $selected,$level,$price) {
    if(!is_array($value)) {
		if($price > 0){
       		 $_html_result = '<option label="' . smarty_function_escape_special_chars($value) . '-- &yen;' . $price . '"value="' .
          	  smarty_function_escape_special_chars($key) . '"';
		}else{
			$_html_result = '<option label="' . smarty_function_escape_special_chars($value) . '" value="' .
           	smarty_function_escape_special_chars($key) . '"';
		}
        if (in_array((string)$key, $selected))
            $_html_result .= ' selected="selected"';
		if ($level)
		$_html_result .= ' class="level'.$level. '"';
        $_html_result .= '>' . smarty_function_escape_special_chars($value) . '</option>' . "\n";
    } else {
        $_html_result = smarty_function_html_options_optgroup($key, $value, $selected,$level[$_key],$price);
    }
    return $_html_result;
}
 
function smarty_function_html_options_optgroup($key, $values, $selected,$level,$price) {
    $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n";
    foreach ($values as $key => $value) {
        $optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected,$level[$_key],$price);
    }
    $optgroup_html .= "</optgroup>\n";
    return $optgroup_html;
}