use of com.salesmanager.core.model.reference.zone.Zone 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.zone.Zone in project shopizer by shopizer-ecommerce.
the class ZonesLoader method mapZone.
// internal complex mapping stuff, don't try this at home ...
private void mapZone(Language l, Map<String, List<ZoneDescription>> zonesDescriptionsMap, Map<String, Country> countriesMap, Map<String, Zone> zonesMap, Map<String, String> zonesMark, Map<String, String> list) {
String zoneCode = list.get("zoneCode");
ZoneDescription zoneDescription = new ZoneDescription();
zoneDescription.setLanguage(l);
zoneDescription.setName(list.get("zoneName"));
Zone zone = null;
List<ZoneDescription> descriptions = null;
if (!zonesMap.containsKey(zoneCode)) {
zone = new Zone();
Country country = countriesMap.get(list.get("countryCode"));
if (country == null) {
LOGGER.warn("Country is null for " + zoneCode + " and country code " + list.get("countryCode"));
return;
}
zone.setCountry(country);
zone.setCode(zoneCode);
zonesMap.put(zoneCode, zone);
}
if (zonesMark.containsKey(l.getCode() + "_" + zoneCode)) {
LOGGER.warn("This zone seems to be a duplicate ! " + zoneCode + " and language code " + l.getCode());
return;
}
zonesMark.put(l.getCode() + "_" + zoneCode, l.getCode() + "_" + zoneCode);
if (zonesDescriptionsMap.containsKey(zoneCode)) {
descriptions = zonesDescriptionsMap.get(zoneCode);
} else {
descriptions = new ArrayList<ZoneDescription>();
zonesDescriptionsMap.put(zoneCode, descriptions);
}
descriptions.add(zoneDescription);
}
use of com.salesmanager.core.model.reference.zone.Zone in project shopizer by shopizer-ecommerce.
the class ZoneServiceImpl method getZones.
@SuppressWarnings("unchecked")
@Override
public List<Zone> getZones(String countryCode, Language language) throws ServiceException {
Validate.notNull(countryCode, "countryCode cannot be null");
Validate.notNull(language, "Language cannot be null");
List<Zone> zones = null;
try {
String cacheKey = ZONE_CACHE_PREFIX + countryCode + Constants.UNDERSCORE + language.getCode();
zones = (List<Zone>) cache.getFromCache(cacheKey);
if (zones == null) {
zones = zoneRepository.listByLanguageAndCountry(countryCode, language.getId());
// set names
for (Zone zone : zones) {
ZoneDescription description = zone.getDescriptions().get(0);
zone.setName(description.getName());
}
cache.putInCache(zones, cacheKey);
}
} catch (Exception e) {
LOGGER.error("getZones()", e);
}
return zones;
}
use of com.salesmanager.core.model.reference.zone.Zone 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.reference.zone.Zone in project shopizer by shopizer-ecommerce.
the class CustomerPopulator method populate.
/**
* Creates a Customer entity ready to be saved
*/
@Override
public Customer populate(PersistableCustomer source, Customer target, MerchantStore store, Language language) throws ConversionException {
try {
if (source.getId() != null && source.getId() > 0) {
target.setId(source.getId());
}
if (!StringUtils.isBlank(source.getPassword())) {
target.setPassword(passwordEncoder.encode(source.getPassword()));
target.setNick(source.getUserName());
target.setAnonymous(false);
}
if (source.getBilling() != null) {
target.setBilling(new Billing());
if (!StringUtils.isEmpty(source.getFirstName())) {
target.getBilling().setFirstName(source.getFirstName());
}
if (!StringUtils.isEmpty(source.getLastName())) {
target.getBilling().setLastName(source.getLastName());
}
}
if (!StringUtils.isBlank(source.getProvider())) {
target.setProvider(source.getProvider());
}
if (!StringUtils.isBlank(source.getEmailAddress())) {
target.setEmailAddress(source.getEmailAddress());
}
if (source.getGender() != null && target.getGender() == null) {
target.setGender(com.salesmanager.core.model.customer.CustomerGender.valueOf(source.getGender()));
}
if (target.getGender() == null) {
target.setGender(com.salesmanager.core.model.customer.CustomerGender.M);
}
Map<String, Country> countries = countryService.getCountriesMap(language);
Map<String, Zone> zones = zoneService.getZones(language);
target.setMerchantStore(store);
Address sourceBilling = source.getBilling();
if (sourceBilling != null) {
Billing billing = target.getBilling();
billing.setAddress(sourceBilling.getAddress());
billing.setCity(sourceBilling.getCity());
billing.setCompany(sourceBilling.getCompany());
// billing.setCountry(country);
if (!StringUtils.isEmpty(sourceBilling.getFirstName()))
billing.setFirstName(sourceBilling.getFirstName());
if (!StringUtils.isEmpty(sourceBilling.getLastName()))
billing.setLastName(sourceBilling.getLastName());
billing.setTelephone(sourceBilling.getPhone());
billing.setPostalCode(sourceBilling.getPostalCode());
billing.setState(sourceBilling.getStateProvince());
Country billingCountry = null;
if (!StringUtils.isBlank(sourceBilling.getCountry())) {
billingCountry = countries.get(sourceBilling.getCountry());
if (billingCountry == null) {
throw new ConversionException("Unsuported country code " + sourceBilling.getCountry());
}
billing.setCountry(billingCountry);
}
if (billingCountry != null && !StringUtils.isBlank(sourceBilling.getZone())) {
Zone zone = zoneService.getByCode(sourceBilling.getZone());
if (zone == null) {
throw new ConversionException("Unsuported zone code " + sourceBilling.getZone());
}
Zone zoneDescription = zones.get(zone.getCode());
billing.setZone(zoneDescription);
}
// target.setBilling(billing);
}
if (target.getBilling() == null && source.getBilling() != null) {
LOG.info("Setting default values for billing");
Billing billing = new Billing();
Country billingCountry = null;
if (StringUtils.isNotBlank(source.getBilling().getCountry())) {
billingCountry = countries.get(source.getBilling().getCountry());
if (billingCountry == null) {
throw new ConversionException("Unsuported country code " + sourceBilling.getCountry());
}
billing.setCountry(billingCountry);
target.setBilling(billing);
}
}
Address sourceShipping = source.getDelivery();
if (sourceShipping != null) {
Delivery delivery = new Delivery();
delivery.setAddress(sourceShipping.getAddress());
delivery.setCity(sourceShipping.getCity());
delivery.setCompany(sourceShipping.getCompany());
delivery.setFirstName(sourceShipping.getFirstName());
delivery.setLastName(sourceShipping.getLastName());
delivery.setTelephone(sourceShipping.getPhone());
delivery.setPostalCode(sourceShipping.getPostalCode());
delivery.setState(sourceShipping.getStateProvince());
Country deliveryCountry = null;
if (!StringUtils.isBlank(sourceShipping.getCountry())) {
deliveryCountry = countries.get(sourceShipping.getCountry());
if (deliveryCountry == null) {
throw new ConversionException("Unsuported country code " + sourceShipping.getCountry());
}
delivery.setCountry(deliveryCountry);
}
if (deliveryCountry != null && !StringUtils.isBlank(sourceShipping.getZone())) {
Zone zone = zoneService.getByCode(sourceShipping.getZone());
if (zone == null) {
throw new ConversionException("Unsuported zone code " + sourceShipping.getZone());
}
Zone zoneDescription = zones.get(zone.getCode());
delivery.setZone(zoneDescription);
}
target.setDelivery(delivery);
}
if (source.getRating() != null && source.getRating().doubleValue() > 0) {
target.setCustomerReviewAvg(new BigDecimal(source.getRating().doubleValue()));
}
if (source.getRatingCount() > 0) {
target.setCustomerReviewCount(source.getRatingCount());
}
if (target.getDelivery() == null && source.getDelivery() != null) {
LOG.info("Setting default value for delivery");
Delivery delivery = new Delivery();
Country deliveryCountry = null;
if (StringUtils.isNotBlank(source.getDelivery().getCountry())) {
deliveryCountry = countries.get(source.getDelivery().getCountry());
if (deliveryCountry == null) {
throw new ConversionException("Unsuported country code " + sourceShipping.getCountry());
}
delivery.setCountry(deliveryCountry);
target.setDelivery(delivery);
}
}
if (source.getAttributes() != null) {
for (PersistableCustomerAttribute attr : source.getAttributes()) {
CustomerOption customerOption = customerOptionService.getById(attr.getCustomerOption().getId());
if (customerOption == null) {
throw new ConversionException("Customer option id " + attr.getCustomerOption().getId() + " does not exist");
}
CustomerOptionValue customerOptionValue = customerOptionValueService.getById(attr.getCustomerOptionValue().getId());
if (customerOptionValue == null) {
throw new ConversionException("Customer option value id " + attr.getCustomerOptionValue().getId() + " does not exist");
}
if (customerOption.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid customer option id ");
}
if (customerOptionValue.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid customer option value id ");
}
CustomerAttribute attribute = new CustomerAttribute();
attribute.setCustomer(target);
attribute.setCustomerOption(customerOption);
attribute.setCustomerOptionValue(customerOptionValue);
attribute.setTextValue(attr.getTextValue());
target.getAttributes().add(attribute);
}
}
if (target.getDefaultLanguage() == null) {
Language lang = source.getLanguage() == null ? language : languageService.getByCode(source.getLanguage());
target.setDefaultLanguage(lang);
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
Aggregations