use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderRESTController method createOrder.
/**
* This method is for adding order to the system. Generally used for the purpose of migration only
* This method won't process any payment nor create transactions
* @param store
* @param order
* @param request
* @param response
* @return
* @throws Exception
* Use v1 methods
*/
@RequestMapping(value = "/{store}/order", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
@Deprecated
public PersistableOrder createOrder(@PathVariable final String store, @Valid @RequestBody PersistableOrder order, 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;
}
PersistableCustomer cust = order.getCustomer();
if (cust != null) {
Customer customer = new Customer();
/* CustomerPopulator populator = new CustomerPopulator();
populator.setCountryService(countryService);
populator.setCustomerOptionService(customerOptionService);
populator.setCustomerOptionValueService(customerOptionValueService);
populator.setLanguageService(languageService);
populator.setZoneService(zoneService);
populator.setGroupService(groupService);*/
customerPopulator.populate(cust, customer, merchantStore, merchantStore.getDefaultLanguage());
customerService.save(customer);
cust.setId(customer.getId());
}
Order modelOrder = new Order();
PersistableOrderPopulator populator = new PersistableOrderPopulator();
populator.setDigitalProductService(digitalProductService);
populator.setProductAttributeService(productAttributeService);
populator.setProductService(productService);
populator.populate(order, modelOrder, merchantStore, merchantStore.getDefaultLanguage());
orderService.save(modelOrder);
order.setId(modelOrder.getId());
return order;
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderApi method checkout.
/**
* Action for performing a checkout on a given shopping cart
*
* @param id
* @param order
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/auth/cart/{code}/checkout" }, method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableOrderConfirmation checkout(// shopping cart
@PathVariable final String code, // order
@Valid @RequestBody PersistableOrder order, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
try {
Principal principal = request.getUserPrincipal();
String userName = principal.getName();
Customer customer = customerService.getByNick(userName);
if (customer == null) {
response.sendError(401, "Error while performing checkout customer not authorized");
return null;
}
ShoppingCart cart = shoppingCartService.getByCode(code, merchantStore);
if (cart == null) {
throw new ResourceNotFoundException("Cart code " + code + " does not exist");
}
order.setShoppingCartId(cart.getId());
// That is an existing customer purchasing
order.setCustomerId(customer.getId());
Order modelOrder = orderFacade.processOrder(order, customer, merchantStore, language, locale);
Long orderId = modelOrder.getId();
modelOrder.setId(orderId);
return orderFacadeV1.orderConfirmation(modelOrder, customer, merchantStore, language);
} catch (Exception e) {
LOGGER.error("Error while processing checkout", e);
try {
response.sendError(503, "Error while processing checkout " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderShippingApi method shipping.
/**
* Get shipping quote for a given shopping cart
*
* @param id
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/auth/cart/{code}/shipping" }, method = RequestMethod.GET)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableShippingSummary shipping(@PathVariable final String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
try {
Locale locale = request.getLocale();
Principal principal = request.getUserPrincipal();
String userName = principal.getName();
// get customer id
Customer customer = customerService.getByNick(userName);
if (customer == null) {
response.sendError(503, "Error while getting user details to calculate shipping quote");
}
ShoppingCart cart = shoppingCartFacade.getShoppingCartModel(code, merchantStore);
if (cart == null) {
response.sendError(404, "Cart code " + code + " does not exist");
}
if (cart.getCustomerId() == null) {
response.sendError(404, "Cart code " + code + " does not exist for exist for user " + userName);
}
if (cart.getCustomerId().longValue() != customer.getId().longValue()) {
response.sendError(404, "Cart code " + code + " does not exist for exist for user " + userName);
}
ShippingQuote quote = orderFacade.getShippingQuote(customer, cart, merchantStore, language);
ShippingSummary summary = orderFacade.getShippingSummary(quote, merchantStore, language);
ReadableShippingSummary shippingSummary = new ReadableShippingSummary();
ReadableShippingSummaryPopulator populator = new ReadableShippingSummaryPopulator();
populator.setPricingService(pricingService);
populator.populate(summary, shippingSummary, merchantStore, language);
List<ShippingOption> options = quote.getShippingOptions();
if (!CollectionUtils.isEmpty(options)) {
for (ShippingOption shipOption : options) {
StringBuilder moduleName = new StringBuilder();
moduleName.append("module.shipping.").append(shipOption.getShippingModuleCode());
String carrier = messages.getMessage(moduleName.toString(), new String[] { merchantStore.getStorename() }, locale);
String note = messages.getMessage(moduleName.append(".note").toString(), locale, "");
shipOption.setDescription(carrier);
shipOption.setNote(note);
// option name
if (!StringUtils.isBlank(shipOption.getOptionCode())) {
// try to get the translate
StringBuilder optionCodeBuilder = new StringBuilder();
try {
optionCodeBuilder.append("module.shipping.").append(shipOption.getShippingModuleCode());
String optionName = messages.getMessage(optionCodeBuilder.toString(), locale);
shipOption.setOptionName(optionName);
} catch (Exception e) {
// label not found
LOGGER.warn("No shipping code found for " + optionCodeBuilder.toString());
}
}
}
shippingSummary.setShippingOptions(options);
}
return shippingSummary;
} catch (Exception e) {
LOGGER.error("Error while getting shipping quote", e);
try {
response.sendError(503, "Error while getting shipping quote" + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderShippingApi method shipping.
/**
* Get shipping quote based on postal code
* @param code
* @param address
* @param merchantStore
* @param language
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/cart/{code}/shipping" }, method = RequestMethod.POST)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableShippingSummary shipping(@PathVariable final String code, @RequestBody AddressLocation address, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
Locale locale = request.getLocale();
ShoppingCart cart = shoppingCartFacade.getShoppingCartModel(code, merchantStore);
if (cart == null) {
response.sendError(404, "Cart id " + code + " does not exist");
}
Delivery addr = new Delivery();
addr.setPostalCode(address.getPostalCode());
Country c = countryService.getByCode(address.getCountryCode());
if (c == null) {
c = merchantStore.getCountry();
}
addr.setCountry(c);
Customer temp = new Customer();
temp.setAnonymous(true);
temp.setDelivery(addr);
ShippingQuote quote = orderFacade.getShippingQuote(temp, cart, merchantStore, language);
ShippingSummary summary = orderFacade.getShippingSummary(quote, merchantStore, language);
ReadableShippingSummary shippingSummary = new ReadableShippingSummary();
ReadableShippingSummaryPopulator populator = new ReadableShippingSummaryPopulator();
populator.setPricingService(pricingService);
populator.populate(summary, shippingSummary, merchantStore, language);
List<ShippingOption> options = quote.getShippingOptions();
if (!CollectionUtils.isEmpty(options)) {
for (ShippingOption shipOption : options) {
StringBuilder moduleName = new StringBuilder();
moduleName.append("module.shipping.").append(shipOption.getShippingModuleCode());
String carrier = messages.getMessage(moduleName.toString(), new String[] { merchantStore.getStorename() }, locale);
String note = messages.getMessage(moduleName.append(".note").toString(), locale, "");
shipOption.setDescription(carrier);
shipOption.setNote(note);
// option name
if (!StringUtils.isBlank(shipOption.getOptionCode())) {
// try to get the translate
StringBuilder optionCodeBuilder = new StringBuilder();
try {
optionCodeBuilder.append("module.shipping.").append(shipOption.getShippingModuleCode());
String optionName = messages.getMessage(optionCodeBuilder.toString(), new String[] { merchantStore.getStorename() }, locale);
shipOption.setOptionName(optionName);
} catch (Exception e) {
// label not found
LOGGER.warn("No shipping code found for " + optionCodeBuilder.toString());
}
}
}
shippingSummary.setShippingOptions(options);
}
return shippingSummary;
} catch (Exception e) {
LOGGER.error("Error while getting shipping quote", e);
try {
response.sendError(503, "Error while getting shipping quote" + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderApi method list.
/**
* List orders for authenticated customers
*
* @param start
* @param count
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = { "/auth/orders" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "string", defaultValue = "en") })
public ReadableOrderList list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "count", required = false) Integer count, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) throws Exception {
Principal principal = request.getUserPrincipal();
String userName = principal.getName();
Customer customer = customerService.getByNick(userName);
if (customer == null) {
response.sendError(401, "Error while listing orders, customer not authorized");
return null;
}
if (page == null) {
page = new Integer(0);
}
if (count == null) {
count = new Integer(100);
}
ReadableCustomer readableCustomer = new ReadableCustomer();
ReadableCustomerPopulator customerPopulator = new ReadableCustomerPopulator();
customerPopulator.populate(customer, readableCustomer, merchantStore, language);
ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, customer, page, count, language);
if (returnList == null) {
returnList = new ReadableOrderList();
}
List<ReadableOrder> orders = returnList.getOrders();
if (!CollectionUtils.isEmpty(orders)) {
for (ReadableOrder order : orders) {
order.setCustomer(readableCustomer);
}
}
return returnList;
}
Aggregations