Ecshop _ custom price range

Source: Internet
Author: User

You can define the price range (for example, 1-30, 31-200,201-, 1001-, or more) in the ecshop background. The front-end is automatically reflected in one way, and the price range of each category can be set at will, make the price range more humane.

1. First, modify the database structure of ecshop to add a new field to ecs_category,

Log on to the background, select database management> SQL query, and run the following SQL statement.

ALTER TABLE ‘ecs_category‘ ADD ‘grade_define‘ VARCHAR( 255 ) NOT NULL AFTER ‘grade‘

Note: Here I use the default database prefix ECs _. If your database prefix is not ECs _, modify it.

2. Open/admin/templates/category_info.htm

Find

<tr>        <td><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="40" /> <br />          <span {if $help_open}style="display:block" {else} style="display:none" {/if} id="noticeGrade">{$lang.notice_grade}</span>        </td>      </tr>

Modify it

<Tr> <TD> Custom price range: </TD> <input type = "text" name = "grade_define" value = "{$ cat_info.grade_define}" size = "60"/> <br/> <Span {if $ help_open} style = "display: block "{else} style =" display: none "{/if} id =" noticegrade "> separated by halfwidth, such: 1-30, 31-200,201-,-, or more </span> </TD> </tr>

3. Open the/admin/category. php file and search

$cat[‘grade‘]        = !empty($_POST[‘grade‘])        ? intval($_POST[‘grade‘])      : 0;

You can search two places in total, and add code under each place (note that each place)

$ Cat ['grade _ DEFINE '] =! Empty ($ _ post ['grade _ DEFINE '])? Trim ($ _ post ['grade _ DEFINE ']): ''; // custom price range by zhangyh

At this point, the background Management Section has been modified.

4. Modify the foreground section below.

Open/category. php

Find

/* Get price Classification */if ($ cat ['grad'] = 0 & $ cat ['parent _ id']! = 0) {$ cat ['grad'] = get_parent_grade ($ cat_id); // if the current category level is empty, take the nearest superior classification} if ($ cat ['grad']> 1) {/* requires price Classification * // * algorithm idea: 1. When the classification is greater than 1, carry out price Classification 2. Take out the maximum and minimum values of the product price under this category 3. Calculate the order of magnitude of the product price based on the maximum value of the product price: price range (excluding the maximum value) grading order of magnitude 0-0.1 0.001 0.1-1 0.01 1-10 0.1 10-100 1 100-1000 10 1000-10000 100 4. Calculation price span: round (maximum value-Minimum value) /(price classification)/order of magnitude) * magnitude 5. Calculate the price range based on the price span. 6. query the database may have problems: 1. Because the price span is calculated by the maximum and minimum values, and then the price span is used to determine the price range when the display is made, it is possible The price classification quantity is incorrect. This problem is not proved. 2. When the price is equal to the maximum value, the grading will increase, it has been proved that */$ 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'; // obtain the maximum and minimum values of the product price under the current category $ ROW = $ db-> getrow ($ SQL); // obtain the minimum unit level of price classification, for example, the minimum product price for a thousand yuan is 100. $ price_grade = 0.0001. f Or ($ I =-2; $ I <= log10 ($ row ['max ']); $ I ++) {$ price_grade * = 10 ;} // span $ dx = Ceil ($ row ['max ']-$ row ['Min'])/($ cat ['grad'])/$ 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); (; $ 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 => $ va L) {$ 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']. '& nbsp;-& nbsp ;'. $ price_grade [$ temp_key] ['end']; $ price_grade [$ temp_key] ['formated _ sta RT '] = 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']);/* determines whether the price range is selected */I F (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 ('C Id' => $ 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 _ grad', $ price_grade );}

Replace it

/* Get price classification _ New */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' => $ 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' => $ 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']); /* determine whether the price range is selected */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 _ grad', $ price_grade );}

In the last step, find

return $GLOBALS[‘db‘]->getRow(‘SELECT cat_name, keywords, cat_desc, style, grade, filter_attr, parent_id FROM ‘ . $GLOBALS[‘ecs‘]->table(‘category‘) .        " WHERE cat_id = ‘$cat_id‘");

Change it

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 _ custom price range

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.