Search in sources :

Example 26 with Product

use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.

the class ProductInstanceFacadeImpl method list.

@Override
public ReadableEntityList<ReadableProductInstance> list(Long productId, MerchantStore store, Language language, int page, int count) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(productId, "Product id cannot be null");
    Product product = productFacade.getProduct(productId, store);
    if (product == null) {
        throw new ResourceNotFoundException("Product with id [" + productId + "] not found for store [" + store.getCode() + "]");
    }
    Page<ProductInstance> instances = productInstanceService.getByProductId(store, product, language, page, count);
    List<ReadableProductInstance> readableInstances = instances.stream().map(rp -> this.readableProductInstanceMapper.convert(rp, store, language)).collect(Collectors.toList());
    return createReadableList(instances, readableInstances);
}
Also used : ReadableEntityUtil.createReadableList(com.salesmanager.shop.util.ReadableEntityUtil.createReadableList) Arrays(java.util.Arrays) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductFacade(com.salesmanager.shop.store.controller.product.facade.ProductFacade) ProductInstanceFacade(com.salesmanager.shop.store.controller.product.facade.ProductInstanceFacade) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductVariationService(com.salesmanager.core.business.services.catalog.product.variation.ProductVariationService) ProductInstanceService(com.salesmanager.core.business.services.catalog.product.instance.ProductInstanceService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ProductVariation(com.salesmanager.core.model.catalog.product.variation.ProductVariation) ConstraintException(com.salesmanager.shop.store.api.exception.ConstraintException) PersistableProductInstanceMapper(com.salesmanager.shop.mapper.catalog.product.PersistableProductInstanceMapper) Page(org.springframework.data.domain.Page) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) Collectors(java.util.stream.Collectors) ProductCommonFacade(com.salesmanager.shop.store.controller.product.facade.ProductCommonFacade) List(java.util.List) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) PersistableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ReadableProductInstanceMapper(com.salesmanager.shop.mapper.catalog.product.ReadableProductInstanceMapper) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) PersistableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance)

Example 27 with Product

use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.

the class ProductInventoryFacadeImpl method getProductAvailabilityToSave.

private ProductAvailability getProductAvailabilityToSave(PersistableInventory inventory, MerchantStore store, Long productId) {
    Product product = getProductById(productId);
    ProductAvailability availability = productInventoryMapper.convert(inventory, store, store.getDefaultLanguage());
    availability.setProduct(product);
    availability.setMerchantStore(store);
    return availability;
}
Also used : ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Product(com.salesmanager.core.model.catalog.product.Product)

Example 28 with Product

use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.

the class ProductInventoryFacadeImpl method get.

@Override
public ReadableInventory get(Long productId, Long inventoryId, MerchantStore store, Language language) {
    Product product = getProductById(productId);
    if (product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
        throw new ResourceNotFoundException("Product with id [" + productId + "] not found for store [" + store.getCode() + "]");
    }
    ProductAvailability availability = productAvailabilityService.getByInventoryId(productId, inventoryId, store).orElseThrow(() -> new ResourceNotFoundException("Inventory with id [" + inventoryId + "] not found"));
    return readableInventoryMapper.convert(availability, store, language);
}
Also used : ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 29 with Product

use of com.salesmanager.core.model.catalog.product.Product in project shopizer by shopizer-ecommerce.

the class ProductInventoryFacadeImpl method update.

@Override
public void update(Long productId, PersistableInventory inventory, MerchantStore store, Language language) {
    Validate.notNull(productId, "Product id cannot be null");
    Validate.notNull(inventory, "Inventory cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Product product = getProductById(productId);
    ProductAvailability availability = getAvailabilityById(store, inventory.getId());
    if (availability.getProduct().getId().longValue() != productId) {
        throw new ResourceNotFoundException("Availability with id [" + inventory.getId() + "] not found for product id [" + productId + "]");
    }
    inventory.setProductId(product.getId());
    availability = productInventoryMapper.merge(inventory, availability, store, language);
    availability.setProduct(product);
    availability.setMerchantStore(store);
    saveOrUpdate(availability);
}
Also used : ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 30 with Product

use of com.salesmanager.core.model.catalog.product.Product 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;
}
Also used : ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) Date(java.util.Date) DateUtil(com.salesmanager.shop.utils.DateUtil) StringUtils(org.apache.commons.lang3.StringUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) PersistableProductPopulator(com.salesmanager.shop.populator.catalog.PersistableProductPopulator) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) 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) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) ReadableProductReview(com.salesmanager.shop.model.catalog.product.ReadableProductReview) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) CustomerService(com.salesmanager.core.business.services.customer.CustomerService) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductReviewService(com.salesmanager.core.business.services.catalog.product.review.ProductReviewService) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) ProductRelationshipService(com.salesmanager.core.business.services.catalog.product.relationship.ProductRelationshipService) PersistableProductReviewPopulator(com.salesmanager.shop.populator.catalog.PersistableProductReviewPopulator) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Collectors(java.util.stream.Collectors) ProductCommonFacade(com.salesmanager.shop.store.controller.product.facade.ProductCommonFacade) Category(com.salesmanager.core.model.catalog.category.Category) ReadableProductReviewPopulator(com.salesmanager.shop.populator.catalog.ReadableProductReviewPopulator) List(java.util.List) Validate(org.apache.commons.lang3.Validate) PersistableProductReview(com.salesmanager.shop.model.catalog.product.PersistableProductReview) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ProductPriceEntity(com.salesmanager.shop.model.catalog.product.ProductPriceEntity) Category(com.salesmanager.core.model.catalog.category.Category) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Aggregations

Product (com.salesmanager.core.model.catalog.product.Product)120 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)53 ArrayList (java.util.ArrayList)45 Language (com.salesmanager.core.model.reference.language.Language)42 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)41 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)36 ServiceException (com.salesmanager.core.business.exception.ServiceException)35 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)35 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)33 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)33 PersistableProduct (com.salesmanager.shop.model.catalog.product.PersistableProduct)29 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)28 List (java.util.List)25 Date (java.util.Date)23 LightPersistableProduct (com.salesmanager.shop.model.catalog.product.LightPersistableProduct)22 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 Category (com.salesmanager.core.model.catalog.category.Category)20 Collectors (java.util.stream.Collectors)20 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)19 ConversionException (com.salesmanager.core.business.exception.ConversionException)17