use of com.salesmanager.shop.model.order.v0.ReadableOrderList in project shopizer by shopizer-ecommerce.
the class OrderRESTController method listOrders.
/**
* Get a list of orders
* accept request parameter 'lang' [en,fr...] otherwise store dafault language
* accept request parameter 'start' start index for count
* accept request parameter 'max' maximum number count, otherwise returns all
* @param store
* @param order
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = "/{store}/orders/", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
public ReadableOrderList listOrders(@PathVariable final String store, HttpServletRequest request, HttpServletResponse response) throws Exception {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
if (merchantStore != null) {
if (!merchantStore.getCode().equals(store)) {
merchantStore = null;
}
}
if (merchantStore == null) {
merchantStore = merchantStoreService.getByCode(store);
}
if (merchantStore == null) {
LOGGER.error("Merchant store is null for code " + store);
response.sendError(503, "Merchant store is null for code " + store);
return null;
}
// get additional request parameters for orders
String lang = request.getParameter(Constants.LANG);
String start = request.getParameter(Constants.START);
String max = request.getParameter(Constants.MAX);
int startCount = 0;
int maxCount = 0;
if (StringUtils.isBlank(lang)) {
lang = merchantStore.getDefaultLanguage().getCode();
}
Language language = languageService.getByCode(lang);
if (language == null) {
LOGGER.error("Language is null for code " + lang);
response.sendError(503, "Language is null for code " + lang);
return null;
}
try {
startCount = Integer.parseInt(start);
} catch (Exception e) {
LOGGER.info("Invalid value for start " + start);
}
try {
maxCount = Integer.parseInt(max);
} catch (Exception e) {
LOGGER.info("Invalid value for max " + max);
}
ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, startCount, maxCount, language);
return returnList;
}
use of com.salesmanager.shop.model.order.v0.ReadableOrderList in project shopizer by shopizer-ecommerce.
the class CustomerOrdersController method listOrders.
@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping(value = "/orders.html", method = { RequestMethod.GET, RequestMethod.POST })
public String listOrders(Model model, @RequestParam(value = "page", defaultValue = "1") final int page, HttpServletRequest request, HttpServletResponse response) throws Exception {
LOGGER.info("Fetching orders for current customer");
MerchantStore store = getSessionAttribute(Constants.MERCHANT_STORE, request);
Language language = getSessionAttribute(Constants.LANGUAGE, request);
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
Customer customer = null;
if (auth != null && request.isUserInRole("AUTH_CUSTOMER")) {
customer = customerFacade.getCustomerByUserName(auth.getName(), store);
}
if (customer == null) {
return "redirect:/" + Constants.SHOP_URI;
}
PaginationData paginaionData = createPaginaionData(page, Constants.MAX_ORDERS_PAGE);
ReadableOrderList readable = orderFacade.getReadableOrderList(store, customer, (paginaionData.getOffset() - 1), paginaionData.getPageSize(), language);
model.addAttribute("customerOrders", readable);
if (readable != null) {
model.addAttribute("paginationData", calculatePaginaionData(paginaionData, Constants.MAX_ORDERS_PAGE, readable.getNumber()));
} else {
model.addAttribute("paginationData", null);
}
StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Customer.customerOrders).append(".").append(store.getStoreTemplate());
return template.toString();
}
Aggregations