use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class PersistableOrderPopulator method populate.
@Override
public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(productService, "productService must be set");
Validate.notNull(digitalProductService, "digitalProductService must be set");
Validate.notNull(productAttributeService, "productAttributeService must be set");
Validate.notNull(customerService, "customerService must be set");
Validate.notNull(countryService, "countryService must be set");
Validate.notNull(zoneService, "zoneService must be set");
Validate.notNull(currencyService, "currencyService must be set");
try {
Map<String, Country> countriesMap = countryService.getCountriesMap(language);
Map<String, Zone> zonesMap = zoneService.getZones(language);
/**
* customer *
*/
PersistableCustomer customer = source.getCustomer();
if (customer != null) {
if (customer.getId() != null && customer.getId() > 0) {
Customer modelCustomer = customerService.getById(customer.getId());
if (modelCustomer == null) {
throw new ConversionException("Customer id " + customer.getId() + " does not exists");
}
if (modelCustomer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Customer id " + customer.getId() + " does not exists for store " + store.getCode());
}
target.setCustomerId(modelCustomer.getId());
target.setBilling(modelCustomer.getBilling());
target.setDelivery(modelCustomer.getDelivery());
target.setCustomerEmailAddress(source.getCustomer().getEmailAddress());
}
}
target.setLocale(LocaleUtils.getLocale(store));
CreditCard creditCard = source.getCreditCard();
if (creditCard != null) {
String maskedNumber = CreditCardUtils.maskCardNumber(creditCard.getCcNumber());
creditCard.setCcNumber(maskedNumber);
target.setCreditCard(creditCard);
}
Currency currency = null;
try {
currency = currencyService.getByCode(source.getCurrency());
} catch (Exception e) {
throw new ConversionException("Currency not found for code " + source.getCurrency());
}
if (currency == null) {
throw new ConversionException("Currency not found for code " + source.getCurrency());
}
target.setCurrency(currency);
target.setDatePurchased(source.getDatePurchased());
// target.setCurrency(store.getCurrency());
target.setCurrencyValue(new BigDecimal(0));
target.setMerchant(store);
target.setStatus(source.getOrderStatus());
target.setPaymentModuleCode(source.getPaymentModule());
target.setPaymentType(source.getPaymentType());
target.setShippingModuleCode(source.getShippingModule());
target.setCustomerAgreement(source.isCustomerAgreed());
target.setConfirmedAddress(source.isConfirmedAddress());
if (source.getPreviousOrderStatus() != null) {
List<OrderStatus> orderStatusList = source.getPreviousOrderStatus();
for (OrderStatus status : orderStatusList) {
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(status);
statusHistory.setOrder(target);
target.getOrderHistory().add(statusHistory);
}
}
if (!StringUtils.isBlank(source.getComments())) {
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(null);
statusHistory.setOrder(target);
statusHistory.setComments(source.getComments());
target.getOrderHistory().add(statusHistory);
}
List<PersistableOrderProduct> products = source.getOrderProductItems();
if (CollectionUtils.isEmpty(products)) {
throw new ConversionException("Requires at least 1 PersistableOrderProduct");
}
com.salesmanager.shop.populator.order.PersistableOrderProductPopulator orderProductPopulator = new PersistableOrderProductPopulator();
orderProductPopulator.setProductAttributeService(productAttributeService);
orderProductPopulator.setProductService(productService);
orderProductPopulator.setDigitalProductService(digitalProductService);
for (PersistableOrderProduct orderProduct : products) {
OrderProduct modelOrderProduct = new OrderProduct();
orderProductPopulator.populate(orderProduct, modelOrderProduct, store, language);
target.getOrderProducts().add(modelOrderProduct);
}
List<OrderTotal> orderTotals = source.getTotals();
if (CollectionUtils.isNotEmpty(orderTotals)) {
for (OrderTotal total : orderTotals) {
com.salesmanager.core.model.order.OrderTotal totalModel = new com.salesmanager.core.model.order.OrderTotal();
totalModel.setModule(total.getModule());
totalModel.setOrder(target);
totalModel.setOrderTotalCode(total.getCode());
totalModel.setTitle(total.getTitle());
totalModel.setValue(total.getValue());
target.getOrderTotal().add(totalModel);
}
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class PersistableCustomerReviewPopulator method populate.
@Override
public CustomerReview populate(PersistableCustomerReview source, CustomerReview target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(customerService, "customerService cannot be null");
Validate.notNull(languageService, "languageService cannot be null");
Validate.notNull(source.getRating(), "Rating cannot bot be null");
try {
if (target == null) {
target = new CustomerReview();
}
if (source.getDate() == null) {
String date = DateUtil.formatDate(new Date());
source.setDate(date);
}
target.setReviewDate(DateUtil.getDate(source.getDate()));
if (source.getId() != null && source.getId().longValue() == 0) {
source.setId(null);
} else {
target.setId(source.getId());
}
Customer reviewer = customerService.getById(source.getCustomerId());
Customer reviewed = customerService.getById(source.getReviewedCustomer());
target.setReviewRating(source.getRating());
target.setCustomer(reviewer);
target.setReviewedCustomer(reviewed);
Language lang = languageService.getByCode(language.getCode());
if (lang == null) {
throw new ConversionException("Invalid language code, use iso codes (en, fr ...)");
}
CustomerReviewDescription description = new CustomerReviewDescription();
description.setDescription(source.getDescription());
description.setLanguage(lang);
description.setName("-");
description.setCustomerReview(target);
Set<CustomerReviewDescription> descriptions = new HashSet<CustomerReviewDescription>();
descriptions.add(description);
target.setDescriptions(descriptions);
} catch (Exception e) {
throw new ConversionException("Cannot populate CustomerReview", e);
}
return target;
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method requestPasswordReset.
@Override
public void requestPasswordReset(String customerName, String customerContextPath, MerchantStore store, Language language) {
try {
// get customer by user name
Customer customer = customerService.getByNick(customerName, store.getId());
if (customer == null) {
throw new ResourceNotFoundException("Customer [" + customerName + "] not found for store [" + store.getCode() + "]");
}
// generates unique token
String token = UUID.randomUUID().toString();
Date expiry = DateUtil.addDaysToCurrentDate(2);
CredentialsReset credsRequest = new CredentialsReset();
credsRequest.setCredentialsRequest(token);
credsRequest.setCredentialsRequestExpiry(expiry);
customer.setCredentialsResetRequest(credsRequest);
customerService.saveOrUpdate(customer);
// reset password link
// this will build http | https ://domain/contextPath
String baseUrl = filePathUtils.buildBaseUrl(customerContextPath, store);
// need to add link to controller receiving user reset password
// request
String customerResetLink = new StringBuilder().append(baseUrl).append(String.format(resetCustomerLink, store.getCode(), token)).toString();
resetPasswordRequest(customer, customerResetLink, store, lamguageService.toLocale(language, store));
} catch (Exception e) {
throw new ServiceRuntimeException("Error while executing resetPassword request", e);
}
/**
* User sends username (unique in the system)
*
* UserNameEntity will be the following { userName: "test@test.com" }
*
* The system retrieves user using userName (username is unique) if user
* exists, system sends an email with reset password link
*
* How to retrieve a User from userName
*
* userFacade.findByUserName
*
* How to send an email
*
* How to generate a token
*
* Generate random token
*
* Calculate token expiration date
*
* Now + 48 hours
*
* Update User in the database with token
*
* Send reset token email
*/
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method updateAddress.
@Override
public void updateAddress(Long userId, MerchantStore merchantStore, Address address, final Language language) throws Exception {
Customer customerModel = customerService.getById(userId);
Map<String, Country> countriesMap = countryService.getCountriesMap(language);
Country country = countriesMap.get(address.getCountry());
if (customerModel == null) {
LOG.error("Customer with ID {} does not exists..", userId);
// throw new CustomerNotFoundException( "customer with given id does not exists" );
throw new Exception("customer with given id does not exists");
}
if (address.isBillingAddress()) {
LOG.info("updating customer billing address..");
PersistableCustomerBillingAddressPopulator billingAddressPopulator = new PersistableCustomerBillingAddressPopulator();
customerModel = billingAddressPopulator.populate(address, customerModel, merchantStore, merchantStore.getDefaultLanguage());
customerModel.getBilling().setCountry(country);
if (StringUtils.isNotBlank(address.getZone())) {
Zone zone = zoneService.getByCode(address.getZone());
if (zone == null) {
throw new ConversionException("Unsuported zone code " + address.getZone());
}
customerModel.getBilling().setZone(zone);
customerModel.getBilling().setState(null);
} else {
customerModel.getBilling().setZone(null);
}
} else {
LOG.info("updating customer shipping address..");
PersistableCustomerShippingAddressPopulator shippingAddressPopulator = new PersistableCustomerShippingAddressPopulator();
customerModel = shippingAddressPopulator.populate(address, customerModel, merchantStore, merchantStore.getDefaultLanguage());
customerModel.getDelivery().setCountry(country);
if (StringUtils.isNotBlank(address.getZone())) {
Zone zone = zoneService.getByCode(address.getZone());
if (zone == null) {
throw new ConversionException("Unsuported zone code " + address.getZone());
}
customerModel.getDelivery().setZone(zone);
customerModel.getDelivery().setState(null);
} else {
customerModel.getDelivery().setZone(null);
}
}
// same update address with customer model
this.customerService.saveOrUpdate(customerModel);
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method registerCustomer.
@Override
public PersistableCustomer registerCustomer(final PersistableCustomer customer, final MerchantStore merchantStore, Language language) throws Exception {
LOG.info("Starting customer registration process..");
if (userExist(customer.getUserName())) {
throw new UserAlreadyExistException("User already exist");
}
Customer customerModel = getCustomerModel(customer, merchantStore, language);
if (customerModel == null) {
LOG.equals("Unable to create customer in system");
// throw new CustomerRegistrationException( "Unable to register customer" );
throw new Exception("Unable to register customer");
}
LOG.info("About to persist customer to database.");
customerService.saveOrUpdate(customerModel);
LOG.info("Returning customer data to controller..");
// return customerEntityPoulator(customerModel,merchantStore);
customer.setId(customerModel.getId());
return customer;
}
Aggregations