use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method convertPersistableCustomerToCustomer.
private Customer convertPersistableCustomerToCustomer(PersistableCustomer customer, MerchantStore store) {
Customer cust = new Customer();
try {
customerPopulator.populate(customer, cust, store, store.getDefaultLanguage());
} catch (ConversionException e) {
throw new ConversionRuntimeException(e);
}
List<Group> groups = getListOfGroups(GroupType.CUSTOMER);
cust.setGroups(groups);
String password = customer.getPassword();
if (StringUtils.isBlank(password)) {
password = new String(UUID.generateRandomBytes());
customer.setPassword(password);
}
return cust;
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method resetPassword.
@Override
public void resetPassword(String password, String token, String store) {
Validate.notNull(token, "ResetPassword token cannot be null");
Validate.notNull(store, "Store code cannot be null");
Validate.notNull(password, "New password cannot be null");
// reverify
Customer customer = verifyCustomerLink(token, store);
customer.setPassword(passwordEncoder.encode(password));
try {
customerService.save(customer);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while saving customer", e);
}
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method verifyCustomerLink.
private Customer verifyCustomerLink(String token, String store) {
Customer customer = null;
try {
customer = customerService.getByPasswordResetToken(store, token);
if (customer == null) {
throw new ResourceNotFoundException("Customer not fount for store [" + store + "] and token [" + token + "]");
}
} catch (Exception e) {
throw new ServiceRuntimeException("Cannot verify customer token", e);
}
Date tokenExpiry = customer.getCredentialsResetRequest().getCredentialsRequestExpiry();
if (tokenExpiry == null) {
throw new GenericRuntimeException("No expiry date configured for token [" + token + "]");
}
if (!DateUtil.dateBeforeEqualsDate(new Date(), tokenExpiry)) {
throw new GenericRuntimeException("Ttoken [" + token + "] has expired");
}
return customer;
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method orderConfirmation.
@Override
public ReadableOrderConfirmation orderConfirmation(Order order, Customer customer, MerchantStore store, Language language) {
Validate.notNull(order, "Order cannot be null");
Validate.notNull(customer, "Customer cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
ReadableOrderConfirmation orderConfirmation = new ReadableOrderConfirmation();
ReadableCustomer readableCustomer = readableCustomerMapper.convert(customer, store, language);
orderConfirmation.setBilling(readableCustomer.getBilling());
orderConfirmation.setDelivery(readableCustomer.getDelivery());
ReadableTotal readableTotal = new ReadableTotal();
Set<OrderTotal> totals = order.getOrderTotal();
List<ReadableOrderTotal> readableTotals = totals.stream().sorted(Comparator.comparingInt(OrderTotal::getSortOrder)).map(tot -> convertOrderTotal(tot, store, language)).collect(Collectors.toList());
readableTotal.setTotals(readableTotals);
Optional<ReadableOrderTotal> grandTotal = readableTotals.stream().filter(tot -> tot.getCode().equals("order.total.total")).findFirst();
if (grandTotal.isPresent()) {
readableTotal.setGrandTotal(grandTotal.get().getText());
}
orderConfirmation.setTotal(readableTotal);
List<ReadableOrderProduct> products = order.getOrderProducts().stream().map(pr -> convertOrderProduct(pr, store, language)).collect(Collectors.toList());
orderConfirmation.setProducts(products);
if (!StringUtils.isBlank(order.getShippingModuleCode())) {
StringBuilder optionCodeBuilder = new StringBuilder();
try {
optionCodeBuilder.append("module.shipping.").append(order.getShippingModuleCode());
String shippingName = messages.getMessage(optionCodeBuilder.toString(), new String[] { store.getStorename() }, languageService.toLocale(language, store));
orderConfirmation.setShipping(shippingName);
} catch (Exception e) {
// label not found
LOGGER.warn("No shipping code found for " + optionCodeBuilder.toString());
}
}
if (order.getPaymentType() != null) {
orderConfirmation.setPayment(order.getPaymentType().name());
}
/**
* Confirmation may be formatted
*/
orderConfirmation.setId(order.getId());
return orderConfirmation;
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method get.
// facade
@Override
public ReadableShoppingCart get(Optional<String> cart, Long customerId, MerchantStore store, Language language) {
Validate.notNull(customerId, "Customer id cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
try {
// lookup customer
Customer customer = customerService.getById(customerId);
if (customer == null) {
throw new ResourceNotFoundException("No Customer found for id [" + customerId + "]");
}
ShoppingCart cartModel = shoppingCartService.getShoppingCart(customer);
if (cart.isPresent()) {
cartModel = customerFacade.mergeCart(customer, cart.get(), store, language);
}
if (cartModel == null) {
return null;
}
ReadableShoppingCart readableCart = shoppingCartFacade.readableCart(cartModel, store, language);
return readableCart;
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
Aggregations