use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method createCartItems.
// used for api
private List<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> createCartItems(ShoppingCart cartModel, List<PersistableShoppingCartItem> shoppingCartItems, MerchantStore store) throws Exception {
List<Long> productIds = shoppingCartItems.stream().map(s -> Long.valueOf(s.getProduct())).collect(Collectors.toList());
List<Product> products = productService.getProductsByIds(productIds);
if (products == null || products.size() != shoppingCartItems.size()) {
LOG.warn("----------------------- Items with in id-list " + productIds + " does not exist");
throw new ResourceNotFoundException("Item with id " + productIds + " does not exist");
}
List<Product> wrongStoreProducts = products.stream().filter(p -> p.getMerchantStore().getId() != store.getId()).collect(Collectors.toList());
if (wrongStoreProducts.size() > 0) {
throw new ResourceNotFoundException("One or more of the items with id's " + wrongStoreProducts.stream().map(s -> Long.valueOf(s.getId())).collect(Collectors.toList()) + " does not belong to merchant " + store.getId());
}
List<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> items = new ArrayList<>();
for (Product p : products) {
com.salesmanager.core.model.shoppingcart.ShoppingCartItem item = shoppingCartService.populateShoppingCartItem(p);
Optional<PersistableShoppingCartItem> oShoppingCartItem = shoppingCartItems.stream().filter(i -> i.getProduct() == p.getId()).findFirst();
if (!oShoppingCartItem.isPresent()) {
// Should never happen if not something is updated in realtime or user has item in local storage and add it long time after to cart!
LOG.warn("Missing shoppingCartItem for product " + p.getSku() + " ( " + p.getId() + " )");
continue;
}
PersistableShoppingCartItem shoppingCartItem = oShoppingCartItem.get();
item.setQuantity(shoppingCartItem.getQuantity());
item.setShoppingCart(cartModel);
/**
* Check if product is available
* Check if product quantity is 0
* Check if date available <= now
*/
if (!p.isAvailable()) {
throw new Exception("Item with id " + p.getId() + " is not available");
}
Set<ProductAvailability> availabilities = p.getAvailabilities();
if (availabilities == null) {
throw new Exception("Item with id " + p.getId() + " is not properly configured");
}
for (ProductAvailability availability : availabilities) {
if (availability.getProductQuantity() == null || availability.getProductQuantity().intValue() == 0) {
throw new Exception("Item with id " + p.getId() + " is not available");
}
}
if (!DateUtil.dateBeforeEqualsDate(p.getDateAvailable(), new Date())) {
throw new Exception("Item with id " + p.getId() + " is not available");
}
// end qty & availablility checks
// set attributes
List<com.salesmanager.shop.model.catalog.product.attribute.ProductAttribute> attributes = shoppingCartItem.getAttributes();
if (!CollectionUtils.isEmpty(attributes)) {
for (com.salesmanager.shop.model.catalog.product.attribute.ProductAttribute attribute : attributes) {
ProductAttribute productAttribute = productAttributeService.getById(attribute.getId());
if (productAttribute != null && productAttribute.getProduct().getId().longValue() == p.getId().longValue()) {
com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem attributeItem = new com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem(item, productAttribute);
item.addAttributes(attributeItem);
}
}
}
items.add(item);
}
return items;
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class StoreFacadeImpl method getMerchantStoresByCriteria.
private ReadableMerchantStoreList getMerchantStoresByCriteria(MerchantStoreCriteria criteria, Language language) {
try {
GenericEntityList<MerchantStore> stores = Optional.ofNullable(merchantStoreService.getByCriteria(criteria)).orElseThrow(() -> new ResourceNotFoundException("Criteria did not match any store"));
ReadableMerchantStoreList storeList = new ReadableMerchantStoreList();
storeList.setData((List<ReadableMerchantStore>) stores.getList().stream().map(s -> convertMerchantStoreToReadableMerchantStore(language, s)).collect(Collectors.toList()));
storeList.setTotalPages(stores.getTotalPages());
storeList.setRecordsTotal(stores.getTotalCount());
storeList.setNumber(stores.getList().size());
return storeList;
} catch (ServiceException e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class StoreFacadeImpl method getBrand.
@Override
public ReadableBrand getBrand(String code) {
MerchantStore mStore = getMerchantStoreByCode(code);
ReadableBrand readableBrand = new ReadableBrand();
if (!StringUtils.isEmpty(mStore.getStoreLogo())) {
String imagePath = imageUtils.buildStoreLogoFilePath(mStore);
ReadableImage image = createReadableImage(mStore.getStoreLogo(), imagePath);
readableBrand.setLogo(image);
}
List<MerchantConfigEntity> merchantConfigTOs = getMerchantConfigEntities(mStore);
readableBrand.getSocialNetworks().addAll(merchantConfigTOs);
return readableBrand;
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class StoreFacadeImpl method getChildStores.
@Override
public ReadableMerchantStoreList getChildStores(Language language, String code, int page, int count) {
try {
// first check if store is retailer
MerchantStore retailer = this.getByCode(code);
if (retailer == null) {
throw new ResourceNotFoundException("Merchant [" + code + "] not found");
}
if (retailer.isRetailer() == null || !retailer.isRetailer().booleanValue()) {
throw new ResourceNotFoundException("Merchant [" + code + "] not a retailer");
}
Page<MerchantStore> children = merchantStoreService.listChildren(code, page, count);
List<ReadableMerchantStore> readableStores = new ArrayList<ReadableMerchantStore>();
ReadableMerchantStoreList readableList = new ReadableMerchantStoreList();
if (!CollectionUtils.isEmpty(children.getContent())) {
for (MerchantStore store : children) readableStores.add(convertMerchantStoreToReadableMerchantStore(language, store));
}
readableList.setData(readableStores);
readableList.setRecordsFiltered(children.getSize());
readableList.setTotalPages(children.getTotalPages());
readableList.setRecordsTotal(children.getTotalElements());
readableList.setNumber(children.getNumber());
return readableList;
/* List<MerchantStore> children = merchantStoreService.listChildren(code);
List<ReadableMerchantStore> readableStores = new ArrayList<ReadableMerchantStore>();
if (!CollectionUtils.isEmpty(children)) {
for (MerchantStore store : children)
readableStores.add(convertMerchantStoreToReadableMerchantStore(language, store));
}
return readableStores;*/
} catch (ServiceException e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.
the class ManufacturerFacadeImpl method getByProductInCategory.
@Override
public List<ReadableManufacturer> getByProductInCategory(MerchantStore store, Language language, Long categoryId) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
Validate.notNull(categoryId, "Category id cannot be null");
Category category = categoryService.getById(categoryId, store.getId());
if (category == null) {
throw new ResourceNotFoundException("Category with id [" + categoryId + "] not found");
}
if (category.getMerchantStore().getId().longValue() != store.getId().longValue()) {
throw new UnauthorizedException("Merchant [" + store.getCode() + "] not authorized");
}
try {
List<Manufacturer> manufacturers = manufacturerService.listByProductsInCategory(store, category, language);
List<ReadableManufacturer> manufacturersList = manufacturers.stream().sorted(new Comparator<Manufacturer>() {
@Override
public int compare(final Manufacturer object1, final Manufacturer object2) {
return object1.getCode().compareTo(object2.getCode());
}
}).map(manuf -> readableManufacturerConverter.convert(manuf, store, language)).collect(Collectors.toList());
return manufacturersList;
} catch (ServiceException e) {
throw new ServiceRuntimeException(e);
}
}
Aggregations