适用于2.6.2和2.7.0,其他版本未测试。此版本是原来共享的基础上修改bug,就是:购物车中商品数量达到个数,不给折扣。
1.在ECS_goods数据表中新增最小购买数量字段min_number,可以在ecshop后台,sql查询那边直接运行,把ecs改成你改的表前缀,如果没有修改,直接使用以下代码。-
- alter table `ecs_goods` add column `min_number` tinyint (3) UNSIGNEDDEFAULT '0' NOT NULLafter `warn_number`
复制代码 2.修改admin/goods.php-
- 在
- 'warn_number' => 1,
- 代码行后插入
- 'min_number' => 0,
复制代码- 在
- $warn_number = isset($_POST['warn_number']) ? $_POST['warn_number'] : 0;
- 代码行后插入
- $min_number = isset($_POST['min_number']) ? $_POST['min_number'] : 0;
复制代码- 将
- /* 入库 */
- if ($is_insert)
- {
- if ($code == '')
- {
- ....由于发帖篇幅的限制省略原有代码无数
- }
- else
- {
- ......
- }
- }
- else
- {
- /* 如果有上传图片,删除原来的商品图 */
- .....
- }
复制代码-
- 修改成
- /* 入库 */
- if ($is_insert)
- {
- if ($code == '')
- {
- $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
- "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .
- "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .
- "seller_note, goods_weight, goods_number, warn_number,min_number, integral, give_integral, is_best, is_new, is_hot, " .
- "is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type, rank_integral)" .
- "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
- "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".
- "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".
- "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
- " '$warn_number','$min_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', ".
- " '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral')";
- }
- else
- {
- $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
- "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .
- "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .
- "seller_note, goods_weight, goods_number, warn_number, min_number,integral, give_integral, is_best, is_new, is_hot, is_real, " .
- "is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral)" .
- "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
- "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".
- "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".
- "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
- " '$warn_number','$min_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', 0, '$is_on_sale', '$is_alone_sale', ".
- " '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral')";
- }
- }
- else
- {
- /* 如果有上传图片,删除原来的商品图 */
- $sql = "SELECT goods_thumb, goods_img, original_img " .
- " FROM " . $ecs->table('goods') .
- " WHERE goods_id = '$_REQUEST[goods_id]'";
- $row = $db->getRow($sql);
- if ($proc_thumb && $goods_img && $row['goods_img'] && !goods_parse_url($row['goods_img']))
- {
- @unlink(ROOT_PATH . $row['goods_img']);
- @unlink(ROOT_PATH . $row['original_img']);
- }
- if ($proc_thumb && $goods_thumb && $row['goods_thumb'] && !goods_parse_url($row['goods_thumb']))
- {
- @unlink(ROOT_PATH . $row['goods_thumb']);
- }
- $sql = "UPDATE " . $ecs->table('goods') . " SET " .
- "goods_name = '$_POST[goods_name]', " .
- "goods_name_style = '$goods_name_style', " .
- "goods_sn = '$goods_sn', " .
- "cat_id = '$catgory_id', " .
- "brand_id = '$brand_id', " .
- "shop_price = '$shop_price', " .
- "market_price = '$market_price', " .
- "is_promote = '$is_promote', " .
- "promote_price = '$promote_price', " .
- "promote_start_date = '$promote_start_date', " .
- "promote_end_date = '$promote_end_date', ";
- /* 如果有上传图片,需要更新数据库 */
- if ($goods_img)
- {
- $sql .= "goods_img = '$goods_img', original_img = '$original_img', ";
- }
- if ($goods_thumb)
- {
- $sql .= "goods_thumb = '$goods_thumb', ";
- }
- if ($code != '')
- {
- $sql .= "is_real=0, extension_code='$code', ";
- }
- $sql .= "keywords = '$_POST[keywords]', " .
- "goods_brief = '$_POST[goods_brief]', " .
- "seller_note = '$_POST[seller_note]', " .
- "goods_weight = '$goods_weight'," .
- "goods_number = '$goods_number', " .
- "warn_number = '$warn_number', " .
- "min_number = '$min_number', " .
- "integral = '$_POST[integral]', " .
- "give_integral = '$give_integral', " .
- "rank_integral = '$rank_integral', " .
- "is_best = '$is_best', " .
- "is_new = '$is_new', " .
- "is_hot = '$is_hot', " .
- "is_on_sale = '$is_on_sale', " .
- "is_alone_sale = '$is_alone_sale', " .
- "goods_desc = '$_POST[goods_desc]', " .
- "last_update = '". gmtime() ."', ".
- "goods_type = '$goods_type' " .
- "WHERE goods_id = '$_REQUEST[goods_id]' LIMIT 1";
- }
复制代码 3.修改admin/templates/goods_info.htm- 在
- <!--商品优惠价格 end -->
- <tr>
- <td class="label">{$lang.lab_market_price}</td>
- <td><input type="text" name="market_price" value="{$goods.market_price}" size="20" />
- <input type="button" value="{$lang.integral_market_price}" onclick="integral_market_price()" />
- </td>
- </tr>
- 之后新增插入
- <!--新增 批发数量限制 begin -->
- <tr>
- <td class="label">{$lang.lab_min_number}</td>
- <td><input type="text" name="min_number" value="{$goods.min_number}" size="20" />
- <br /><span class="notice-span" {if $help_open}style="display:block" {else} style="display:none" {/if} id="minNumber">{$lang.notice_min_number}</span></td>
- </td>
- </tr>
- <!-- 批发数量限制 end -->
复制代码 4.修改languages/zh_cn/admin/goods.php- 在文件最后新增
- /* 新增 */
- $_LANG['lab_min_number'] = '最小购买数量:';
- $_LANG['notice_min_number'] = '该商品最小购买数量,0表示按购买数量无限制.';
复制代码 5.修改themes/default/goods.dwt- 将
- <input name="number" type="text" id="number" value="1" size="4" onblur="changePrice()" style="border:1px solid #ccc; "/>
- 修改成
- <input name="number" type="text" id="number" value="{$goods.min_number|default:"1"}" size="4" onblur="changePrice()" style="border:1px solid #ccc; "/>
复制代码- 在
- var qty = document.forms['ECS_FORMBUY'].elements['number'].value;
- 之后添加
- <!-- {if $goods.min_number} -->
- if (qty < {$goods.min_number})
- {
- alert('您输入的数字小于此商品最小购买数量:{$goods.min_number}');
- qty = {$goods.min_number};
- }
- <!-- {/if} -->
复制代码 6.修改language/zh_cn/shopping_flow.php- $_LANG['stock_insufficiency'] = '非常抱歉,您选择的商品 %s 的库存数量只有 %d,您最多只能购买 %d 件。';后增加一行
- $_LANG['goods_number_too_few'] = '非常抱歉,您选择的商品 %s ,购买的的数量小于此商品最小购买数量 %d 件。';
复制代码 7.修改flow.php- 查找
- $sql = "SELECT g.goods_name, g.goods_number ".
- "FROM " .$GLOBALS['ecs']->table('goods'). " AS g, ".
- $GLOBALS['ecs']->table('cart'). " AS c ".
- "WHERE g.goods_id = c.goods_id AND c.rec_id = '$key'";
- 修改为
- $sql = "SELECT g.goods_name, g.goods_number, g.min_number ".
- "FROM " .$GLOBALS['ecs']->table('goods'). " AS g, ".
- $GLOBALS['ecs']->table('cart'). " AS c ".
- "WHERE g.goods_id = c.goods_id AND c.rec_id = '$key'";
复制代码- 在代码 if ($row['goods_number'] < $val)
- {
- show_message(sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'],
- $row['goods_number'], $row['goods_number']));
- exit;
- }后添加
- if ($row['min_number'] > $val)
- {
- show_message(sprintf($GLOBALS['_LANG']['goods_number_too_few'], $row['goods_name'],
- $row['min_number']));
- exit;
- }
复制代码
|