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