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