use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class SearchFacadeImpl method convertToSearchProductList.
@Override
public SearchProductList convertToSearchProductList(SearchResponse searchResponse, MerchantStore merchantStore, int start, int count, Language language) {
SearchProductList returnList = new SearchProductList();
List<SearchEntry> entries = searchResponse.getEntries();
if (CollectionUtils.isNotEmpty(entries)) {
List<Long> ids = entries.stream().map(SearchEntry::getIndexProduct).map(IndexProduct::getId).map(Long::parseLong).collect(Collectors.toList());
ProductCriteria searchCriteria = new ProductCriteria();
searchCriteria.setMaxCount(count);
searchCriteria.setStartIndex(start);
searchCriteria.setProductIds(ids);
searchCriteria.setAvailable(true);
ProductList productList = productService.listByStore(merchantStore, language, searchCriteria);
List<ReadableProduct> readableProducts = productList.getProducts().stream().map(product -> convertProductToReadableProduct(product, merchantStore, language)).collect(Collectors.toList());
returnList.getProducts().addAll(readableProducts);
returnList.setProductCount(productList.getProducts().size());
}
// Facets
Map<String, List<SearchFacet>> facets = Optional.ofNullable(searchResponse.getFacets()).orElse(Collections.emptyMap());
List<ReadableCategory> categoryProxies = getCategoryFacets(merchantStore, language, facets);
returnList.setCategoryFacets(categoryProxies);
List<SearchFacet> manufacturersFacets = facets.entrySet().stream().filter(e -> MANUFACTURER_FACET_NAME.equals(e.getKey())).findFirst().map(Entry::getValue).orElse(Collections.emptyList());
if (CollectionUtils.isNotEmpty(manufacturersFacets)) {
// TODO add manufacturer facets
}
return returnList;
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class ShippingFacadeImpl method updatePackage.
@Override
public void updatePackage(String code, PackageDetails packaging, MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(packaging, "PackageDetails cannot be null");
Validate.notEmpty(code, "Packaging unique code cannot be empty");
ShippingConfiguration config = getDbConfig(store);
com.salesmanager.core.model.shipping.Package p = this.packageDetails(config, code);
if (p == null) {
throw new ResourceNotFoundException("Package with unique code [" + packaging.getCode() + "] not found");
}
com.salesmanager.core.model.shipping.Package pack = toPackage(packaging);
pack.setCode(code);
// need to check if code exists
List<com.salesmanager.core.model.shipping.Package> packs = config.getPackages().stream().filter(pa -> !pa.getCode().equals(code)).collect(Collectors.toList());
packs.add(pack);
config.setPackages(packs);
this.saveShippingConfiguration(config, store);
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class ShippingFacadeImpl method listPackages.
@Override
public List<PackageDetails> listPackages(MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
ShippingConfiguration config = getDbConfig(store);
return config.getPackages().stream().map(p -> this.toPackageDetails(p)).collect(Collectors.toList());
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class ShippingFacadeImpl method deletePackage.
@Override
public void deletePackage(String code, MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notEmpty(code, "Packaging unique code cannot be empty");
ShippingConfiguration config = getDbConfig(store);
List<com.salesmanager.core.model.shipping.Package> packages = config.getPackages();
List<com.salesmanager.core.model.shipping.Package> packList = config.getPackages().stream().filter(p -> p.getCode().equalsIgnoreCase(code)).collect(Collectors.toList());
if (!packList.isEmpty()) {
packages.removeAll(packList);
config.setPackages(packages);
this.saveShippingConfiguration(config, store);
}
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class ShippingFacadeImpl method shipToCountry.
@Override
public List<ReadableCountry> shipToCountry(MerchantStore store, Language language) {
try {
List<Country> countries = shippingService.getShipToCountryList(store, language);
List<ReadableCountry> countryList = new ArrayList<ReadableCountry>();
if (!CollectionUtils.isEmpty(countries)) {
countryList = countries.stream().map(c -> {
try {
return convert(c, store, language);
} catch (ConversionException e) {
throw new ConversionRuntimeException("Error converting Country to readable country,e");
}
}).sorted(Comparator.comparing(ReadableCountry::getName)).collect(Collectors.toList());
}
return countryList;
} catch (Exception e) {
throw new ServiceRuntimeException("Error getting shipping country", e);
}
}
Aggregations