use of com.salesmanager.core.model.reference.currency.Currency in project shopizer by shopizer-ecommerce.
the class UtilsTestCase method testCurrency.
// @Test
@Ignore
public void testCurrency() throws Exception {
Currency currency = currencyService.getByCode("BGN");
java.util.Currency c = currency.getCurrency();
NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.US);
numberFormat.setCurrency(c);
System.out.println("Done");
}
use of com.salesmanager.core.model.reference.currency.Currency in project shopizer by shopizer-ecommerce.
the class InitializationDatabaseImpl method createCurrencies.
private void createCurrencies() throws ServiceException {
LOGGER.info(String.format("%s : Populating Currencies ", name));
for (String code : SchemaConstant.CURRENCY_MAP.keySet()) {
try {
java.util.Currency c = java.util.Currency.getInstance(code);
if (c == null) {
LOGGER.info(String.format("%s : Populating Currencies : no currency for code : %s", name, code));
}
// check if it exist
Currency currency = new Currency();
currency.setName(c.getCurrencyCode());
currency.setCurrency(c);
currencyService.create(currency);
// System.out.println(l.getCountry() + " " + c.getSymbol() + " " + c.getSymbol(l));
} catch (IllegalArgumentException e) {
LOGGER.info(String.format("%s : Populating Currencies : no currency for code : %s", name, code));
}
}
}
use of com.salesmanager.core.model.reference.currency.Currency in project shopizer by shopizer-ecommerce.
the class InitializationDatabaseImpl method createMerchant.
private void createMerchant() throws ServiceException {
LOGGER.info(String.format("%s : Creating merchant ", name));
Date date = new Date(System.currentTimeMillis());
Language en = languageService.getByCode("en");
Country ca = countryService.getByCode("CA");
Currency currency = currencyService.getByCode("CAD");
Zone qc = zoneService.getByCode("QC");
List<Language> supportedLanguages = new ArrayList<Language>();
supportedLanguages.add(en);
// create a merchant
MerchantStore store = new MerchantStore();
store.setCountry(ca);
store.setCurrency(currency);
store.setDefaultLanguage(en);
store.setInBusinessSince(date);
store.setZone(qc);
store.setStorename("Default store");
store.setStorephone("888-888-8888");
store.setCode(MerchantStore.DEFAULT_STORE);
store.setStorecity("My city");
store.setStoreaddress("1234 Street address");
store.setStorepostalcode("H2H-2H2");
store.setStoreEmailAddress("john@test.com");
store.setDomainName("localhost:8080");
store.setStoreTemplate("december");
store.setRetailer(true);
store.setLanguages(supportedLanguages);
merchantService.create(store);
TaxClass taxclass = new TaxClass(TaxClass.DEFAULT_TAX_CLASS);
taxclass.setMerchantStore(store);
taxClassService.create(taxclass);
// create default manufacturer
Manufacturer defaultManufacturer = new Manufacturer();
defaultManufacturer.setCode("DEFAULT");
defaultManufacturer.setMerchantStore(store);
ManufacturerDescription manufacturerDescription = new ManufacturerDescription();
manufacturerDescription.setLanguage(en);
manufacturerDescription.setName("DEFAULT");
manufacturerDescription.setManufacturer(defaultManufacturer);
manufacturerDescription.setDescription("DEFAULT");
defaultManufacturer.getDescriptions().add(manufacturerDescription);
manufacturerService.create(defaultManufacturer);
Optin newsletter = new Optin();
newsletter.setCode(OptinType.NEWSLETTER.name());
newsletter.setMerchant(store);
newsletter.setOptinType(OptinType.NEWSLETTER);
optinService.create(newsletter);
}
use of com.salesmanager.core.model.reference.currency.Currency in project shopizer by shopizer-ecommerce.
the class PersistableOrderApiPopulator method populate.
@Override
public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {
/* Validate.notNull(currencyService,"currencyService must be set");
Validate.notNull(customerService,"customerService must be set");
Validate.notNull(shoppingCartService,"shoppingCartService must be set");
Validate.notNull(productService,"productService must be set");
Validate.notNull(productAttributeService,"productAttributeService must be set");
Validate.notNull(digitalProductService,"digitalProductService must be set");*/
Validate.notNull(source.getPayment(), "Payment cannot be null");
try {
if (target == null) {
target = new Order();
}
// target.setLocale(LocaleUtils.getLocale(store));
target.setLocale(LocaleUtils.getLocale(store));
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());
}
// Customer
Customer customer = null;
if (source.getCustomerId() != null && source.getCustomerId().longValue() > 0) {
Long customerId = source.getCustomerId();
customer = customerService.getById(customerId);
if (customer == null) {
throw new ConversionException("Curstomer with id " + source.getCustomerId() + " does not exist");
}
target.setCustomerId(customerId);
} else {
if (source instanceof PersistableAnonymousOrder) {
PersistableCustomer persistableCustomer = ((PersistableAnonymousOrder) source).getCustomer();
customer = new Customer();
customer = customerPopulator.populate(persistableCustomer, customer, store, language);
} else {
throw new ConversionException("Curstomer details or id not set in request");
}
}
target.setCustomerEmailAddress(customer.getEmailAddress());
Delivery delivery = customer.getDelivery();
target.setDelivery(delivery);
Billing billing = customer.getBilling();
target.setBilling(billing);
if (source.getAttributes() != null && source.getAttributes().size() > 0) {
Set<OrderAttribute> attrs = new HashSet<OrderAttribute>();
for (com.salesmanager.shop.model.order.OrderAttribute attribute : source.getAttributes()) {
OrderAttribute attr = new OrderAttribute();
attr.setKey(attribute.getKey());
attr.setValue(attribute.getValue());
attr.setOrder(target);
attrs.add(attr);
}
target.setOrderAttributes(attrs);
}
target.setDatePurchased(new Date());
target.setCurrency(currency);
target.setCurrencyValue(new BigDecimal(0));
target.setMerchant(store);
target.setChannel(OrderChannel.API);
// need this
target.setStatus(OrderStatus.ORDERED);
target.setPaymentModuleCode(source.getPayment().getPaymentModule());
target.setPaymentType(PaymentType.valueOf(source.getPayment().getPaymentType()));
target.setCustomerAgreement(source.isCustomerAgreement());
// force this to true, cannot perform this activity from the API
target.setConfirmedAddress(true);
if (!StringUtils.isBlank(source.getComments())) {
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(null);
statusHistory.setOrder(target);
statusHistory.setComments(source.getComments());
target.getOrderHistory().add(statusHistory);
}
return target;
} catch (Exception e) {
throw new ConversionException(e);
}
}
use of com.salesmanager.core.model.reference.currency.Currency 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;
}
Aggregations