商品批发增加起订数功能,设置购买数量(修正版)

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家



适用于2.6.2和2.7.0,其他版本未测试。此版本是原来共享的基础上修改bug,就是:购物车中商品数量达到个数,不给折扣。
1.在ECS_goods数据表中新增最小购买数量字段min_number,可以在ecshop后台,sql查询那边直接运行,把ecs改成你改的表前缀,如果没有修改,直接使用以下代码。

  1. alter table `ecs_goods` add column `min_number` tinyint (3) UNSIGNEDDEFAULT '0' NOT NULLafter `warn_number`
复制代码
2.修改admin/goods.php


  1. 'warn_number' => 1,
  2. 代码行后插入
  3. 'min_number' => 0,
复制代码

  1. $warn_number = isset($_POST['warn_number']) ? $_POST['warn_number'] : 0;
  2. 代码行后插入
  3. $min_number = isset($_POST['min_number']) ? $_POST['min_number'] : 0;
复制代码

  1. /* 入库 */
  2. if ($is_insert)
  3. {
  4. if ($code == '')
  5. {
  6. ....由于发帖篇幅的限制省略原有代码无数
  7. }
  8. else
  9. {
  10. ......
  11. }
  12. }
  13. else
  14. {
  15. /* 如果有上传图片,删除原来的商品图 */
  16. .....
  17. }
复制代码

  1. 修改成
  2. /* 入库 */
  3. if ($is_insert)
  4. {
  5. if ($code == '')
  6. {
  7. $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
  8. "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .
  9. "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .
  10. "seller_note, goods_weight, goods_number, warn_number,min_number, integral, give_integral, is_best, is_new, is_hot, " .
  11. "is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type, rank_integral)" .
  12. "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
  13. "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".
  14. "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".
  15. "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
  16. " '$warn_number','$min_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', ".
  17. " '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral')";
  18. }
  19. else
  20. {
  21. $sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .
  22. "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .
  23. "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .
  24. "seller_note, goods_weight, goods_number, warn_number, min_number,integral, give_integral, is_best, is_new, is_hot, is_real, " .
  25. "is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral)" .
  26. "VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .
  27. "'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".
  28. "'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".
  29. "'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".
  30. " '$warn_number','$min_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', 0, '$is_on_sale', '$is_alone_sale', ".
  31. " '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral')";
  32. }
  33. }
  34. else
  35. {
  36. /* 如果有上传图片,删除原来的商品图 */
  37. $sql = "SELECT goods_thumb, goods_img, original_img " .
  38. " FROM " . $ecs->table('goods') .
  39. " WHERE goods_id = '$_REQUEST[goods_id]'";
  40. $row = $db->getRow($sql);
  41. if ($proc_thumb && $goods_img && $row['goods_img'] && !goods_parse_url($row['goods_img']))
  42. {
  43. @unlink(ROOT_PATH . $row['goods_img']);
  44. @unlink(ROOT_PATH . $row['original_img']);
  45. }
  46. if ($proc_thumb && $goods_thumb && $row['goods_thumb'] && !goods_parse_url($row['goods_thumb']))
  47. {
  48. @unlink(ROOT_PATH . $row['goods_thumb']);
  49. }
  50. $sql = "UPDATE " . $ecs->table('goods') . " SET " .
  51. "goods_name = '$_POST[goods_name]', " .
  52. "goods_name_style = '$goods_name_style', " .
  53. "goods_sn = '$goods_sn', " .
  54. "cat_id = '$catgory_id', " .
  55. "brand_id = '$brand_id', " .
  56. "shop_price = '$shop_price', " .
  57. "market_price = '$market_price', " .
  58. "is_promote = '$is_promote', " .
  59. "promote_price = '$promote_price', " .
  60. "promote_start_date = '$promote_start_date', " .
  61. "promote_end_date = '$promote_end_date', ";
  62. /* 如果有上传图片,需要更新数据库 */
  63. if ($goods_img)
  64. {
  65. $sql .= "goods_img = '$goods_img', original_img = '$original_img', ";
  66. }
  67. if ($goods_thumb)
  68. {
  69. $sql .= "goods_thumb = '$goods_thumb', ";
  70. }
  71. if ($code != '')
  72. {
  73. $sql .= "is_real=0, extension_code='$code', ";
  74. }
  75. $sql .= "keywords = '$_POST[keywords]', " .
  76. "goods_brief = '$_POST[goods_brief]', " .
  77. "seller_note = '$_POST[seller_note]', " .
  78. "goods_weight = '$goods_weight'," .
  79. "goods_number = '$goods_number', " .
  80. "warn_number = '$warn_number', " .
  81. "min_number = '$min_number', " .
  82. "integral = '$_POST[integral]', " .
  83. "give_integral = '$give_integral', " .
  84. "rank_integral = '$rank_integral', " .
  85. "is_best = '$is_best', " .
  86. "is_new = '$is_new', " .
  87. "is_hot = '$is_hot', " .
  88. "is_on_sale = '$is_on_sale', " .
  89. "is_alone_sale = '$is_alone_sale', " .
  90. "goods_desc = '$_POST[goods_desc]', " .
  91. "last_update = '". gmtime() ."', ".
  92. "goods_type = '$goods_type' " .
  93. "WHERE goods_id = '$_REQUEST[goods_id]' LIMIT 1";
  94. }
复制代码
3.修改admin/templates/goods_info.htm

  1. <!--商品优惠价格 end -->
  2. <tr>
  3. <td class="label">{$lang.lab_market_price}</td>
  4. <td><input type="text" name="market_price" value="{$goods.market_price}" size="20" />
  5. <input type="button" value="{$lang.integral_market_price}" onclick="integral_market_price()" />
  6. </td>
  7. </tr>
  8. 之后新增插入
  9. <!--新增 批发数量限制 begin -->
  10. <tr>
  11. <td class="label">{$lang.lab_min_number}</td>
  12. <td><input type="text" name="min_number" value="{$goods.min_number}" size="20" />
  13. <br /><span class="notice-span" {if $help_open}style="display:block" {else} style="display:none" {/if} id="minNumber">{$lang.notice_min_number}</span></td>
  14. </td>
  15. </tr>
  16. <!-- 批发数量限制 end -->
复制代码
4.修改languages/zh_cn/admin/goods.php
  1. 在文件最后新增
  2. /* 新增 */
  3. $_LANG['lab_min_number'] = '最小购买数量:';
  4. $_LANG['notice_min_number'] = '该商品最小购买数量,0表示按购买数量无限制.';
复制代码
5.修改themes/default/goods.dwt

  1. <input name="number" type="text" id="number" value="1" size="4" onblur="changePrice()" style="border:1px solid #ccc; "/>
  2. 修改成
  3. <input name="number" type="text" id="number" value="{$goods.min_number|default:"1"}" size="4" onblur="changePrice()" style="border:1px solid #ccc; "/>
复制代码

  1. var qty = document.forms['ECS_FORMBUY'].elements['number'].value;
  2. 之后添加
  3. <!-- {if $goods.min_number} -->
  4. if (qty < {$goods.min_number})
  5. {
  6. alert('您输入的数字小于此商品最小购买数量:{$goods.min_number}');
  7. qty = {$goods.min_number};
  8. }
  9. <!-- {/if} -->
复制代码
6.修改language/zh_cn/shopping_flow.php
  1. $_LANG['stock_insufficiency'] = '非常抱歉,您选择的商品 %s 的库存数量只有 %d,您最多只能购买 %d 件。';后增加一行
  2. $_LANG['goods_number_too_few'] = '非常抱歉,您选择的商品 %s ,购买的的数量小于此商品最小购买数量 %d 件。';
复制代码
7.修改flow.php
  1. 查找
  2. $sql = "SELECT g.goods_name, g.goods_number ".
  3. "FROM " .$GLOBALS['ecs']->table('goods'). " AS g, ".
  4. $GLOBALS['ecs']->table('cart'). " AS c ".
  5. "WHERE g.goods_id = c.goods_id AND c.rec_id = '$key'";
  6. 修改为
  7. $sql = "SELECT g.goods_name, g.goods_number, g.min_number ".
  8. "FROM " .$GLOBALS['ecs']->table('goods'). " AS g, ".
  9. $GLOBALS['ecs']->table('cart'). " AS c ".
  10. "WHERE g.goods_id = c.goods_id AND c.rec_id = '$key'";
复制代码
  1. 在代码 if ($row['goods_number'] < $val)
  2. {
  3. show_message(sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'],
  4. $row['goods_number'], $row['goods_number']));
  5. exit;
  6. }后添加
  7. if ($row['min_number'] > $val)
  8. {
  9. show_message(sprintf($GLOBALS['_LANG']['goods_number_too_few'], $row['goods_name'],
  10. $row['min_number']));
  11. exit;
  12. }
复制代码


回答:
不错
支持

谢谢楼主的分享,但是这样恐怕用户体验不是很好吧?日常生活中都是买的多优惠率越高,这样用户可能会???
希望楼主考虑考虑

4# owndream 就是有人需要我才写的,呵呵。。。

这个可以选择应用范围么?
品牌,分类,或者商品,

不能。。如果需要可以拓展下。

感谢楼主分享, 不过购物车 更新数量要是能跟 产品页一样就更好了!呵呵
继续支持!

不太适合做批发的,一般有些批是一包一包的批,一包里有很多件,比如一包10件,客户输入11怎么办?还是没办法

好定西啊!!!

不错的功能,支持楼主

此功能在商品详情面购买时有批发数量限制,但是在购物流程结算时可以任意修改批发数量

此功能在商品详情面购买时有批发数量限制,但是在购物流程结算时可以任意修改批发数量
gzjob 发表于 2009-10-30 01:14

当数量小于后台设置的数量的时候,会自动按照平常购买,不打折扣。

想问下 我在ecshop后台,sql查询那边直接运行,alter table `ecs_goods` add column `min_number` tinyint (3) UNSIGNEDDEFAULT '0' NOT NULLafter `warn_number`

现在顾客只能够买1 样东西。 怎么办??
一把货物放入购物车就直接跳到结帐的面页 。。。 跳过了checkout的面页。

应该怎么处理呢?

请大家帮帮忙。。

www.fashiondeliver21.com