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
49 public class ActionUtil {
50
51 public static void getCategory(ActionRequest actionRequest)
52 throws Exception {
53
54 HttpServletRequest request = PortalUtil.getHttpServletRequest(
55 actionRequest);
56
57 getCategory(request);
58 }
59
60 public static void getCategory(RenderRequest renderRequest)
61 throws Exception {
62
63 HttpServletRequest request = PortalUtil.getHttpServletRequest(
64 renderRequest);
65
66 getCategory(request);
67 }
68
69 public static void getCategory(HttpServletRequest request)
70 throws Exception {
71
72 long categoryId = ParamUtil.getLong(request, "categoryId");
73
74 ShoppingCategory category = null;
75
76 if ((categoryId > 0) &&
77 (categoryId != ShoppingCategoryImpl.DEFAULT_PARENT_CATEGORY_ID)) {
78
79 category = ShoppingCategoryServiceUtil.getCategory(categoryId);
80 }
81
82 request.setAttribute(WebKeys.SHOPPING_CATEGORY, category);
83 }
84
85 public static void getCoupon(ActionRequest actionRequest) throws Exception {
86 HttpServletRequest request = PortalUtil.getHttpServletRequest(
87 actionRequest);
88
89 getCoupon(request);
90 }
91
92 public static void getCoupon(RenderRequest renderRequest) throws Exception {
93 HttpServletRequest request = PortalUtil.getHttpServletRequest(
94 renderRequest);
95
96 getCoupon(request);
97 }
98
99 public static void getCoupon(HttpServletRequest request) throws Exception {
100 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
101 WebKeys.THEME_DISPLAY);
102
103 long couponId = ParamUtil.getLong(request, "couponId");
104
105 ShoppingCoupon coupon = null;
106
107 if (couponId > 0) {
108 coupon = ShoppingCouponServiceUtil.getCoupon(
109 themeDisplay.getPlid(), couponId);
110 }
111
112 request.setAttribute(WebKeys.SHOPPING_COUPON, coupon);
113 }
114
115 public static void getItem(ActionRequest actionRequest) throws Exception {
116 HttpServletRequest request = PortalUtil.getHttpServletRequest(
117 actionRequest);
118
119 getItem(request);
120 }
121
122 public static void getItem(RenderRequest renderRequest) throws Exception {
123 HttpServletRequest request = PortalUtil.getHttpServletRequest(
124 renderRequest);
125
126 getItem(request);
127 }
128
129 public static void getItem(HttpServletRequest request) throws Exception {
130 long itemId = ParamUtil.getLong(request, "itemId");
131
132 ShoppingItem item = null;
133
134 if (itemId > 0) {
135 item = ShoppingItemServiceUtil.getItem(itemId);
136 }
137
138 request.setAttribute(WebKeys.SHOPPING_ITEM, item);
139 }
140
141 public static void getOrder(ActionRequest actionRequest) throws Exception {
142 HttpServletRequest request = PortalUtil.getHttpServletRequest(
143 actionRequest);
144
145 getOrder(request);
146 }
147
148 public static void getOrder(RenderRequest renderRequest) throws Exception {
149 HttpServletRequest request = PortalUtil.getHttpServletRequest(
150 renderRequest);
151
152 getOrder(request);
153 }
154
155 public static void getOrder(HttpServletRequest request) throws Exception {
156 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
157 WebKeys.THEME_DISPLAY);
158
159 long orderId = ParamUtil.getLong(request, "orderId");
160
161 ShoppingOrder order = null;
162
163 if (orderId > 0) {
164 order = ShoppingOrderServiceUtil.getOrder(
165 themeDisplay.getPlid(), orderId);
166 }
167
168 request.setAttribute(WebKeys.SHOPPING_ORDER, order);
169 }
170
171 }