As we all know, the price range of Ecshop is set up in the background a "price range number", and then by the program to automatically split, many Ecshop web owners think this is done, there is a lot of unsatisfactory place.
Others have provided a way to modify the method, as if it were a method of manually writing dead intervals in a template file, or could not be freely defined.
The next way I would like to talk about is that you can freely define the price range in the Ecshop background ( For example: 1-30,31-200,201-1000,1001-5000,5000 above ), the front desk automatically reflects a method, and each category of price range can be arbitrarily set, Make the price range more humane.
First, we'll modify the ECSHOP database structure to add a new field to ecs_category.
Into the background "database management" SQL query, execute the following SQL statement
ALTER TABLE 'ecs_category ' ADD ' grade_define ' VARCHAR (255) not NULL after ' grade '
Note: Here I am using the default database prefix Ecs_, if your database prefix is not ecs_, please modify it.
2),
Open/admin/templates/category_info.htm
Found it
<tr> <TD class= "label" ><a href= "Javascript:shownotice (' Noticegrade ');" title= "{$lang. Form_notice}" ></a>{$lang. Grade}: </td> <td> <input type= "text" name= "grade" value= "{$cat _info.grade|default:0}" size= "/> <br/> <span class= "Notice-span" {if $help _open}style= "Display:block" {else} style= "Display:none" {/if} id= "Noticegrade" >{$lang .notice_grade}</span> </td> </tr> |
Fix it to
<TR> &NBSP;&NBSP;&NBSP;&NBS P;&NBSP;&NBSP;&NBSP;&NBSP;<TD class= "label" > Custom price range: </td> <td> <input type= "text" name= "Grade_define" value= "{$cat _info.grade_define}" Size= "/> <br/> & Nbsp; <span class= "Notice-span" {if $help _open}style= "Display:block" {else} style= "Display:none" {/if} id= " Noticegrade "> with half-width, interval, such as: 1-30,31-200,201-1000,1001-5000,5000 above </span> & Nbsp; </td> </tr> |
3),
Then open/admin/category.php file, search
| $cat [' grade '] =!empty ($_post[' grade ')? Intval ($_post[' grade '): 0; |
Can be found in a total of two, in each place to add code (note that every place)
| $cat [' grade_define '] =!empty ($_post[' grade_define ')? Trim ($_post[' grade_define '): "; Custom price range by Zhangyh |
Here, the background Management Section has been modified.
4),
Start modifying the foreground section below
Open/category.php
Found it
if ($cat [' grade '] = = 0 && $cat [' parent_id ']! = 0) { $cat [' grade '] = Get_parent_grade ($cat _id); If the current classification level is empty, take the nearest ancestor category }
if ($cat [' Grade '] > 1) {
$sql = "Select min (g.shop_price) as Min, Max (g.shop_price) as Max". "From". $ecs->table (' goods '). "As G". "WHERE ($children OR". Get_extension_goods ($children). ') and G.is_delete = 0 and G.is_on_sale = 1 and G.is_alone_sale = 1 '; Get the maximum and minimum value of the commodity price under the current classification $row = $db->getrow ($sql); //Gets the minimum unit series for the price grade, for example, the minimum of a thousand-dollar commodity is 100 series $price _grade = 0.0001; for ($i =-2; $i <= log10 ($row [ ' Max ']); $i + +) { $price _grade *= 10; } Span $DX = Ceil (($row [' Max ']-$row [' min '])/($cat [' Grade '])/$price _grade) * $price _grade; if ($dx = = 0) { $DX = $price _grade; } for ($i = 1; $row [' min '] > $DX * $i; $i + +); for ($j = 1; $row [' min '] > $DX * ($i-1) + $price _grade * $J; $j + +); $row [' min '] = $DX * ($i-1) + $price _grade * ($j-1); for (; $row [' Max '] >= $dx * $i; $i + +); $row [' max '] = $DX * ($i) + $price _grade * ($j-1); $sql = "Select (Floor ((g.shop_price-$row [min])/$DX) as SN, COUNT (*) as Goods_num". "From". $ecs->table (' goods '). "As G". "WHERE ($children OR". Get_extension_goods ($children). ') and G.is_delete = 0 and G.is_on_sale = 1 and G.is_alone_sale = 1 '. "GROUP by SN"; $price _grade = $db->getall ($sql); foreach ($price _grade as $key = $val) { $temp _key = $key + 1; $price _grade[$temp _key][' goods_num ') = $val [' Goods_num ']; $price _grade[$temp _key][' start '] = $row [' min '] + round ($DX * $val [' SN ']); $price _grade[$temp _key][' End ' = $row [' min '] + round ($DX * ($val [' SN '] + 1)); $price _grade[$temp _key][' price_range ') = $price _grade[$temp _key][' start ']. ' - '. $price _grade[$temp _key][' End '; $price _grade[$temp _key][' formated_start ') = Price_format ($price _grade[$temp _key][' start '); $price _grade[$temp _key][' formated_end ') = Price_format ($price _grade[$temp _key][' end '); $price _grade[$temp _key][' url '] = Build_uri (' category ', Array (' cid ' = $cat _id, ' bid ' = = $brand, ' price_min ' =>$ price_grade[$temp _key][' start '], ' price_max ' = $price _grade[$temp _key][' End ', ' filter_attr ' = $filter _attr_ STR), $cat [' cat_name ']); if (Isset ($_request[' price_min ') && $price _grade[$temp _key][' start '] = = $price _min && $price _grade[$ temp_key][' end '] = = $price _max) { $price _grade[$temp _key][' selected ') = 1; } Else { $price _grade[$temp _key][' selected ') = 0; } }
$price _grade[0][' start '] = 0; $price _grade[0][' End ' = 0; $price _grade[0][' price_range '] = $_lang[' All_attribute ']; $price _grade[0][' url '] = Build_uri (' category ', Array (' cid ' = $cat _id, ' bid ' = $brand, ' price_min ' =>0, ' Price_ Max ' = 0, ' filter_attr ' = $filter _attr_str), $cat [' cat_name ']); $price _grade[0][' selected ' = Empty ($price _max)? 1:0; $smarty->assign (' Price_grade ', $price _grade); } |
Replace it with the
if ($cat [' grade_define ']) { $price _grade=array (); $price _grade[0][' start '] = 0; $price _grade[0][' end ' = 0; $price _grade[0][' price_range '] = $_lang[' All_attribute ‘]; $price _grade[0][' url '] = Build_uri (' category ', Array (' CID ' = $cat _id, ' bid ' and $brand, ' price_min ' =>0, ' price _max ' + 0, ' filter_attr ' = $filter _attr_str), $cat [' cat_name ']); $price _grade[0][' selected '] = Empty ($price _max)? 1:0; $grade _temp=explode (",", $cat [' grade_define ']); foreach ($grade _temp as $grade _temp_key=> $grade _temp_val) { $grade _temp_key2= $grade _temp_key+1; $grade _temp=explode ("-", $grade _temp_val); $price _grade[$grade _temp_key2][' start ']=intval ($grade _temp[0]); $price _grade[$grade _temp_key2][' End ']= $grade _temp[1]? Intval ($grade _temp[1]): "999999999"; $price _grade[$grade _temp_key2][' price_range ') = $grade _temp_val; $price _grade[$grade _temp_key2][' url '] = Build_uri (' category ', Array (' cid ' = $cat _id, ' Bid ' and $brand, ' price_min ' + $price _grade[$grade _temp_key2][' start ', ' Price_max ' = $price _grade[$grade _temp_key2][' End '), ' Filter_attr ' = $filter _attr_str), $cat [' cat_name ']);
if (Isset ($_request[' price_min ')) && $price _grade[$grade _temp_key2][' start '] = = $price _min && $price _grade[$grade _temp_key2][' end '] = = $price _max) { $price _grade[$grade _temp_key2][' selected ') = 1; } Else { $price _grade[$grade _temp_key2][' selected ') = 0; } } $smarty->assign (' Price_grade ', $price _grade); } |
Last step, find
return $GLOBALS [' DB ']->getrow (' SELECT cat_name, keywords, cat_desc, style, grade, filter_attr, parent_id from '. $GLOB als[' ECS ']->table (' category '). "WHERE cat_id = ' $cat _id '"); |
Change the revision to
return $GLOBALS [' DB ']->getrow (' SELECT cat_name, keywords, cat_desc, style, grade, Grade_define, Filter_attr, Parent_ ID from '. $GLOBALS [' ECS ']->table (' category '). "WHERE cat_id = ' $cat _id '"); |
Ecshop Commodity Classification Filter Custom price range