首页>代码>高仿京东商城SSH源代码下载>/京东源码/JingDongSSH/src/com/softeem/jingdong/action/ShoppingCarAction.java
package com.softeem.jingdong.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.softeem.jingdong.entity.ShoppingCarBean;
import com.softeem.jingdong.entity.UsersBean;

/**
 * 购物车 Action
 * @author Administrator
 *
 */
public class ShoppingCarAction extends ActionSupport {

	private static final long serialVersionUID = 5108850816643819815L;
	
	private String[] index;
	
	/**
	 * 删除购物车中的商品信息
	 * @return
	 */
	public String deleteGoods(){
		
		//获取用户 购物车集合 
		ShoppingCarBean shoppingCar = ((UsersBean)ActionContext.getContext().getSession().get("users")).getShoppingCar();
		
		for(int i=index.length - 1;i>=0;i--){
			
			//当前索引编号
			int j = Integer.parseInt( index[i] );
			
			//获取删除商品的单价
			double price = shoppingCar.getList().get(j).getPrice();
			
			//直接删除商品
			shoppingCar.getList().remove(j);
			
			//修改剩余数量
			shoppingCar.setNumber( shoppingCar.getNumber() - 1 );
			
			//修改剩余价格
			shoppingCar.setSumPrice( shoppingCar.getSumPrice() - price );
		}
			
		return SUCCESS;
	}

	public String[] getIndex() {
		return index;
	}

	public void setIndex(String[] index) {
		this.index = index;
	}
	
}
最近下载更多
baoligeer  LV5 2022年6月6日
任星浩  LV1 2021年11月18日
giantinheart  LV3 2021年5月23日
wusiyin  LV14 2020年12月17日
曾学成  LV2 2020年12月14日
refreshbird  LV1 2020年12月14日
方立亮  LV1 2020年11月6日
渺无人烟  LV11 2020年7月31日
cpemy_abc  LV10 2020年6月9日
远大帅比  LV6 2020年5月19日
最近浏览更多
czx5450  LV16 4月1日
linlin01  LV1 1月2日
2486624997  LV1 2023年12月22日
2385649653  LV7 2023年12月12日
limin123  LV6 2023年11月20日
heqian  LV16 2023年10月31日
zhaozhiqi  LV5 2023年10月21日
微信网友_6680567232876544  LV8 2023年10月10日
mengmeng12323423  LV3 2023年9月8日
543539666  LV7 2023年8月30日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友