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> ...
随机推荐
- libtiff4.04
http://www.linuxfromscratch.org/blfs/view/svn/general/libtiff.html 安装方法 : ./configure --prefix=/usr ...
- C#操作XML(读XML,写XML,更新,删除节点,与dataset结合等)【转载】
已知有一个XML文件(bookstore.xml)如下: Corets, Eva 5.95 1.插入节点 往节点中插入一个节点: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
- opengl中拾取操作的实现
opengl采用一种比较复杂的方式来实现拾取操作,即选择模式.选择模式是一种绘制模式,它的基本思想是在一次拾取操作时,系统会根据拾取操作的参数(如鼠标位置)生成一个特定视景体,然后又系统重新绘制场景中 ...
- hdu I NEED A OFFER!
这道题是道很基本的0/1背包的问题,为了使解题很简单一点,可以将题目中要求的最大概率转换成不能录取的最小概率,这样1-dp[n]即为至少有一个offer的最大概率.状态方程 为:dp[j]=min{d ...
- Html - 对话箭头
对话箭头 <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="U ...
- [GE]手动截取当前活动窗口,并且按规则命名(1/2)
Function Take-ScreenShot { <# .SYNOPSIS Used to take a screenshot of the desktop or the active wi ...
- 修改ssh服务端口
第一种: 01假如要改Linux SSH的默认端口(22),那么你只要修改:/etc/ssh/sshd_config中Port 22,这里把22改成自己要设的端口就行了,不过千万别设和现已有的端口相同 ...
- java类的继承
继承就是在一个现有类型的基础上,通过增加新的方法或者重定义已有方法(重写)的方式,产生一个新的类型.继承是面向对 象的三个基本特征--封装.继承.多态的其中之一,我们在使用java时编写的每一个类都是 ...
- jQuery中添加/改变/移除改变CSS样式例子
在jquery中对于div样式操作我们会使用到CSS() removeClass() addClass()方法来操作了,下面我们就整理了几个例子大家一起来看看吧. CSS()方法改变CSS样式 ...
- Apache Spark源码走读之5 -- DStream处理的容错性分析
欢迎转载,转载请注明出处,徽沪一郎,谢谢. 在流数据的处理过程中,为了保证处理结果的可信度(不能多算,也不能漏算),需要做到对所有的输入数据有且仅有一次处理.在Spark Streaming的处理机制 ...