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> ... 
随机推荐
- edtftpj让Java上传FTP文件支持断点续传
			在用Java实现FTP上传文件功能时,特别是上传大文件的时候,可以需要这样的功能:程序在上传的过程中意外终止了,文件传了一大半,想从断掉了地方继续传:或者想做类似迅雷下载类似的功能,文件太大,今天传一 ... 
- ThinkPHP 中M方法和D方法详解----转载
			转载的地址,http://blog.163.com/litianyichuanqi@126/blog/static/115979441201223043452383/ 自己学到这里的时候,不能清除的分 ... 
- C# - Dbhelp
			dbhelp.cs using System; using System.Data; using System.Data.Common; using System.Configuration; pub ... 
- Lucene搜索方法总结
			转自:summerbell http://www.iteye.com/topic/569358 1.多字段搜索 使用 multifieldqueryparser 可以指定多个搜索字段. query q ... 
- Xampp 添加 SSL
			我的 XAMPP 没有找到这句话 ,直接添加 extension=php_openssl.dll 大概988行另外,需要配置 httpd-ssl.conf 文件(*\xampp\apache\con ... 
- Apache Storm技术实战之1 -- WordCountTopology
			欢迎转载,转载请注意出处,徽沪一郎. “源码走读系列”从代码层面分析了storm的具体实现,接下来通过具体的实例来说明storm的使用.因为目前storm已经正式迁移到Apache,文章系列也由twi ... 
- Gmail 启用 POP 标准配置说明:
			接收邮件 (POP3) 服务器 - 要求 SSL:pop.gmail.com使用 SSL:是端口:995 发送邮件 (SMTP) 服务器 - 要求 TLS 或 SSL:smtp.gmail.com使用 ... 
- oracle sqlplus常用命令
			登录到sqlplus sqlplus user/pwd@dbname 不登录使用 sqlplus /nolog 查看当前登录用户 show user; 更改用户密码 ALTER USER USER I ... 
- HTML: Css初始化
			相同的元素, 如ul>li,body等元素在不同的瀏覽器下被渲染的效果不同(各個瀏覽器對這些元素的border,margin,padding,font-size等等的初始值不同), 要讓他們表現 ... 
- endsWith和startsWith同样效果其他形式的写法(2016.1.12)
			//判断以什么开始startWith str = "abcdef"; //用其他的形式写的startsWith if(str.indexOf("abc")==0 ... 
