chem01- 添加商品到购物车
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- 添加商品到购物车的更多相关文章
- 添加商品到购物车add_to_cart.php(学生笔记)
<?php session_start();//启动session $goods_id = $_POST['goods_id'];//获取商品id $number = $_POST['num'] ...
- jQuery 动画之 添加商品到购物车
前台页面 <link href="MyCar.css" rel="stylesheet" /> <script src="../jq ...
- AI学习吧-购物车-添加商品接口
create接口流程 需求:向购物车添加商品 流程:写shopping_cart路由--->写ShoppingCart视图函数--->使用Authuser校验用户是否登录--->首先 ...
- Flutter实战视频-移动电商-51.购物车_Provide中添加商品
51.购物车_Provide中添加商品 新加provide的cart.dart页面 引入三个文件.开始写provide类.provide需要用with 进行混入 从prefs里面获取到数据,判断有没有 ...
- ssh整合问题总结--在添加商品模块实现图片(文件)的上传
今天在做毕设(基于SSH的网上商城项目)中碰到了一个文件上传的需求,就是在后台管理员的商品模块中,有一个添加商品,需要将磁盘上的图片上传到tomcat保存图片的指定目录中: 完成这个功能需要两个步,第 ...
- GZFramwork快速开发框架演练之会员系统(四)添加商品管理
1.1:创建表结构 新建三张商品关联的表,表模型如下: 创建SQL语句略 1.2:生成表Model(生成方法见上一节) 1.3:生成tb_ProductType的单结构界面然后添加到项目中 1.4:修 ...
- IOS之UI--小实例项目--添加商品和商品名(使用xib文件终结版) + xib相关知识点总结
添加商品和商品名小项目(使用xib文件终结版) 小贴士:博文末尾有项目源码在百度云备份的下载链接. xib相关知识点总结 01-基本使用 一开始使用xib的时候,如果要使用自定义view的代码,就需要 ...
- IOS之UI--小实例项目--添加商品和商品名(纯代码终结版)
前言:这个小实例项目是完完全全以MJ视频传授的优化方案一步一个思路从零开始敲出代码的,而且每一步都有思路,都有逻辑所以然.敲代码讲究思路,我个人不建议记忆太多东西,反正我记性很差的. 小贴士:文章末尾 ...
- 移动商城第八篇【添加商品之基本属性和大字段数据(FCK文本编辑器)】
添加商品 修改对应的超链接url,controller转发到对应的JSP页面 <a href="${path}/item/toAddItem.do" class=" ...
- Vue小案例 之 商品管理------添加商品
进行添加button,以及商品列表的创建 html: <div class="form-btn"> <button>确认添加</button> ...
随机推荐
- 【BZOJ】1051: [HAOI2006]受欢迎的牛(tarjan)
http://www.lydsy.com/JudgeOnline/problem.php?id=1051 这题还好-1A了..但是前提还是看了题解的 囧.....一开始认为是并查集,oh,不行,,无法 ...
- CentOS目录结构超详细版
最近初学Linux 对linux的目录产生了很多疑问,看到这篇文章,让我顿时对目录有了一个清晰的认识!推荐给大家! ------------------------------------------ ...
- Java中替换HTML标签的方法代码
这篇文章主要介绍了Java中替换HTML标签的方法代码,需要的朋友可以参考下 replaceAll("\\&[a-zA-Z]{0,9};", "").r ...
- Java正则表达式教程
地址:http://www.java3z.com/cwbwebhome/article/article8/Regex/Java.Regex.Tutorial.html#reg0_1
- UIWebView弹出键盘按钮显示中文
UIWebView是一个很常用的视图,一般用来加载网页,比如百度: 点击文本框输入框后,会弹出一个带有toolbar的键盘,toolbar中有3个辅助按钮 有了这3个按钮,是方便很多,但默认是英文的, ...
- tableviewCell折叠状态3
// // LHQDelegateModel.h // 11 - 投资管理 - 李洪强 // // Created by vic fan on 16/4/13. // Copyright © ...
- python的几个常用内置函数
dir()查看属性(函数和数据对象) help()查看具体的帮助文档 id() 用来查看数据对象的地址 split 分隔(str ---> list): >>> s=" ...
- shiyan2
<?xml version="1.0" encoding="ISO-8859-1"?><web-app xmlns="http:// ...
- 交叉报表列头排序时遇到的oracle问题—oracle ORA-12704:字符集不匹配、varchar2转化为nvarchar2字符缺失、case when else后的字符类型要一致
在做交叉报表列头的排序时,遇到这三个问题,下面具体来说一下. 设计的数据库的表结构如图1所示: 图1 要处出来student_name_,s.grade_,s.subject_name_,这三个属性, ...
- Linux提示no crontab for root的解决办法
Linux提示no crontab for root的解决办法 安装crontab:yum install crontabs 说明:/sbin/service crond start //启动服务/s ...