1.

package selleck.web.cart;

import java.io.InputStream;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import lombok.Getter;
import lombok.Setter;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext; import selleck.Core.util.Constants;
import selleck.Core.util.MD5Maker;
import selleck.Core.web.SelleckActionSupport;
import selleck.model.attachment.dao.imp.AttachmentDAOImp;
import selleck.model.cart.dto.CartDTO;
import selleck.model.cart.service.CartService;
import selleck.model.country.dto.CountryDTO;
import selleck.model.country.service.CountryService;
import selleck.model.product.dto.ProductDTO;
import selleck.model.product.dto.SizeDTO;
import selleck.model.product.service.ProductService;
import selleck.model.product.service.SizeService;
import selleck.model.user.dto.UserDTO; import com.opensymphony.xwork2.ActionContext;
@Setter @Getter
public class AddCartAction extends SelleckActionSupport {
private static Logger logger = Logger.getLogger(AddCartAction.class);
private Double shipFee;
private Double shipFeeJudge;
private CartService cartService;
private CountryService countryService;
private ProductService productService;
private SizeService sizeService;
private List<CartDTO> cartDTOs;
private CountryDTO countryDTO;
private InputStream is; public String addCart(){
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
HttpSession httpSession = request.getSession();
Map<String, Object> mapSession = ActionContext.getContext().getSession();
shipFee = new Double(request.getServletContext().getInitParameter(Constants.FEE));
shipFeeJudge = new Double(request.getServletContext().getInitParameter(Constants.FEEJUDGE));
UserDTO user = (UserDTO)mapSession.get(Constants.SESSIONID); //1.判断有没有cookie存在
Cookie[] cookies = request.getCookies();
int j = 0;
String sessionId = null;
String countryCode = null;
if ( null != cookies ) {
for (int i = 0, len = cookies.length; i < len; i++) {
Cookie c = cookies[i];
if (c.getName().equals(cookieName)) { //cookieCartId
sessionId = c.getValue();
j++;
}
if (Constants.COUNTRYCODE.equals(c.getName())) {
countryCode = c.getValue();
j++;
}
if ( j >=2 && null != sessionId && null != countryCode) {
break;
}
}
if ( j == 0) {
Cookie cookie = new Cookie(cookieName, httpSession.getId());
cookie.setMaxAge(360 *24*60 *60 *1000);
cookie.setPath("/");
response.addCookie(cookie);
}
} //2. 取国别
if (countryCode == null) countryCode = getDefaultCountryCode();
countryDTO = countryService.findByCode(countryCode);
for (CartDTO cart : cartDTOs) {
if ( null != user) cart.setUserId(user.getId());
else {
if ( null != sessionId){
cart.setSessionId(sessionId);
} else {
cart.setSessionId(httpSession.getId());
}
}
try{
if ( null != cart.getQuantity() && cart.getQuantity() > 0) {
cart.setSizeId(cart.getSizeId());
cart.setCreateTime(new Timestamp(System.currentTimeMillis()));
SizeDTO sizeDTO = sizeService.findById(cart.getSizeId());
Double temprice = sizeDTO.getPrice(); //单价
if (temprice == 0) {logger.error("Product price is zero exception"); return FAIL;}
cart.setUnitPrice(temprice);
cart.setSubTotal(temprice * cart.getQuantity().intValue());
cartService.create(cart);
}
} catch (Exception e) {
logger.error(e.toString());
}
}
if ( null != user) {
cartDTOs = cartService.list(user.getId());
} else {
cartDTOs = cartService.list(httpSession.getId());
}
return SUCCESS;
}
}

chem01- 添加商品到购物车的更多相关文章

  1. 添加商品到购物车add_to_cart.php(学生笔记)

    <?php session_start();//启动session $goods_id = $_POST['goods_id'];//获取商品id $number = $_POST['num'] ...

  2. jQuery 动画之 添加商品到购物车

    前台页面 <link href="MyCar.css" rel="stylesheet" /> <script src="../jq ...

  3. AI学习吧-购物车-添加商品接口

    create接口流程 需求:向购物车添加商品 流程:写shopping_cart路由--->写ShoppingCart视图函数--->使用Authuser校验用户是否登录--->首先 ...

  4. Flutter实战视频-移动电商-51.购物车_Provide中添加商品

    51.购物车_Provide中添加商品 新加provide的cart.dart页面 引入三个文件.开始写provide类.provide需要用with 进行混入 从prefs里面获取到数据,判断有没有 ...

  5. ssh整合问题总结--在添加商品模块实现图片(文件)的上传

    今天在做毕设(基于SSH的网上商城项目)中碰到了一个文件上传的需求,就是在后台管理员的商品模块中,有一个添加商品,需要将磁盘上的图片上传到tomcat保存图片的指定目录中: 完成这个功能需要两个步,第 ...

  6. GZFramwork快速开发框架演练之会员系统(四)添加商品管理

    1.1:创建表结构 新建三张商品关联的表,表模型如下: 创建SQL语句略 1.2:生成表Model(生成方法见上一节) 1.3:生成tb_ProductType的单结构界面然后添加到项目中 1.4:修 ...

  7. IOS之UI--小实例项目--添加商品和商品名(使用xib文件终结版) + xib相关知识点总结

    添加商品和商品名小项目(使用xib文件终结版) 小贴士:博文末尾有项目源码在百度云备份的下载链接. xib相关知识点总结 01-基本使用 一开始使用xib的时候,如果要使用自定义view的代码,就需要 ...

  8. IOS之UI--小实例项目--添加商品和商品名(纯代码终结版)

    前言:这个小实例项目是完完全全以MJ视频传授的优化方案一步一个思路从零开始敲出代码的,而且每一步都有思路,都有逻辑所以然.敲代码讲究思路,我个人不建议记忆太多东西,反正我记性很差的. 小贴士:文章末尾 ...

  9. 移动商城第八篇【添加商品之基本属性和大字段数据(FCK文本编辑器)】

    添加商品 修改对应的超链接url,controller转发到对应的JSP页面 <a href="${path}/item/toAddItem.do" class=" ...

  10. Vue小案例 之 商品管理------添加商品

    进行添加button,以及商品列表的创建 html: <div class="form-btn"> <button>确认添加</button> ...

随机推荐

  1. 【POJ】1556 The Doors(计算几何基础+spfa)

    http://poj.org/problem?id=1556 首先路径的每条线段一定是端点之间的连线.证明?这是个坑...反正我是随便画了一下图然后就写了.. 然后re是什么节奏?我记得我开够了啊.. ...

  2. oracle系列--第二篇 oracle下载

    对于很多新手来说,包括我之前也是这样,知道oracle数据库,但是就是不知道在哪里下载.有时候,上到oracle官方网站上面都找不到下载的地方. 这不像apache里面那么直接,我们想下载如:tomc ...

  3. Qt OpenCV Support Image Type 支持读写的图像格式

    Qt 支持的图片格式如下: Format Description Qt's support BMP Windows Bitmap Read/write GIF Graphic Interchange ...

  4. php 配置正确的时间

    关于php时区时间错误问题 date 当前时间 时差 当地 本地date_default_timezone_set 之前有一个遗留问题,就是echo date("y-m-d h:i:s&qu ...

  5. 2015寒假ACM训练计划

    1月26号至3月4号 每天给自己一个计划.做有意义的事情,不要浪费时间. 8:00——11:30 acm训练 11:30——13:00 午休 13:00——17:30  acm训练 17:30——18 ...

  6. Oracle11g创建表空间语句

    在plsql工具中执行以下语句,可建立Oracle表空间. /*分为四步 *//*第1步:创建临时表空间  */create temporary tablespace yuhang_temp temp ...

  7. hdu 1116 并查集和欧拉路径

    ---恢复内容开始--- 把它看成是一个图 只是需要欧拉路径就可以了 首尾能连成一条线即可 如果要判断这个图是否连通 得用并查集 在hrbust oj里面看答案学到的方法 不用各种for循环套着判断能 ...

  8. poj2387 初涉最短路

    前两天自学了一点点最短路..看起来很简单的样子... 就去kuangbin的专题找了最简单的一道题练手..然后被自己萌萌的三重for循环超时虐的不要不要的~ 松弛虽然会但是用的十分之不熟练... 代码 ...

  9. hdu1078 记忆化搜索

    /* hdu 1078 QAQ记忆化搜索 其实还是搜索..因为里面开了一个数组这样可以省时间 (dp[x][y]大于0就不用算了直接返回值) */ #include<stdio.h> #i ...

  10. Frenetic Python实验(三)

    实验5 repeater 这个实验在HelloSDNWorld里面做的实验是一样的.HelloSDNWorld 目的:模拟一个有多个端口的中继器. This application implement ...