use of com.salesmanager.shop.model.order.ReadableOrderTotalSummary in project shopizer by shopizer-ecommerce.
the class ReadableOrderSummaryPopulator method populate.
@Override
public ReadableOrderTotalSummary populate(OrderTotalSummary source, ReadableOrderTotalSummary target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(pricingService, "PricingService must be set");
Validate.notNull(messages, "LabelUtils must be set");
if (target == null) {
target = new ReadableOrderTotalSummary();
}
try {
if (source.getSubTotal() != null) {
target.setSubTotal(pricingService.getDisplayAmount(source.getSubTotal(), store));
}
if (source.getTaxTotal() != null) {
target.setTaxTotal(pricingService.getDisplayAmount(source.getTaxTotal(), store));
}
if (source.getTotal() != null) {
target.setTotal(pricingService.getDisplayAmount(source.getTotal(), store));
}
if (!CollectionUtils.isEmpty(source.getTotals())) {
ReadableOrderTotalPopulator orderTotalPopulator = new ReadableOrderTotalPopulator();
orderTotalPopulator.setMessages(messages);
orderTotalPopulator.setPricingService(pricingService);
for (OrderTotal orderTotal : source.getTotals()) {
ReadableOrderTotal t = new ReadableOrderTotal();
orderTotalPopulator.populate(orderTotal, t, store, language);
target.getTotals().add(t);
}
}
} catch (Exception e) {
LOGGER.error("Error during amount formatting " + e.getMessage());
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.shop.model.order.ReadableOrderTotalSummary in project shopizer by shopizer-ecommerce.
the class OrderTotalApi method calculateTotal.
/**
* Public api
* @param id
* @param quote
* @param merchantStore
* @param language
* @param response
* @return
*/
@RequestMapping(value = { "/cart/{code}/total" }, method = RequestMethod.GET)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableOrderTotalSummary calculateTotal(@PathVariable final String code, @RequestParam(value = "quote", required = false) Long quote, @ApiIgnore MerchantStore merchantStore, // possible postal code, province and country
@ApiIgnore Language language, HttpServletResponse response) {
try {
ShoppingCart shoppingCart = shoppingCartFacade.getShoppingCartModel(code, merchantStore);
if (shoppingCart == null) {
response.sendError(404, "Cart code " + code + " does not exist");
return null;
}
ShippingSummary shippingSummary = null;
// get shipping quote if asked for
if (quote != null) {
shippingSummary = shippingQuoteService.getShippingSummary(quote, merchantStore);
}
OrderTotalSummary orderTotalSummary = null;
OrderSummary orderSummary = new OrderSummary();
orderSummary.setShippingSummary(shippingSummary);
List<ShoppingCartItem> itemsSet = new ArrayList<ShoppingCartItem>(shoppingCart.getLineItems());
orderSummary.setProducts(itemsSet);
orderTotalSummary = orderService.caculateOrderTotal(orderSummary, merchantStore, language);
ReadableOrderTotalSummary returnSummary = new ReadableOrderTotalSummary();
ReadableOrderSummaryPopulator populator = new ReadableOrderSummaryPopulator();
populator.setMessages(messages);
populator.setPricingService(pricingService);
populator.populate(orderTotalSummary, returnSummary, merchantStore, language);
return returnSummary;
} catch (Exception e) {
LOGGER.error("Error while calculating order summary", e);
try {
response.sendError(503, "Error while calculating order summary " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.shop.model.order.ReadableOrderTotalSummary in project shopizer by shopizer-ecommerce.
the class OrderTotalApi method payment.
/**
* This service calculates order total for a given shopping cart This method takes in
* consideration any applicable sales tax An optional request parameter accepts a quote id that
* was received using shipping api
*
* @param quote
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/auth/cart/{id}/total" }, method = RequestMethod.GET)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableOrderTotalSummary payment(@PathVariable final Long id, @RequestParam(value = "quote", required = false) Long quote, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
try {
Principal principal = request.getUserPrincipal();
String userName = principal.getName();
Customer customer = customerService.getByNick(userName);
if (customer == null) {
response.sendError(503, "Error while getting user details to calculate shipping quote");
}
ShoppingCart shoppingCart = shoppingCartFacade.getShoppingCartModel(id, merchantStore);
if (shoppingCart == null) {
response.sendError(404, "Cart id " + id + " does not exist");
return null;
}
if (shoppingCart.getCustomerId() == null) {
response.sendError(404, "Cart id " + id + " does not exist for exist for user " + userName);
return null;
}
if (shoppingCart.getCustomerId().longValue() != customer.getId().longValue()) {
response.sendError(404, "Cart id " + id + " does not exist for exist for user " + userName);
return null;
}
ShippingSummary shippingSummary = null;
// get shipping quote if asked for
if (quote != null) {
shippingSummary = shippingQuoteService.getShippingSummary(quote, merchantStore);
}
OrderTotalSummary orderTotalSummary = null;
OrderSummary orderSummary = new OrderSummary();
orderSummary.setShippingSummary(shippingSummary);
List<ShoppingCartItem> itemsSet = new ArrayList<ShoppingCartItem>(shoppingCart.getLineItems());
orderSummary.setProducts(itemsSet);
orderTotalSummary = orderService.caculateOrderTotal(orderSummary, customer, merchantStore, language);
ReadableOrderTotalSummary returnSummary = new ReadableOrderTotalSummary();
ReadableOrderSummaryPopulator populator = new ReadableOrderSummaryPopulator();
populator.setMessages(messages);
populator.setPricingService(pricingService);
populator.populate(orderTotalSummary, returnSummary, merchantStore, language);
return returnSummary;
} catch (Exception e) {
LOGGER.error("Error while calculating order summary", e);
try {
response.sendError(503, "Error while calculating order summary " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
Aggregations