use of com.salesmanager.shop.model.customer.address.Address in project shopizer by shopizer-ecommerce.
the class PersistableCustomerPopulator method populate.
@Override
public PersistableCustomer populate(Customer source, PersistableCustomer target, MerchantStore store, Language language) throws ConversionException {
try {
if (source.getBilling() != null) {
Address address = new Address();
address.setCity(source.getBilling().getCity());
address.setCompany(source.getBilling().getCompany());
address.setFirstName(source.getBilling().getFirstName());
address.setLastName(source.getBilling().getLastName());
address.setPostalCode(source.getBilling().getPostalCode());
address.setPhone(source.getBilling().getTelephone());
if (source.getBilling().getTelephone() == null) {
address.setPhone(source.getBilling().getTelephone());
}
address.setAddress(source.getBilling().getAddress());
if (source.getBilling().getCountry() != null) {
address.setCountry(source.getBilling().getCountry().getIsoCode());
}
if (source.getBilling().getZone() != null) {
address.setZone(source.getBilling().getZone().getCode());
}
if (source.getBilling().getState() != null) {
address.setStateProvince(source.getBilling().getState());
}
target.setBilling(address);
}
target.setProvider(source.getProvider());
if (source.getCustomerReviewAvg() != null) {
target.setRating(source.getCustomerReviewAvg().doubleValue());
}
if (source.getCustomerReviewCount() != null) {
target.setRatingCount(source.getCustomerReviewCount().intValue());
}
if (source.getDelivery() != null) {
Address address = new Address();
address.setAddress(source.getDelivery().getAddress());
address.setCity(source.getDelivery().getCity());
address.setCompany(source.getDelivery().getCompany());
address.setFirstName(source.getDelivery().getFirstName());
address.setLastName(source.getDelivery().getLastName());
address.setPostalCode(source.getDelivery().getPostalCode());
address.setPhone(source.getDelivery().getTelephone());
if (source.getDelivery().getCountry() != null) {
address.setCountry(source.getDelivery().getCountry().getIsoCode());
}
if (source.getDelivery().getZone() != null) {
address.setZone(source.getDelivery().getZone().getCode());
}
if (source.getDelivery().getState() != null) {
address.setStateProvince(source.getDelivery().getState());
}
target.setDelivery(address);
}
target.setId(source.getId());
target.setEmailAddress(source.getEmailAddress());
if (source.getGender() != null) {
target.setGender(source.getGender().name());
}
if (source.getDefaultLanguage() != null) {
target.setLanguage(source.getDefaultLanguage().getCode());
}
target.setUserName(source.getNick());
target.setStoreCode(store.getCode());
if (source.getDefaultLanguage() != null) {
target.setLanguage(source.getDefaultLanguage().getCode());
} else {
target.setLanguage(store.getDefaultLanguage().getCode());
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.shop.model.customer.address.Address in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method processOrderModel.
/**
* Commit an order
* @param order
* @param customer
* @param transaction
* @param store
* @param language
* @return
* @throws ServiceException
*/
private Order processOrderModel(ShopOrder order, Customer customer, Transaction transaction, MerchantStore store, Language language) throws ServiceException {
try {
if (order.isShipToBillingAdress()) {
// customer shipping is billing
PersistableCustomer orderCustomer = order.getCustomer();
Address billing = orderCustomer.getBilling();
orderCustomer.setDelivery(billing);
}
Order modelOrder = new Order();
modelOrder.setDatePurchased(new Date());
modelOrder.setBilling(customer.getBilling());
modelOrder.setDelivery(customer.getDelivery());
modelOrder.setPaymentModuleCode(order.getPaymentModule());
modelOrder.setPaymentType(PaymentType.valueOf(order.getPaymentMethodType()));
modelOrder.setShippingModuleCode(order.getShippingModule());
modelOrder.setCustomerAgreement(order.isCustomerAgreed());
// set the store
modelOrder.setLocale(LocaleUtils.getLocale(store));
// locale based
// on the
// country for
// order $
// formatting
List<ShoppingCartItem> shoppingCartItems = order.getShoppingCartItems();
Set<OrderProduct> orderProducts = new LinkedHashSet<OrderProduct>();
if (!StringUtils.isBlank(order.getComments())) {
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(OrderStatus.ORDERED);
statusHistory.setOrder(modelOrder);
statusHistory.setDateAdded(new Date());
statusHistory.setComments(order.getComments());
modelOrder.getOrderHistory().add(statusHistory);
}
OrderProductPopulator orderProductPopulator = new OrderProductPopulator();
orderProductPopulator.setDigitalProductService(digitalProductService);
orderProductPopulator.setProductAttributeService(productAttributeService);
orderProductPopulator.setProductService(productService);
String shoppingCartCode = null;
for (ShoppingCartItem item : shoppingCartItems) {
if (shoppingCartCode == null && item.getShoppingCart() != null) {
shoppingCartCode = item.getShoppingCart().getShoppingCartCode();
}
/**
* Before processing order quantity of item must be > 0
*/
Product product = productService.getById(item.getProductId());
if (product == null) {
throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
}
LOGGER.debug("Validate inventory");
for (ProductAvailability availability : product.getAvailabilities()) {
if (availability.getRegion().equals(Constants.ALL_REGIONS)) {
int qty = availability.getProductQuantity();
if (qty < item.getQuantity()) {
throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
}
}
}
OrderProduct orderProduct = new OrderProduct();
orderProduct = orderProductPopulator.populate(item, orderProduct, store, language);
orderProduct.setOrder(modelOrder);
orderProducts.add(orderProduct);
}
modelOrder.setOrderProducts(orderProducts);
OrderTotalSummary summary = order.getOrderTotalSummary();
List<com.salesmanager.core.model.order.OrderTotal> totals = summary.getTotals();
// re-order totals
Collections.sort(totals, new Comparator<com.salesmanager.core.model.order.OrderTotal>() {
public int compare(com.salesmanager.core.model.order.OrderTotal x, com.salesmanager.core.model.order.OrderTotal y) {
if (x.getSortOrder() == y.getSortOrder())
return 0;
return x.getSortOrder() < y.getSortOrder() ? -1 : 1;
}
});
Set<com.salesmanager.core.model.order.OrderTotal> modelTotals = new LinkedHashSet<com.salesmanager.core.model.order.OrderTotal>();
for (com.salesmanager.core.model.order.OrderTotal total : totals) {
total.setOrder(modelOrder);
modelTotals.add(total);
}
modelOrder.setOrderTotal(modelTotals);
modelOrder.setTotal(order.getOrderTotalSummary().getTotal());
// order misc objects
modelOrder.setCurrency(store.getCurrency());
modelOrder.setMerchant(store);
// customer object
orderCustomer(customer, modelOrder, language);
// populate shipping information
if (!StringUtils.isBlank(order.getShippingModule())) {
modelOrder.setShippingModuleCode(order.getShippingModule());
}
String paymentType = order.getPaymentMethodType();
Payment payment = new Payment();
payment.setPaymentType(PaymentType.valueOf(paymentType));
payment.setAmount(order.getOrderTotalSummary().getTotal());
payment.setModuleName(order.getPaymentModule());
payment.setCurrency(modelOrder.getCurrency());
if (order.getPayment() != null && order.getPayment().get("paymentToken") != null) {
// set
// token
String paymentToken = order.getPayment().get("paymentToken");
Map<String, String> paymentMetaData = new HashMap<String, String>();
payment.setPaymentMetaData(paymentMetaData);
paymentMetaData.put("paymentToken", paymentToken);
}
if (PaymentType.CREDITCARD.name().equals(paymentType)) {
payment = new CreditCardPayment();
((CreditCardPayment) payment).setCardOwner(order.getPayment().get("creditcard_card_holder"));
((CreditCardPayment) payment).setCredidCardValidationNumber(order.getPayment().get("creditcard_card_cvv"));
((CreditCardPayment) payment).setCreditCardNumber(order.getPayment().get("creditcard_card_number"));
((CreditCardPayment) payment).setExpirationMonth(order.getPayment().get("creditcard_card_expirationmonth"));
((CreditCardPayment) payment).setExpirationYear(order.getPayment().get("creditcard_card_expirationyear"));
Map<String, String> paymentMetaData = order.getPayment();
payment.setPaymentMetaData(paymentMetaData);
payment.setPaymentType(PaymentType.valueOf(paymentType));
payment.setAmount(order.getOrderTotalSummary().getTotal());
payment.setModuleName(order.getPaymentModule());
payment.setCurrency(modelOrder.getCurrency());
CreditCardType creditCardType = null;
String cardType = order.getPayment().get("creditcard_card_type");
// supported credit cards
if (CreditCardType.AMEX.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.AMEX;
} else if (CreditCardType.VISA.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.VISA;
} else if (CreditCardType.MASTERCARD.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.MASTERCARD;
} else if (CreditCardType.DINERS.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.DINERS;
} else if (CreditCardType.DISCOVERY.name().equalsIgnoreCase(cardType)) {
creditCardType = CreditCardType.DISCOVERY;
}
((CreditCardPayment) payment).setCreditCard(creditCardType);
if (creditCardType != null) {
CreditCard cc = new CreditCard();
cc.setCardType(creditCardType);
cc.setCcCvv(((CreditCardPayment) payment).getCredidCardValidationNumber());
cc.setCcOwner(((CreditCardPayment) payment).getCardOwner());
cc.setCcExpires(((CreditCardPayment) payment).getExpirationMonth() + "-" + ((CreditCardPayment) payment).getExpirationYear());
// hash credit card number
if (!StringUtils.isBlank(cc.getCcNumber())) {
String maskedNumber = CreditCardUtils.maskCardNumber(order.getPayment().get("creditcard_card_number"));
cc.setCcNumber(maskedNumber);
modelOrder.setCreditCard(cc);
}
}
}
if (PaymentType.PAYPAL.name().equals(paymentType)) {
// check for previous transaction
if (transaction == null) {
throw new ServiceException("payment.error");
}
payment = new com.salesmanager.core.model.payments.PaypalPayment();
((com.salesmanager.core.model.payments.PaypalPayment) payment).setPayerId(transaction.getTransactionDetails().get("PAYERID"));
((com.salesmanager.core.model.payments.PaypalPayment) payment).setPaymentToken(transaction.getTransactionDetails().get("TOKEN"));
}
modelOrder.setShoppingCartCode(shoppingCartCode);
modelOrder.setPaymentModuleCode(order.getPaymentModule());
payment.setModuleName(order.getPaymentModule());
if (transaction != null) {
orderService.processOrder(modelOrder, customer, order.getShoppingCartItems(), summary, payment, store);
} else {
orderService.processOrder(modelOrder, customer, order.getShoppingCartItems(), summary, payment, transaction, store);
}
return modelOrder;
} catch (ServiceException se) {
// may be invalid credit card
throw se;
} catch (Exception e) {
throw new ServiceException(e);
}
}
use of com.salesmanager.shop.model.customer.address.Address in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method getAddress.
@Override
public Address getAddress(Long userId, final MerchantStore merchantStore, boolean isBillingAddress) throws Exception {
LOG.info("Fetching customer for id {} ", userId);
Address address = null;
final Customer customerModel = customerService.getById(userId);
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 (isBillingAddress) {
LOG.info("getting billing address..");
CustomerBillingAddressPopulator billingAddressPopulator = new CustomerBillingAddressPopulator();
address = billingAddressPopulator.populate(customerModel, merchantStore, merchantStore.getDefaultLanguage());
address.setBillingAddress(true);
return address;
}
LOG.info("getting Delivery address..");
CustomerDeliveryAddressPopulator deliveryAddressPopulator = new CustomerDeliveryAddressPopulator();
return deliveryAddressPopulator.populate(customerModel, merchantStore, merchantStore.getDefaultLanguage());
}
use of com.salesmanager.shop.model.customer.address.Address in project shopizer by shopizer-ecommerce.
the class CustomerEntityPopulator method populate.
@Override
public CustomerEntity populate(final Customer source, final CustomerEntity target, final MerchantStore merchantStore, final Language language) throws ConversionException {
try {
target.setId(source.getId());
if (StringUtils.isNotBlank(source.getEmailAddress())) {
target.setEmailAddress(source.getEmailAddress());
}
if (source.getBilling() != null) {
Address address = new Address();
address.setCity(source.getBilling().getCity());
address.setAddress(source.getBilling().getAddress());
address.setCompany(source.getBilling().getCompany());
address.setFirstName(source.getBilling().getFirstName());
address.setLastName(source.getBilling().getLastName());
address.setPostalCode(source.getBilling().getPostalCode());
address.setPhone(source.getBilling().getTelephone());
if (source.getBilling().getCountry() != null) {
address.setCountry(source.getBilling().getCountry().getIsoCode());
}
if (source.getBilling().getZone() != null) {
address.setZone(source.getBilling().getZone().getCode());
}
address.setStateProvince(source.getBilling().getState());
target.setBilling(address);
}
if (source.getCustomerReviewAvg() != null) {
target.setRating(source.getCustomerReviewAvg().doubleValue());
}
if (source.getCustomerReviewCount() != null) {
target.setRatingCount(source.getCustomerReviewCount().intValue());
}
if (source.getDelivery() != null) {
Address address = new Address();
address.setCity(source.getDelivery().getCity());
address.setAddress(source.getDelivery().getAddress());
address.setCompany(source.getDelivery().getCompany());
address.setFirstName(source.getDelivery().getFirstName());
address.setLastName(source.getDelivery().getLastName());
address.setPostalCode(source.getDelivery().getPostalCode());
address.setPhone(source.getDelivery().getTelephone());
if (source.getDelivery().getCountry() != null) {
address.setCountry(source.getDelivery().getCountry().getIsoCode());
}
if (source.getDelivery().getZone() != null) {
address.setZone(source.getDelivery().getZone().getCode());
}
address.setStateProvince(source.getDelivery().getState());
target.setDelivery(address);
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.shop.model.customer.address.Address in project shopizer by shopizer-ecommerce.
the class ReadableCustomerPopulator method populate.
@Override
public ReadableCustomer populate(Customer source, ReadableCustomer target, MerchantStore store, Language language) throws ConversionException {
try {
if (target == null) {
target = new ReadableCustomer();
}
if (source.getId() != null && source.getId() > 0) {
target.setId(source.getId());
}
target.setEmailAddress(source.getEmailAddress());
if (StringUtils.isNotEmpty(source.getNick())) {
target.setUserName(source.getNick());
}
if (source.getDefaultLanguage() != null) {
target.setLanguage(source.getDefaultLanguage().getCode());
}
if (source.getGender() != null) {
target.setGender(source.getGender().name());
}
if (StringUtils.isNotEmpty(source.getProvider())) {
target.setProvider(source.getProvider());
}
if (source.getBilling() != null) {
Address address = new Address();
address.setAddress(source.getBilling().getAddress());
address.setCity(source.getBilling().getCity());
address.setCompany(source.getBilling().getCompany());
address.setFirstName(source.getBilling().getFirstName());
address.setLastName(source.getBilling().getLastName());
address.setPostalCode(source.getBilling().getPostalCode());
address.setPhone(source.getBilling().getTelephone());
if (source.getBilling().getCountry() != null) {
address.setCountry(source.getBilling().getCountry().getIsoCode());
}
if (source.getBilling().getZone() != null) {
address.setZone(source.getBilling().getZone().getCode());
}
if (source.getBilling().getState() != null) {
address.setStateProvince(source.getBilling().getState());
}
target.setFirstName(address.getFirstName());
target.setLastName(address.getLastName());
target.setBilling(address);
}
if (source.getCustomerReviewAvg() != null) {
target.setRating(source.getCustomerReviewAvg().doubleValue());
}
if (source.getCustomerReviewCount() != null) {
target.setRatingCount(source.getCustomerReviewCount().intValue());
}
if (source.getDelivery() != null) {
Address address = new Address();
address.setCity(source.getDelivery().getCity());
address.setAddress(source.getDelivery().getAddress());
address.setCompany(source.getDelivery().getCompany());
address.setFirstName(source.getDelivery().getFirstName());
address.setLastName(source.getDelivery().getLastName());
address.setPostalCode(source.getDelivery().getPostalCode());
address.setPhone(source.getDelivery().getTelephone());
if (source.getDelivery().getCountry() != null) {
address.setCountry(source.getDelivery().getCountry().getIsoCode());
}
if (source.getDelivery().getZone() != null) {
address.setZone(source.getDelivery().getZone().getCode());
}
if (source.getDelivery().getState() != null) {
address.setStateProvince(source.getDelivery().getState());
}
target.setDelivery(address);
}
if (source.getAttributes() != null) {
for (CustomerAttribute attribute : source.getAttributes()) {
ReadableCustomerAttribute readableAttribute = new ReadableCustomerAttribute();
readableAttribute.setId(attribute.getId());
readableAttribute.setTextValue(attribute.getTextValue());
ReadableCustomerOption option = new ReadableCustomerOption();
option.setId(attribute.getCustomerOption().getId());
option.setCode(attribute.getCustomerOption().getCode());
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);
target.getAttributes().add(readableAttribute);
}
if (source.getGroups() != null) {
for (Group group : source.getGroups()) {
ReadableGroup readableGroup = new ReadableGroup();
readableGroup.setId(group.getId().longValue());
readableGroup.setName(group.getGroupName());
readableGroup.setType(group.getGroupType().name());
target.getGroups().add(readableGroup);
}
}
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
Aggregations