use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method getShippingQuote.
@Override
public ShippingQuote getShippingQuote(PersistableCustomer persistableCustomer, ShoppingCart cart, ShopOrder order, MerchantStore store, Language language) throws Exception {
// create shipping products
List<ShippingProduct> shippingProducts = shoppingCartService.createShippingProduct(cart);
if (CollectionUtils.isEmpty(shippingProducts)) {
// products are virtual
return null;
}
Customer customer = customerFacade.getCustomerModel(persistableCustomer, store, language);
Delivery delivery = new Delivery();
// adjust shipping and billing
if (order.isShipToBillingAdress() && !order.isShipToDeliveryAddress()) {
Billing billing = customer.getBilling();
String postalCode = billing.getPostalCode();
postalCode = validatePostalCode(postalCode);
delivery.setAddress(billing.getAddress());
delivery.setCompany(billing.getCompany());
delivery.setCity(billing.getCity());
delivery.setPostalCode(billing.getPostalCode());
delivery.setState(billing.getState());
delivery.setCountry(billing.getCountry());
delivery.setZone(billing.getZone());
} else {
delivery = customer.getDelivery();
}
ShippingQuote quote = shippingService.getShippingQuote(cart.getId(), store, delivery, shippingProducts, language);
return quote;
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method calculateOrderTotal.
@Override
public OrderTotalSummary calculateOrderTotal(MerchantStore store, ShopOrder order, Language language) throws Exception {
Customer customer = customerFacade.getCustomerModel(order.getCustomer(), store, language);
OrderTotalSummary summary = calculateOrderTotal(store, customer, order, language);
this.setOrderTotals(order, summary);
return summary;
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method initEmptyCustomer.
@Override
public Customer initEmptyCustomer(MerchantStore store) {
Customer customer = new Customer();
Billing billing = new Billing();
billing.setCountry(store.getCountry());
billing.setZone(store.getZone());
billing.setState(store.getStorestateprovince());
/**
* empty postal code for initial quote *
*/
// billing.setPostalCode(store.getStorepostalcode());
customer.setBilling(billing);
Delivery delivery = new Delivery();
delivery.setCountry(store.getCountry());
delivery.setZone(store.getZone());
delivery.setState(store.getStorestateprovince());
/**
* empty postal code for initial quote *
*/
// delivery.setPostalCode(store.getStorepostalcode());
customer.setDelivery(delivery);
return customer;
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class CustomerReviewServiceImpl method saveOrUpdate.
private void saveOrUpdate(CustomerReview review) throws ServiceException {
Validate.notNull(review, "CustomerReview cannot be null");
Validate.notNull(review.getCustomer(), "CustomerReview.customer cannot be null");
Validate.notNull(review.getReviewedCustomer(), "CustomerReview.reviewedCustomer cannot be null");
// refresh customer
Customer customer = customerService.getById(review.getReviewedCustomer().getId());
// ajust product rating
Integer count = 0;
if (customer.getCustomerReviewCount() != null) {
count = customer.getCustomerReviewCount();
}
BigDecimal averageRating = customer.getCustomerReviewAvg();
if (averageRating == null) {
averageRating = new BigDecimal(0);
}
// get reviews
BigDecimal totalRating = averageRating.multiply(new BigDecimal(count));
totalRating = totalRating.add(new BigDecimal(review.getReviewRating()));
count = count + 1;
double avg = totalRating.doubleValue() / count;
customer.setCustomerReviewAvg(new BigDecimal(avg));
customer.setCustomerReviewCount(count);
super.save(review);
customerService.update(customer);
review.setReviewedCustomer(customer);
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderRESTController method listOrders.
/**
* Get a list of orders for a given customer
* 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/customer/{id}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.ACCEPTED)
@ResponseBody
public ReadableOrderList listOrders(@PathVariable final String store, @PathVariable final Long id, 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);
}
Customer customer = customerService.getById(id);
if (customer == null) {
LOGGER.error("Customer is null for id " + id);
response.sendError(503, "Customer is null for id " + id);
return null;
}
if (customer.getMerchantStore().getId().intValue() != merchantStore.getId().intValue()) {
LOGGER.error("Customer is null for id " + id + " and store id " + store);
response.sendError(503, "Customer is null for id " + id + " and store id " + store);
return null;
}
ReadableOrderList returnList = orderFacade.getReadableOrderList(merchantStore, startCount, maxCount, language);
return returnList;
}
Aggregations