1
22
23 package com.liferay.portlet.shopping.action;
24
25 import com.liferay.portal.kernel.util.ParamUtil;
26 import com.liferay.portal.theme.ThemeDisplay;
27 import com.liferay.portal.util.PortalUtil;
28 import com.liferay.portal.util.WebKeys;
29 import com.liferay.portlet.shopping.model.ShoppingCategory;
30 import com.liferay.portlet.shopping.model.ShoppingCoupon;
31 import com.liferay.portlet.shopping.model.ShoppingItem;
32 import com.liferay.portlet.shopping.model.ShoppingOrder;
33 import com.liferay.portlet.shopping.model.impl.ShoppingCategoryImpl;
34 import com.liferay.portlet.shopping.service.ShoppingCategoryServiceUtil;
35 import com.liferay.portlet.shopping.service.ShoppingCouponServiceUtil;
36 import com.liferay.portlet.shopping.service.ShoppingItemServiceUtil;
37 import com.liferay.portlet.shopping.service.ShoppingOrderServiceUtil;
38
39 import javax.portlet.ActionRequest;
40 import javax.portlet.RenderRequest;
41
42 import javax.servlet.http.HttpServletRequest;
43
44
50 public class ActionUtil {
51
52 public static void getCategory(ActionRequest req) throws Exception {
53 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
54
55 getCategory(httpReq);
56 }
57
58 public static void getCategory(RenderRequest req) throws Exception {
59 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
60
61 getCategory(httpReq);
62 }
63
64 public static void getCategory(HttpServletRequest req) throws Exception {
65 long categoryId = ParamUtil.getLong(req, "categoryId");
66
67 ShoppingCategory category = null;
68
69 if ((categoryId > 0) &&
70 (categoryId != ShoppingCategoryImpl.DEFAULT_PARENT_CATEGORY_ID)) {
71
72 category = ShoppingCategoryServiceUtil.getCategory(categoryId);
73 }
74
75 req.setAttribute(WebKeys.SHOPPING_CATEGORY, category);
76 }
77
78 public static void getCoupon(ActionRequest req) throws Exception {
79 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
80
81 getCoupon(httpReq);
82 }
83
84 public static void getCoupon(RenderRequest req) throws Exception {
85 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
86
87 getCoupon(httpReq);
88 }
89
90 public static void getCoupon(HttpServletRequest req) throws Exception {
91 ThemeDisplay themeDisplay =
92 (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
93
94 long couponId = ParamUtil.getLong(req, "couponId");
95
96 ShoppingCoupon coupon = null;
97
98 if (couponId > 0) {
99 coupon = ShoppingCouponServiceUtil.getCoupon(
100 themeDisplay.getPlid(), couponId);
101 }
102
103 req.setAttribute(WebKeys.SHOPPING_COUPON, coupon);
104 }
105
106 public static void getItem(ActionRequest req) throws Exception {
107 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
108
109 getItem(httpReq);
110 }
111
112 public static void getItem(RenderRequest req) throws Exception {
113 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
114
115 getItem(httpReq);
116 }
117
118 public static void getItem(HttpServletRequest req) throws Exception {
119 long itemId = ParamUtil.getLong(req, "itemId");
120
121 ShoppingItem item = null;
122
123 if (itemId > 0) {
124 item = ShoppingItemServiceUtil.getItem(itemId);
125 }
126
127 req.setAttribute(WebKeys.SHOPPING_ITEM, item);
128 }
129
130 public static void getOrder(ActionRequest req) throws Exception {
131 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
132
133 getOrder(httpReq);
134 }
135
136 public static void getOrder(RenderRequest req) throws Exception {
137 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
138
139 getOrder(httpReq);
140 }
141
142 public static void getOrder(HttpServletRequest req) throws Exception {
143 ThemeDisplay themeDisplay =
144 (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
145
146 long orderId = ParamUtil.getLong(req, "orderId");
147
148 ShoppingOrder order = null;
149
150 if (orderId > 0) {
151 order = ShoppingOrderServiceUtil.getOrder(
152 themeDisplay.getPlid(), orderId);
153 }
154
155 req.setAttribute(WebKeys.SHOPPING_ORDER, order);
156 }
157
158 }