use of com.salesmanager.shop.model.customer.ReadableCustomer in project shopizer by shopizer-ecommerce.
the class ReadableCustomerReviewPopulator method populate.
@Override
public ReadableCustomerReview populate(CustomerReview source, ReadableCustomerReview target, MerchantStore store, Language language) throws ConversionException {
try {
if (target == null) {
target = new ReadableCustomerReview();
}
if (source.getReviewDate() != null) {
target.setDate(DateUtil.formatDate(source.getReviewDate()));
}
ReadableCustomer reviewed = new ReadableCustomer();
reviewed.setId(source.getReviewedCustomer().getId());
reviewed.setFirstName(source.getReviewedCustomer().getBilling().getFirstName());
reviewed.setLastName(source.getReviewedCustomer().getBilling().getLastName());
target.setId(source.getId());
target.setCustomerId(source.getCustomer().getId());
target.setReviewedCustomer(reviewed);
target.setRating(source.getReviewRating());
target.setReviewedCustomer(reviewed);
target.setCustomerId(source.getCustomer().getId());
Set<CustomerReviewDescription> descriptions = source.getDescriptions();
if (CollectionUtils.isNotEmpty(descriptions)) {
CustomerReviewDescription description = null;
if (descriptions.size() > 1) {
for (CustomerReviewDescription desc : descriptions) {
if (desc.getLanguage().getCode().equals(language.getCode())) {
description = desc;
break;
}
}
} else {
description = descriptions.iterator().next();
}
if (description != null) {
target.setDescription(description.getDescription());
target.setLanguage(description.getLanguage().getCode());
}
}
} catch (Exception e) {
throw new ConversionException("Cannot populate ReadableCustomerReview", e);
}
return target;
}
use of com.salesmanager.shop.model.customer.ReadableCustomer in project shopizer by shopizer-ecommerce.
the class ReadableShopOrderPopulator method populate.
@Override
public ReadableShopOrder populate(ShopOrder source, ReadableShopOrder target, MerchantStore store, Language language) throws ConversionException {
try {
ReadableCustomer customer = new ReadableCustomer();
PersistableCustomer persistableCustomer = source.getCustomer();
customer.setEmailAddress(persistableCustomer.getEmailAddress());
if (persistableCustomer.getBilling() != null) {
Address address = new Address();
address.setCity(persistableCustomer.getBilling().getCity());
address.setCompany(persistableCustomer.getBilling().getCompany());
address.setFirstName(persistableCustomer.getBilling().getFirstName());
address.setLastName(persistableCustomer.getBilling().getLastName());
address.setPostalCode(persistableCustomer.getBilling().getPostalCode());
address.setPhone(persistableCustomer.getBilling().getPhone());
if (persistableCustomer.getBilling().getCountry() != null) {
address.setCountry(persistableCustomer.getBilling().getCountry());
}
if (persistableCustomer.getBilling().getZone() != null) {
address.setZone(persistableCustomer.getBilling().getZone());
}
customer.setBilling(address);
}
if (persistableCustomer.getDelivery() != null) {
Address address = new Address();
address.setCity(persistableCustomer.getDelivery().getCity());
address.setCompany(persistableCustomer.getDelivery().getCompany());
address.setFirstName(persistableCustomer.getDelivery().getFirstName());
address.setLastName(persistableCustomer.getDelivery().getLastName());
address.setPostalCode(persistableCustomer.getDelivery().getPostalCode());
address.setPhone(persistableCustomer.getDelivery().getPhone());
if (persistableCustomer.getDelivery().getCountry() != null) {
address.setCountry(persistableCustomer.getDelivery().getCountry());
}
if (persistableCustomer.getDelivery().getZone() != null) {
address.setZone(persistableCustomer.getDelivery().getZone());
}
customer.setDelivery(address);
}
// TODO if ship to billing enabled, set delivery = billing
/* if(persistableCustomer.getAttributes()!=null) {
for(PersistableCustomerAttribute attribute : persistableCustomer.getAttributes()) {
ReadableCustomerAttribute readableAttribute = new ReadableCustomerAttribute();
readableAttribute.setId(attribute.getId());
ReadableCustomerOption option = new ReadableCustomerOption();
option.setId(attribute.getCustomerOption().getId());
option.setCode(attribute.getCustomerOption());
CustomerOptionDescription d = new CustomerOptionDescription();
d.setDescription(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getDescription());
d.setName(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getName());
option.setDescription(d);
readableAttribute.setCustomerOption(option);
ReadableCustomerOptionValue optionValue = new ReadableCustomerOptionValue();
optionValue.setId(attribute.getCustomerOptionValue().getId());
CustomerOptionValueDescription vd = new CustomerOptionValueDescription();
vd.setDescription(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getDescription());
vd.setName(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getName());
optionValue.setCode(attribute.getCustomerOptionValue().getCode());
optionValue.setDescription(vd);
readableAttribute.setCustomerOptionValue(optionValue);
customer.getAttributes().add(readableAttribute);
}
}*/
target.setCustomer(customer);
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.shop.model.customer.ReadableCustomer in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method create.
@Override
public ReadableCustomer create(PersistableCustomer customer, MerchantStore store, Language language) {
Validate.notNull(customer, "Customer cannot be null");
Validate.notNull(customer.getEmailAddress(), "Customer email address is required");
// set customer user name
customer.setUserName(customer.getEmailAddress());
if (userExist(customer.getUserName())) {
throw new ServiceRuntimeException("User already exist");
}
// end user exists
Customer customerToPopulate = convertPersistableCustomerToCustomer(customer, store);
try {
setCustomerModelDefaultProperties(customerToPopulate, store);
} catch (Exception e) {
throw new ServiceRuntimeException("Cannot set default customer properties", e);
}
saveCustomer(customerToPopulate);
customer.setId(customerToPopulate.getId());
notifyNewCustomer(customer, store, customerToPopulate.getDefaultLanguage());
// convert to readable
return convertCustomerToReadableCustomer(customerToPopulate, store, language);
}
use of com.salesmanager.shop.model.customer.ReadableCustomer in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method updateAddress.
@Override
public void updateAddress(String userName, PersistableCustomer customer, MerchantStore store) {
ReadableCustomer customerModel = getByUserName(userName, store, store.getDefaultLanguage());
customer.setId(customerModel.getId());
customer.setUserName(userName);
updateAddress(customer, store);
}
use of com.salesmanager.shop.model.customer.ReadableCustomer 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