Search in sources :

Example 61 with MerchantStore

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;
}
Also used : ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) NoResultException(javax.persistence.NoResultException) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ServiceException(com.salesmanager.core.business.exception.ServiceException) RequestContextHolder(org.springframework.web.context.request.RequestContextHolder) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ShoppingCartDataPopulator(com.salesmanager.shop.populator.shoppingCart.ShoppingCartDataPopulator) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Set(java.util.Set) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) List(java.util.List) ShoppingCartCalculationService(com.salesmanager.core.business.services.shoppingcart.ShoppingCartCalculationService) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) LocalDate(java.time.LocalDate) Optional(java.util.Optional) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ProductPriceUtils(com.salesmanager.core.business.utils.ProductPriceUtils) ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) Constants(com.salesmanager.shop.constants.Constants) ReadableShoppingCartMapper(com.salesmanager.shop.mapper.cart.ReadableShoppingCartMapper) DateUtil(com.salesmanager.shop.utils.DateUtil) CartModificationException(com.salesmanager.shop.model.shoppingcart.CartModificationException) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Nullable(org.springframework.lang.Nullable) ShoppingCartAttribute(com.salesmanager.shop.model.shoppingcart.ShoppingCartAttribute) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) ShoppingCartService(com.salesmanager.core.business.services.shoppingcart.ShoppingCartService) Product(com.salesmanager.core.model.catalog.product.Product) Logger(org.slf4j.Logger) Customer(com.salesmanager.core.model.customer.Customer) PersistableShoppingCartItem(com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ShoppingCartData(com.salesmanager.shop.model.shoppingcart.ShoppingCartData) Validate(org.apache.commons.lang3.Validate) ShoppingCartItem(com.salesmanager.shop.model.shoppingcart.ShoppingCartItem) ArrayList(java.util.ArrayList) Product(com.salesmanager.core.model.catalog.product.Product) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) PersistableShoppingCartItem(com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) NoResultException(javax.persistence.NoResultException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) CartModificationException(com.salesmanager.shop.model.shoppingcart.CartModificationException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Date(java.util.Date) LocalDate(java.time.LocalDate) PersistableShoppingCartItem(com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem) ShoppingCartItem(com.salesmanager.shop.model.shoppingcart.ShoppingCartItem)

Example 62 with MerchantStore

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);
    }
}
Also used : MerchantConfigEntity(com.salesmanager.shop.model.store.MerchantConfigEntity) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) PersistableMerchantStorePopulator(com.salesmanager.shop.populator.store.PersistableMerchantStorePopulator) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ReadableBrand(com.salesmanager.shop.model.store.ReadableBrand) CollectionUtils(org.apache.commons.collections4.CollectionUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ZoneService(com.salesmanager.core.business.services.reference.zone.ZoneService) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) PersistableBrand(com.salesmanager.shop.model.store.PersistableBrand) MerchantStoreCriteria(com.salesmanager.core.model.merchant.MerchantStoreCriteria) HttpServletRequest(javax.servlet.http.HttpServletRequest) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) GenericEntityList(com.salesmanager.core.model.common.GenericEntityList) ReadableMerchantStorePopulator(com.salesmanager.shop.populator.store.ReadableMerchantStorePopulator) MerchantStoreService(com.salesmanager.core.business.services.merchant.MerchantStoreService) MeasureUnit(com.salesmanager.core.constants.MeasureUnit) CountryService(com.salesmanager.core.business.services.reference.country.CountryService) Logger(org.slf4j.Logger) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Page(org.springframework.data.domain.Page) InputContentFile(com.salesmanager.core.model.content.InputContentFile) Collectors(java.util.stream.Collectors) MerchantConfigurationService(com.salesmanager.core.business.services.system.MerchantConfigurationService) ContentService(com.salesmanager.core.business.services.content.ContentService) List(java.util.List) ReadableImage(com.salesmanager.shop.model.content.ReadableImage) Validate(org.apache.commons.lang3.Validate) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) LanguageUtils(com.salesmanager.shop.utils.LanguageUtils) MerchantConfigurationType(com.salesmanager.core.model.system.MerchantConfigurationType) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) Optional(java.util.Optional) ConversionException(com.salesmanager.core.business.exception.ConversionException) Collections(java.util.Collections) StringUtils(org.drools.core.util.StringUtils) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 63 with MerchantStore

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;
}
Also used : ReadableImage(com.salesmanager.shop.model.content.ReadableImage) MerchantConfigEntity(com.salesmanager.shop.model.store.MerchantConfigEntity) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ReadableBrand(com.salesmanager.shop.model.store.ReadableBrand)

Example 64 with MerchantStore

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);
    }
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ArrayList(java.util.ArrayList) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 65 with MerchantStore

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);
    }
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) ListCriteria(com.salesmanager.shop.model.entity.ListCriteria) PersistableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.PersistableManufacturerPopulator) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) ManufacturerService(com.salesmanager.core.business.services.catalog.product.manufacturer.ManufacturerService) Mapper(com.salesmanager.shop.mapper.Mapper) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturerList(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturerList) Validate(org.jsoup.helper.Validate) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) Category(com.salesmanager.core.model.catalog.category.Category) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) List(java.util.List) ManufacturerFacade(com.salesmanager.shop.store.controller.manufacturer.facade.ManufacturerFacade) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Comparator(java.util.Comparator) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Category(com.salesmanager.core.model.catalog.category.Category) ServiceException(com.salesmanager.core.business.exception.ServiceException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)171 Language (com.salesmanager.core.model.reference.language.Language)123 ServiceException (com.salesmanager.core.business.exception.ServiceException)72 List (java.util.List)65 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)62 ArrayList (java.util.ArrayList)61 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)60 Collectors (java.util.stream.Collectors)60 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)52 Autowired (org.springframework.beans.factory.annotation.Autowired)46 Product (com.salesmanager.core.model.catalog.product.Product)43 Service (org.springframework.stereotype.Service)37 Optional (java.util.Optional)35 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)35 Customer (com.salesmanager.core.model.customer.Customer)33 Logger (org.slf4j.Logger)33 LoggerFactory (org.slf4j.LoggerFactory)33 Inject (javax.inject.Inject)32 Validate (org.apache.commons.lang3.Validate)30 ConversionException (com.salesmanager.core.business.exception.ConversionException)27