use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method taxClasses.
@Override
public ReadableEntityList<ReadableTaxClass> taxClasses(MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
List<TaxClass> models = taxClassService.listByStore(store);
List<ReadableTaxClass> taxClasses = models.stream().map(t -> convertToReadableTaxClass(t, store, language)).collect(Collectors.toList());
ReadableEntityList<ReadableTaxClass> list = new ReadableEntityList<ReadableTaxClass>();
list.setItems(taxClasses);
list.setNumber(taxClasses.size());
list.setTotalPages(1);
list.setRecordsTotal(taxClasses.size());
return list;
} catch (ServiceException e) {
LOGGER.error("Error while getting taxClasses for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while getting taxClasses for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method taxRates.
@Override
public ReadableEntityList<ReadableTaxRate> taxRates(MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
List<TaxRate> rates = taxRateService.listByStore(store, language);
List<ReadableTaxRate> readableRates = rates.stream().map(r -> readableTaxRateMapper.convert(r, store, language)).collect(Collectors.toList());
ReadableEntityList<ReadableTaxRate> returnRates = new ReadableEntityList<ReadableTaxRate>();
returnRates.setItems(readableRates);
returnRates.setTotalPages(1);
returnRates.setNumber(readableRates.size());
returnRates.setRecordsTotal(readableRates.size());
return returnRates;
} catch (ServiceException e) {
LOGGER.error("Error while getting taxRates for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while getting taxRates for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method addProductToCategory.
@Override
public ReadableProduct addProductToCategory(Category category, Product product, Language language) {
Validate.notNull(category, "Category cannot be null");
Validate.notNull(product, "Product cannot be null");
// not alloweed if category already attached
List<Category> assigned = product.getCategories().stream().filter(cat -> cat.getId().longValue() == category.getId().longValue()).collect(Collectors.toList());
if (assigned.size() > 0) {
throw new OperationNotAllowedException("Category with id [" + category.getId() + "] already attached to product [" + product.getId() + "]");
}
product.getCategories().add(category);
ReadableProduct readableProduct = new ReadableProduct();
try {
productService.update(product);
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
populator.populate(product, readableProduct, product.getMerchantStore(), language);
} catch (Exception e) {
throw new RuntimeException("Exception when adding product [" + product.getId() + "] to category [" + category.getId() + "]", e);
}
return readableProduct;
}
use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.
the class ProductOptionSetFacadeImpl method list.
@Override
public List<ReadableProductOptionSet> list(MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
try {
List<ProductOptionSet> optionSets = productOptionSetService.listByStore(store, language);
return optionSets.stream().map(opt -> this.convert(opt, store, language)).collect(Collectors.toList());
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while listing ProductOptionSet", e);
}
}
use of com.salesmanager.core.model.reference.language.Language 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);
}
Aggregations