package ds.servlet;import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import ds.bean.CratItem;
import ds.bean.WaresBean;
import ds.dao.WaresBase;
import ds.dao.WaresBaseImp;public class AddCartServlet extends HttpServlet { public AddCartServlet() {
super();
} public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
String[] id = request.getParameterValues("chbox"); //得到用户所选ID数组
//System.out.println("id01------>" + id);
List select_list = new ArrayList(); //封装用户所选ID和输入的购买数量(匹配后的)
for(int i = 0; i < id.length; i++){
int acount = Integer.parseInt(request.getParameter(id[i]+"waresText"));
System.out.println("acount" + acount);
WaresBean select_wares=new WaresBean();
select_wares.setWaresid(Integer.parseInt(id[i]));
select_wares.setPnum(acount);
select_list.add(select_wares); //将保存ID与数量的对象封装到list中
}
HttpSession session = request.getSession();
List waresList = (List)session.getAttribute("waresList");
WaresBase waresDao = new WaresBaseImp(); //实例化dao层对象
List cartList = new ArrayList();
if(id != null){ //如果用户选择了商品
WaresBean wares = null;
WaresBean select_wares01 = null;
for(int i = 0; i < select_list.size(); i++){
//遍历匹配用户选择后的list,里面存有WaresBean对象
for(int j = 0; j < cartList.size(); j++){
cartList = (List)session.getAttribute("cratItemList");
CratItem cratItem = (CratItem)cartList.get(j);
System.out.println(cratItem);
select_wares01 = (WaresBean)select_list.get(i); //对象中有选择后的id属性和输入后的pnum属性
wares = (WaresBean)waresList.get(i); //WaresBean对象,数据库中的数据
if(cratItem == null){
if(wares.getWaresid() == select_wares01.getWaresid()){
//将数据库中的id与匹配后的id对比
cratItem = new CratItem(wares, select_wares01.getPnum()); //将其存入cratItem对象中
cartList.add(cratItem); //封装成list }
}else{
cratItem.setNum(cratItem.getNum() + select_wares01.getPnum());
cartList.add(cratItem); }
}
}
}
session.setAttribute("cratItemList",cartList); System.out.println("准备跳转2");
request.getRequestDispatcher("ViewCart.jsp").forward(request,response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
} public void init() throws ServletException {
// Put your code here
}}这个购物车不能再页面选择商品后,点击购物 结果就是购物车页面什么都不显示
还有就是我只能购买第一个商品 其他商品会出错!~!!!
网上很多购物车都是购买一个物品,我这个是购买数量由用户在text里面输入。
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import ds.bean.CratItem;
import ds.bean.WaresBean;
import ds.dao.WaresBase;
import ds.dao.WaresBaseImp;public class AddCartServlet extends HttpServlet { public AddCartServlet() {
super();
} public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
String[] id = request.getParameterValues("chbox"); //得到用户所选ID数组
//System.out.println("id01------>" + id);
List select_list = new ArrayList(); //封装用户所选ID和输入的购买数量(匹配后的)
for(int i = 0; i < id.length; i++){
int acount = Integer.parseInt(request.getParameter(id[i]+"waresText"));
System.out.println("acount" + acount);
WaresBean select_wares=new WaresBean();
select_wares.setWaresid(Integer.parseInt(id[i]));
select_wares.setPnum(acount);
select_list.add(select_wares); //将保存ID与数量的对象封装到list中
}
HttpSession session = request.getSession();
List waresList = (List)session.getAttribute("waresList");
WaresBase waresDao = new WaresBaseImp(); //实例化dao层对象
List cartList = new ArrayList();
if(id != null){ //如果用户选择了商品
WaresBean wares = null;
WaresBean select_wares01 = null;
for(int i = 0; i < select_list.size(); i++){
//遍历匹配用户选择后的list,里面存有WaresBean对象
for(int j = 0; j < cartList.size(); j++){
cartList = (List)session.getAttribute("cratItemList");
CratItem cratItem = (CratItem)cartList.get(j);
System.out.println(cratItem);
select_wares01 = (WaresBean)select_list.get(i); //对象中有选择后的id属性和输入后的pnum属性
wares = (WaresBean)waresList.get(i); //WaresBean对象,数据库中的数据
if(cratItem == null){
if(wares.getWaresid() == select_wares01.getWaresid()){
//将数据库中的id与匹配后的id对比
cratItem = new CratItem(wares, select_wares01.getPnum()); //将其存入cratItem对象中
cartList.add(cratItem); //封装成list }
}else{
cratItem.setNum(cratItem.getNum() + select_wares01.getPnum());
cartList.add(cratItem); }
}
}
}
session.setAttribute("cratItemList",cartList); System.out.println("准备跳转2");
request.getRequestDispatcher("ViewCart.jsp").forward(request,response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
} public void init() throws ServletException {
// Put your code here
}}这个购物车不能再页面选择商品后,点击购物 结果就是购物车页面什么都不显示
还有就是我只能购买第一个商品 其他商品会出错!~!!!
网上很多购物车都是购买一个物品,我这个是购买数量由用户在text里面输入。
找错的话,先看是否到servlet了,servlet里是否得到数据的值,
可以查看一下购物车List的东西是否是客户选的,
如果涉及到数据库,看一下数据是否进数据库了
哪一步错了哪一步找
还有你这个购物车数量由用户输入完全没有问题,我以前就做过这样的例子
至于购买其他商品会出错,你用心找找就好了
package ds.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import ds.bean.CratItem;
import ds.bean.WaresBean;
import ds.dao.WaresBase;
import ds.dao.WaresBaseImp; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ response.setContentType( "text/html ");
request.setCharacterEncoding( "gbk ");
response.setCharacterEncoding( "gbk "); String[] id = request.getParameterValues("chbox"); //得到用户所选ID数组 List select_list = new ArrayList(); //封装用户所选ID和输入的购买数量(匹配后的)
for(int i = 0; i < id.length; i++){
int acount = Integer.parseInt(request.getParameter(id[i]+ "waresText ")); WaresBean select_wares=new WaresBean();
select_wares.setWaresid(Integer.parseInt(id[i]));
select_wares.setPnum(acount);
select_list.add(select_wares); //将保存ID与数量的对象封装到list中
} HttpSession session = request.getSession(); List waresList = (List)session.getAttribute( "waresList "); WaresBase waresDao = new WaresBaseImp(); //实例化dao层对象里面有调去数据库的方法 List cartList = new ArrayList();
if(id != null){ //如果用户选择了商品
WaresBean wares = null;
WaresBean select_wares01 = null; //遍历匹配用户选择后的list,里面存有WaresBean对象
for(int i = 0; i < select_list.size(); i++){
for(int j = 0; j < cartList.size(); j++){ cartList = (List)session.getAttribute( "cratItemList ");
//CratItem类是用来存放WaresBean对象和用户输入的购买数量(就是上面的acount)
CratItem cratItem = (CratItem)cartList.get(j);
//对象中有选择后的id属性和输入后的pnum属性
select_wares01 = (WaresBean)select_list.get(i);
wares = (WaresBean)waresList.get(i); //WaresBean对象,数据库中的数据 if(cratItem == null){
//将数据库中的id与匹配后的id对比
if(wares.getWaresid() == select_wares01.getWaresid()){
//将其存入cratItem对象中
cratItem = new CratItem(wares, select_wares01.getPnum());
cartList.add(cratItem); //封装成list }
}else{
cratItem.setNum(cratItem.getNum() + select_wares01.getPnum());
cartList.add(cratItem);
}
}
}
}
session.setAttribute( "cratItemList ",cartList);
request.getRequestDispatcher( "ViewCart.jsp ").forward(request,response);
} public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ doGet(request,response);
}
不好意思各位,我整理了一下 这个就是servlet文件 但是我把判断都放这个里面了 下部整理了 现在就是程序问题这个购物车不能再页面选择商品后,点击购物 结果就是购物车页面什么都不显示
还有就是我只能购买第一个商品 其他商品会出错!~!!!
网上很多购物车都是购买一个物品,我这个是购买数量由用户在text里面输入。
package com.octmami.xjf.action;import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;import org.apache.struts2.ServletActionContext;import com.octmami.chh.service.ActivityService;
import com.octmami.chh.service.GiftServices;
import com.octmami.chh.service.IActivityCenterService;
import com.octmami.chh.vo.ActivityVo;
import com.octmami.chh.vo.ActivityactivitytypeVo;
import com.octmami.chh.vo.BuyLessVo;
import com.octmami.chh.vo.CouponVo;
import com.octmami.chh.vo.DiscountVo;
import com.octmami.chh.vo.GiftVo;
import com.octmami.chh.vo.TiffanycoupontypeVo_;
import com.octmami.chh.vo.UserInfoVo;
import com.octmami.py.service.IPCSService;
import com.octmami.py.service.IProductService;
import com.octmami.py.vo.PCSVo;
import com.octmami.util.GenerateNumber;
import com.octmami.xjf.vo.Cart;
import com.opensymphony.xwork2.ActionSupport;public class ShopChartAction extends ActionSupport{ private IProductService productservice; private int pid; //private List<PCSVo> shopChartList = new ArrayList<PCSVo>();// 购物车集合
private int count = 0;
private Float money = 0F;
private Cart shopChartList = new Cart();
private boolean flag = true;
private IPCSService service;
private IActivityCenterService activityCenterService;
private GiftServices giftServices;
private ActivityService activityService;
public void setGiftServices(GiftServices giftServices) {
this.giftServices = giftServices;
}
public String queryList() throws Exception {
List<PCSVo> pcsVoList = service.queryAllPCSByPage(1, 10);
ServletActionContext.getRequest().setAttribute("pcsVoList", pcsVoList);
return "all";
}
private List<ActivityVo> queryCurDateActivity(Float price){
return activityService.queryActivityByCurDate(new Date(),price);
}
private int buyCount = 1;//购买数量
public void setBuyCount(int buyCount) {
this.buyCount = buyCount;
}
/**
* 加入购物车
* @return
* @throws Exception
*/
public String joinShopChart() throws Exception {
PCSVo pcsvo = service.queryPCSById(pid);
shopChartList = (Cart) ServletActionContext.getRequest().getSession().getAttribute("shopChart");
if(shopChartList == null){
shopChartList = new Cart();
}
if (shopChartList.getShopChartList().size() > 0) {
for (PCSVo pv : shopChartList.getShopChartList()) {
if (pcsvo.getProductVO().getProductId().equals(pv.getProductVO().getProductId())) {
if(pcsvo.getColorVo().getColorId().equals(pv.getColorVo().getColorId())){
if(pcsvo.getSizeVo().getSizeId().equals(pv.getSizeVo().getSizeId())){
if(pv.getWithName() == null){
pv.setCount(pv.getCount() + buyCount);// 商品的id、颜色、尺码都相同则将数量加 buyCount, 并且 搭配名称应为空
flag = false;//说明当前商品在购物车中
break;
}
}
}
}
}
if(flag){ //如果当前商品不存在购物车中则添加
pcsvo.setCount(buyCount);//购买数量默认为buyCount
shopChartList.getShopChartList().add(pcsvo);
}
}else{
pcsvo.setCount(buyCount);//购买数量默认为buyCount
shopChartList.getShopChartList().add(pcsvo);
}
if (shopChartList.getShopChartList().size() > 0) {
for(PCSVo pv : shopChartList.getShopChartList()){
count += pv.getCount() == null ? 0 : pv.getCount();
if(pv.getWithName() != null){
money += pv.getCount() * (pv.getWithPrice() == null ? 1 : pv.getWithPrice());
}else{
money += pv.getCount() * pv.getProductVO().getPromotionPrice();
}
}
}else{
count = 0;
money = 0F;
}
shopChartList.setTotalCount(count);
shopChartList.setTotalMoney(money);
ServletActionContext.getRequest().getSession().setAttribute("shopChart", shopChartList);
this.joinActivity();
flag = true;//还原状态
count = 0;
money = 0F;
return "back";
} /**
* 从购物车中删除商品
* @return
*/
public String delProductFromChart(){
shopChartList = (Cart) ServletActionContext.getRequest().getSession().getAttribute("shopChart");
if(shopChartList != null){
if(shopChartList.getShopChartList().size() > 0){
for(PCSVo vo : shopChartList.getShopChartList()){
if(vo.getPCSId() == Integer.parseInt(delId)){
if(vo.getColorVo().getColorId() == Integer.parseInt(colorId)){
if(vo.getSizeVo().getSizeId() == Integer.parseInt(sizeId)){
if(vo.getWithName() == null){
shopChartList.getShopChartList().remove(vo);
break;
}
}
}
}
}
}
if (shopChartList.getShopChartList().size() > 0) {
for(PCSVo pv : shopChartList.getShopChartList()){
count += pv.getCount() == null ? 0 : pv.getCount();
if(pv.getWithName() != null){
money += pv.getCount() * (pv.getWithPrice() == null ? 1 : pv.getWithPrice());
}else{
money += pv.getCount() * pv.getProductVO().getPromotionPrice();
}
}
}else{
count = 0;
money = 0F;
}
shopChartList.setTotalCount(count);
shopChartList.setTotalMoney(money);
shopChartList.setActivityVo(new ActivityVo());//设置优惠活动为空
shopChartList.setCouMoney(0F);//设置优惠金额为0
ServletActionContext.getRequest().getSession().setAttribute("shopChart",shopChartList);
this.joinActivity();
count = 0;
money = 0F;
}
return "back";
}
/**
* 根据活动id查找金额、时间都满足的活动内容
* @return
*/
public String find(){
List<ActivityVo> activityVoList = (List<ActivityVo>) ServletActionContext.getRequest().getSession().getAttribute("curDateActivity");
shopChartList = (Cart) ServletActionContext.getRequest().getSession().getAttribute("shopChart");
Float couMoney = 0F;//优惠总金额
if(activityVoList != null){
List<DiscountVo> disVoList = new ArrayList<DiscountVo>();
List<CouponVo> couVoList = new ArrayList<CouponVo>();
List<GiftVo> giftVoList = new ArrayList<GiftVo>();
for(ActivityVo activityVo : activityVoList){
if(activityVo.getActivityId() == activityId_){
shopChartList.setActivityVo(activityVo);
for(ActivityactivitytypeVo vo : activityVo.getActivity2VoList()){
shopChartList.getOrderVo().setActivityname(vo.getActivityVo().getActivityname());//设置活动名称
if(vo.getBuyLessVoSet() != null){//满就减
for(Object o : vo.getBuyLessVoSet()){
BuyLessVo lessVo = (BuyLessVo) o;
couMoney += lessVo.getCouponmoney();
}
shopChartList.getOrderVo().setActivitymoney(couMoney);//设置满就减优惠额
}
if(vo.getTiffanycouSet() != null){//买就送
for(Object o : vo.getTiffanycouSet()){
TiffanycoupontypeVo_ vo_ = (TiffanycoupontypeVo_) o;
switch (vo_.getType()) {
case 1://折扣券
DiscountVo discountVo = new DiscountVo();
discountVo.setDiscountId(vo_.getTypeid());
System.out.println("zhekouquan:"+vo_.getTypeid());
disVoList.add(discountVo);
shopChartList.getOrderVo().setTiffanyGucciid(vo_.getTiffanycoupontypeId().toString());
shopChartList.getOrderVo().setTiffanyGucciname(vo.getActivityVo().getActivityname());
shopChartList.getOrderVo().setTiffanyGuccitype(0);//买就送类型: 折扣券
break;
case 2://优惠券
CouponVo couponVo = new CouponVo();
couponVo.setCouponId(vo_.getTypeid());
couVoList.add(couponVo);
shopChartList.getOrderVo().setTiffanyGucciid(vo_.getTiffanycoupontypeId().toString());
shopChartList.getOrderVo().setTiffanyGucciname(vo.getActivityVo().getActivityname());
shopChartList.getOrderVo().setTiffanyGuccitype(1);//买就送类型: 优惠券
break;
case 3://赠品
GiftVo giftVo = new GiftVo();
giftVo.setGrade(vo_.getTypeid());//设置赠品等级
giftVoList.add(giftVo);
shopChartList.getOrderVo().setTiffanyGucciid(vo_.getTiffanycoupontypeId().toString());
shopChartList.getOrderVo().setTiffanyGucciname(vo.getActivityVo().getActivityname());
shopChartList.getOrderVo().setTiffanyGuccitype(2);//买就送类型: 赠品
break;
default:
break;
}
}
}
shopChartList.setCouMoney(couMoney);//满就减优惠金额
shopChartList.setDiscount(disVoList);//设置送的折扣券集合
shopChartList.setCoupon(couVoList);//设置送的优惠券集合
shopChartList.setGift(giftVoList);//设置送的赠品集合
}
ServletActionContext.getRequest().getSession().setAttribute("shopChart",shopChartList);
return "back";
}
}
ServletActionContext.getRequest().getSession().setAttribute("shopChart",shopChartList);
}
return "back";
} /**
* 添加数量
* @return
*/
public String addCount(){
shopChartList = (Cart) ServletActionContext.getRequest().getSession().getAttribute("shopChart");
if(shopChartList != null){
if(shopChartList.getShopChartList().size() > 0){
for(PCSVo vo : shopChartList.getShopChartList()){
if(vo.getPCSId() == addId){
if(vo.getColorVo().getColorId() == colorId_){
if(vo.getWithName() == null){
vo.setCount(count_);//设置数量
}
}
}
}
}
}
}
if (shopChartList.getShopChartList().size() > 0) {
for(PCSVo pv : shopChartList.getShopChartList()){
count += pv.getCount() == null ? 0 : pv.getCount();
if(pv.getWithName() != null){
money += pv.getCount() * (pv.getWithPrice() == null ? 1 : pv.getWithPrice());
}else{
money += pv.getCount() * pv.getProductVO().getPromotionPrice();
}
}
}else{
count = 0;
money = 0F;
}
shopChartList.setTotalCount(count);
shopChartList.setTotalMoney(money);
shopChartList.setActivityVo(new ActivityVo());//设置优惠活动为空
shopChartList.setCouMoney(0F);//设置优惠金额为0
ServletActionContext.getRequest().getSession().setAttribute("shopChart",shopChartList);
this.joinActivity();
count = 0;
money = 0F;
return "back";
}
private int pcsMainId;//捆绑销售主商品Id
private String withName;//捆版销售 名称(商品名称相加)
private Float withPrice;//捆版销售价格
private boolean withflag = true;
public void setPcsMainId(int pcsMainId) {
this.pcsMainId = pcsMainId;
}
public void setWithName(String withName) {
this.withName = withName;
}
public void setWithPrice(Float withPrice) {
this.withPrice = withPrice;
}
/**
* 捆绑销售加入购物车
* @return
* @throws UnsupportedEncodingException
*/
public String joinShopCart_withSale() throws UnsupportedEncodingException{
ServletActionContext.getRequest().setCharacterEncoding("utf-8");
ServletActionContext.getResponse().setCharacterEncoding("utf-8");
ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
PCSVo pcsvo = service.queryPCSById(pcsMainId);
shopChartList = (Cart) ServletActionContext.getRequest().getSession().getAttribute("shopChart");
if(shopChartList == null){
shopChartList = new Cart();
}
if (shopChartList.getShopChartList().size() > 0) {
for(PCSVo vo : shopChartList.getShopChartList()){
if (pcsvo.getProductVO().getProductId().equals(vo.getProductVO().getProductId())) {
if(pcsvo.getColorVo().getColorId().equals(vo.getColorVo().getColorId())){
if(pcsvo.getSizeVo().getSizeId().equals(vo.getSizeVo().getSizeId())){
if(withName.equals(vo.getWithName())){
/**
* 如果 颜色,尺寸,商品id都相同并且 搭配名称也相同。那么、就是相同的搭配销售
*/
vo.setCount(vo.getCount() + buyCount);
vo.setWithName(withName);
vo.setWithPrice(withPrice);
withflag = false;
break;
}
}
}
}
}
if(withflag){ //如果当前商品不存在购物车中则添加
pcsvo.setCount(buyCount);//购买数量默认为buyCount
pcsvo.setWithName(withName);
pcsvo.setWithPrice(withPrice);
shopChartList.getShopChartList().add(pcsvo);
}
}
else{
pcsvo.setCount(buyCount);//购买数量默认为buyCount
pcsvo.setWithName(withName);
pcsvo.setWithPrice(withPrice);
shopChartList.getShopChartList().add(pcsvo);
}
if (shopChartList.getShopChartList().size() > 0) {
for(PCSVo pv : shopChartList.getShopChartList()){
count += pv.getCount() == null ? 0 : pv.getCount();
if(pv.getWithName() != null){
money += pv.getCount() * (pv.getWithPrice() == null ? 1 : pv.getWithPrice());
}else{
money += pv.getCount() * pv.getProductVO().getPromotionPrice();
}
}
}else{
count = 0;
money = 0F;
}
shopChartList.setTotalCount(count);
shopChartList.setTotalMoney(money);
ServletActionContext.getRequest().getSession().setAttribute("shopChart", shopChartList);
this.joinActivity();
withflag = true;//还原状态
count = 0;
money = 0F;
return "back";
}
private int withColorId;
private int withSizeId;
public void setWithColorId(int withColorId) {
this.withColorId = withColorId;
}
public void setWithSizeId(int withSizeId) {
this.withSizeId = withSizeId;
}
/**
* 中文
* @param str
* @return
* @throws UnsupportedEncodingException
*/
private String uncode(String str) throws UnsupportedEncodingException{
str = new String(str.getBytes("iso-8859-1"),"utf-8");
StringBuffer buffer = new StringBuffer();
String[] names = str.split(" ");
for(int s = 0; s < names.length; s ++){
buffer.append(names[s]+"+");
}
str = buffer.toString().substring(0, buffer.toString().lastIndexOf("+"));
return str;
}
/**
* 删除搭配销售
* @return
* @throws UnsupportedEncodingException
*/
public String delWithSale() throws UnsupportedEncodingException{
ServletActionContext.getRequest().setCharacterEncoding("utf-8");
withName = this.uncode(withName);
shopChartList = (Cart) ServletActionContext.getRequest().getSession().getAttribute("shopChart");
if(shopChartList != null){
if(shopChartList.getShopChartList().size() > 0){
for(PCSVo vo : shopChartList.getShopChartList()){
if(vo.getPCSId() == pcsMainId){
if(vo.getColorVo().getColorId() == withColorId){
if(vo.getSizeVo().getSizeId() == withSizeId){
if(withName.equals(vo.getWithName())){
shopChartList.getShopChartList().remove(vo);
break;
}
}
}
}
}
}
if (shopChartList.getShopChartList().size() > 0) {
for(PCSVo pv : shopChartList.getShopChartList()){
count += pv.getCount() == null ? 0 : pv.getCount();
if(pv.getWithName() != null){
money += pv.getCount() * (pv.getWithPrice() == null ? 1 : pv.getWithPrice());
}else{
money += pv.getCount() * pv.getProductVO().getPromotionPrice();
}
}
}else{
count = 0;
money = 0F;
}
shopChartList.setTotalCount(count);
shopChartList.setTotalMoney(money);
shopChartList.setActivityVo(new ActivityVo());//设置优惠活动为空
shopChartList.setCouMoney(0F);//设置优惠金额为0
ServletActionContext.getRequest().getSession().setAttribute("shopChart",shopChartList);
this.joinActivity();
count = 0;
money = 0F;
}
return "back";
}
private int withSaleCount;
public void setWithSaleCount(int withSaleCount) {
this.withSaleCount = withSaleCount;
}
private String withName_;
public void setWithName_(String withName_) {
this.withName_ = withName_;
}
private void joinActivity(){
UserInfoVo infoVo = (UserInfoVo) ServletActionContext.getRequest().getSession().getAttribute("userinfo");
if(infoVo == null){
return;
}else{
Cart cart = (Cart) ServletActionContext.getRequest().getSession().getAttribute("shopChart");
ServletActionContext.getRequest().getSession().setAttribute("curDateActivity", this.queryCurDateActivity(money - cart.getSelfMoney()));
}
}
/**
* 添加捆绑销售数量
* @return
* @throws UnsupportedEncodingException
*/
public String addWithSaleCount() throws UnsupportedEncodingException{
shopChartList = (Cart) ServletActionContext.getRequest().getSession().getAttribute("shopChart");
withName_ = this.uncode(withName_);
if(shopChartList != null){
if(shopChartList.getShopChartList().size() > 0){
for(PCSVo vo : shopChartList.getShopChartList()){
if(vo.getPCSId() == pcsMainId){
if(vo.getColorVo().getColorId() == withColorId){
if(vo.getSizeVo().getSizeId() ==withSizeId){
if(withName_.equals(vo.getWithName())){
vo.setCount(withSaleCount);//设置数量
}
}
}
}
}
}
}
if (shopChartList.getShopChartList().size() > 0) {
for(PCSVo pv : shopChartList.getShopChartList()){
count += pv.getCount() == null ? 0 : pv.getCount();
if(pv.getWithName() != null){
money += pv.getCount() * (pv.getWithPrice() == null ? 1 : pv.getWithPrice());
}else{
money += pv.getCount() * pv.getProductVO().getPromotionPrice();
}
}
}else{
count = 0;
money = 0F;
}
shopChartList.setTotalCount(count);
shopChartList.setTotalMoney(money);
shopChartList.setActivityVo(new ActivityVo());//设置优惠活动为空
shopChartList.setCouMoney(0F);//设置优惠金额为0
ServletActionContext.getRequest().getSession().setAttribute("shopChart",shopChartList);
this.joinActivity();
count = 0;
money = 0F;
return "back";
}
private int addId;
private int colorId_;
private int sizeId_;
private int count_;
public void setCount_(int count_) {
this.count_ = count_;
}
public void setAddId(int addId) {
this.addId = addId;
}
public void setColorId_(int colorId_) {
this.colorId_ = colorId_;
}
public void setSizeId_(int sizeId_) {
this.sizeId_ = sizeId_;
}
private int activityId_;
public void setActivityId_(int activityId_) {
this.activityId_ = activityId_;
}
private String delId;
private String colorId;
private String sizeId;
public void setDelId(String delId) {
this.delId = delId;
}
public void setColorId(String colorId) {
this.colorId = colorId;
}
public void setSizeId(String sizeId) {
this.sizeId = sizeId;
}
public void setActivityService(ActivityService activityService) {
this.activityService = activityService;
}
public void setActivityCenterService(
IActivityCenterService activityCenterService) {
this.activityCenterService = activityCenterService;
}
public void setPid(int pid) {
this.pid = pid;
}
public void setService(IPCSService service) {
this.service = service;
}
public void setProductservice(IProductService productservice) {
this.productservice = productservice;
}
//-------------------------------------------------------------
/**
* 立即结算
* @return
* @throws Exception
*/
public String joinShopCharthidden() throws Exception {
PCSVo pcsvo = service.queryPCSById(pid);
shopChartList = (Cart) ServletActionContext.getRequest().getSession().getAttribute("shopChart");
if(shopChartList == null){
shopChartList = new Cart();
}
if (shopChartList.getShopChartList().size() > 0) {
for (PCSVo pv : shopChartList.getShopChartList()) {
if (pcsvo.getProductVO().getProductId().equals(pv.getProductVO().getProductId())) {
if(pcsvo.getColorVo().getColorId().equals(pv.getColorVo().getColorId())){
if(pcsvo.getSizeVo().getSizeId().equals(pv.getSizeVo().getSizeId())){
if(pv.getWithName() == null){
pv.setCount(pv.getCount() + buyCount);// 商品的id、颜色、尺码都相同则将数量加 buyCount, 并且 搭配名称应为空
flag = false;//说明当前商品在购物车中
break;
}
}
}
}
}
if(flag){ //如果当前商品不存在购物车中则添加
pcsvo.setCount(buyCount);//购买数量默认为buyCount
shopChartList.getShopChartList().add(pcsvo);
}
}else{
pcsvo.setCount(buyCount);//购买数量默认为buyCount
shopChartList.getShopChartList().add(pcsvo);
}
if (shopChartList.getShopChartList().size() > 0) {
for(PCSVo pv : shopChartList.getShopChartList()){
count += pv.getCount() == null ? 0 : pv.getCount();
if(pv.getWithName() != null){
money += pv.getCount() * (pv.getWithPrice() == null ? 1 : pv.getWithPrice());
}else{
money += pv.getCount() * pv.getProductVO().getPromotionPrice();
}
}
}else{
count = 0;
money = 0F;
}
shopChartList.setTotalCount(count);
shopChartList.setTotalMoney(money);
ServletActionContext.getRequest().getSession().setAttribute("shopChart", shopChartList);
this.joinActivity();
flag = true;//还原状态
count = 0;
money = 0F;
return "addressback";
}}