批发前台怎么实现批量添加

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



在<form>底部添加批量提交按钮, wholesale.php如何修改可以让它循环添加有填入数量的产品?
表单有这样的数据
<input name="goods_number[6][1]" type="text" class="inputBg" value="" size="10" />
通过循环goods_number可以吗?

谁帮忙改一下代码啊, 谢谢!!!

  1. /*------------------------------------------------------ */
  2. //-- 批发批量添加
  3. /*------------------------------------------------------ */
  4. elseif ($_REQUEST['act'] == 'all_add_to_cart')
  5. {
  6. /* 取得参数 */

  7. $goods_number= $_POST['goods_number'];
  8. foreach ($goods_number as $key => $value)
  9. {
  10. $act_id= intval($key);
  11. $attr_id= isset($_POST['attr_id']) ? $_POST['attr_id'] : array();
  12. if(isset($attr_id[$act_id]))
  13. {
  14. $goods_attr= $attr_id[$act_id];
  15. }
  16. /* 用户提交必须全部通过检查,才能视为完成操作 */
  17. /* 检查数量 */
  18. if (empty($goods_number) || (is_array($goods_number) && array_sum($goods_number) <= 0))
  19. {
  20. show_message($_LANG['ws_invalid_goods_number']);
  21. }
  22. /* 确定购买商品列表 */
  23. $goods_list = array();
  24. if (is_array($goods_number))
  25. {
  26. foreach ($goods_number as $key => $value)
  27. {
  28. if (!$value)
  29. {
  30. unset($goods_number[$key], $goods_attr[$key]);
  31. continue;
  32. }
  33. $goods_list[] = array('number' => $goods_number[$key], 'goods_attr' => $goods_attr[$key]);
  34. }
  35. }
  36. else
  37. {
  38. $goods_list[0] = array('number' => $goods_number, 'goods_attr' => '');
  39. }
  40. /* 取批发相关数据 */
  41. $wholesale = wholesale_info($act_id);
  42. /* 检查session中该商品,该属性是否存在 */
  43. if (isset($_SESSION['wholesale_goods']))
  44. {
  45. foreach ($_SESSION['wholesale_goods'] as $goods)
  46. {
  47. if ($goods['goods_id'] == $wholesale['goods_id'])
  48. {
  49. if (empty($goods_attr))
  50. {
  51. show_message($_LANG['ws_goods_attr_exists']);
  52. }
  53. elseif (in_array($goods['goods_attr_id'], $goods_attr))
  54. {
  55. show_message($_LANG['ws_goods_attr_exists']);
  56. }
  57. }
  58. }
  59. }
  60. /* 获取购买商品的批发方案的价格阶梯 (一个方案多个属性组合、一个属性组合、一个属性、无属性) */
  61. $attr_matching = false;
  62. foreach ($wholesale['price_list'] as $attr_price)
  63. {
  64. // 没有属性
  65. if (empty($attr_price['attr']))
  66. {
  67. $attr_matching = true;
  68. $goods_list[0]['qp_list'] = $attr_price['qp_list'];
  69. break;
  70. }
  71. // 有属性
  72. elseif (($key = is_attr_matching($goods_list, $attr_price['attr'])) !== false)
  73. {
  74. $attr_matching = true;
  75. $goods_list[$key]['qp_list'] = $attr_price['qp_list'];
  76. }
  77. }
  78. if (!$attr_matching)
  79. {
  80. show_message($_LANG['ws_attr_not_matching']);
  81. }
  82. /* 检查数量是否达到最低要求 */
  83. foreach ($goods_list as $goods_key => $goods)
  84. {
  85. if ($goods['number'] < $goods['qp_list'][0]['quantity'])
  86. {
  87. show_message($_LANG['ws_goods_number_not_enough']);
  88. }
  89. else
  90. {
  91. $goods_price = 0;
  92. foreach ($goods['qp_list'] as $qp)
  93. {
  94. if ($goods['number'] >= $qp['quantity'])
  95. {
  96. $goods_list[$goods_key]['goods_price'] = $qp['price'];
  97. }
  98. else
  99. {
  100. break;
  101. }
  102. }
  103. }
  104. }
  105. /* 写入session */
  106. foreach ($goods_list as $goods_key => $goods)
  107. {
  108. // 属性名称
  109. $goods_attr_name = '';
  110. if (!empty($goods['goods_attr']))
  111. {
  112. foreach ($goods['goods_attr'] as $key=> $attr)
  113. {
  114. $attr['attr_name']=htmlspecialchars($attr['attr_name']);
  115. $goods['goods_attr'][$key]['attr_name']=$attr['attr_name'];
  116. $attr['attr_val'] =htmlspecialchars($attr['attr_val']);
  117. $goods['goods_attr'][$key]['attr_name']=$attr['attr_name'];
  118. $goods_attr_name .= $attr['attr_name'] . ':' . $attr['attr_val'] . '&nbsp;';
  119. }
  120. }
  121. // 总价
  122. $total = $goods['number'] * $goods['goods_price'];
  123. $_SESSION['wholesale_goods'][] = array(
  124. 'goods_id'=> $wholesale['goods_id'],
  125. 'goods_name' => $wholesale['goods_name'],
  126. 'goods_attr_id' => $goods['goods_attr'],
  127. 'goods_attr' => $goods_attr_name,
  128. 'goods_number'=> $goods['number'],
  129. 'goods_price'=> $goods['goods_price'],
  130. 'subtotal'=> $total,
  131. 'formated_goods_price'=> price_format($goods['goods_price'], false),
  132. 'formated_subtotal'=> price_format($total, false),
  133. 'goods_url'=> build_uri('goods', array('gid' => $wholesale['goods_id']), $wholesale['goods_name']),
  134. );
  135. }
  136. unset($goods_attr, $attr_id, $goods_list, $wholesale, $goods_attr_name);
  137. }
  138. /* 刷新页面 */
  139. ecs_header("Location: ./wholesale.php\n");
  140. exit;
  141. }
复制代码

回答:
木有人帮忙看看吗?

这个没搞过,有点难啊 感觉

路过的朋友帮忙顶一下啊