Search in sources :

Example 76 with Product

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

the class ProductCommonFacadeImpl method saveProduct.

@Override
public PersistableProduct saveProduct(MerchantStore store, PersistableProduct product, Language language) {
    String manufacturer = Manufacturer.DEFAULT_MANUFACTURER;
    if (product.getProductSpecifications() != null) {
        manufacturer = product.getProductSpecifications().getManufacturer();
    } else {
        ProductSpecification specifications = new ProductSpecification();
        specifications.setManufacturer(manufacturer);
    }
    Product target = null;
    if (product.getId() != null && product.getId().longValue() > 0) {
        target = productService.getById(product.getId());
    } else {
        target = new Product();
    }
    try {
        persistableProductPopulator.populate(product, target, store, language);
        if (target.getId() != null && target.getId() > 0) {
            productService.update(target);
        } else {
            productService.create(target);
            product.setId(target.getId());
        }
        return product;
    } catch (Exception e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) 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) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 77 with Product

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

the class ProductCommonFacadeImpl method getProduct.

@Override
public ReadableProduct getProduct(MerchantStore store, Long id, Language language) {
    Product product = productService.findOne(id, store);
    if (product == null) {
        throw new ResourceNotFoundException("Product [" + id + "] not found");
    }
    if (product.getMerchantStore().getId() != store.getId()) {
        throw new ResourceNotFoundException("Product [" + id + "] not found for store [" + store.getId() + "]");
    }
    ReadableProduct readableProduct = new ReadableProduct();
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    try {
        readableProduct = populator.populate(product, readableProduct, store, language);
    } catch (ConversionException e) {
        throw new ConversionRuntimeException("Error converting product [" + id + "]", e);
    }
    return readableProduct;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 78 with Product

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

the class ProductCommonFacadeImpl method updateProductPrice.

@Override
public ReadableProduct updateProductPrice(ReadableProduct product, ProductPriceEntity price, Language language) throws Exception {
    Product persistable = productService.getById(product.getId());
    if (persistable == null) {
        throw new Exception("product is null for id " + product.getId());
    }
    java.util.Set<ProductAvailability> availabilities = persistable.getAvailabilities();
    for (ProductAvailability availability : availabilities) {
        ProductPrice productPrice = availability.defaultPrice();
        productPrice.setProductPriceAmount(price.getOriginalPrice());
        if (price.isDiscounted()) {
            productPrice.setProductPriceSpecialAmount(price.getDiscountedPrice());
            if (!StringUtils.isBlank(price.getDiscountStartDate())) {
                Date startDate = DateUtil.getDate(price.getDiscountStartDate());
                productPrice.setProductPriceSpecialStartDate(startDate);
            }
            if (!StringUtils.isBlank(price.getDiscountEndDate())) {
                Date endDate = DateUtil.getDate(price.getDiscountEndDate());
                productPrice.setProductPriceSpecialEndDate(endDate);
            }
        }
    }
    productService.update(persistable);
    ReadableProduct readableProduct = new ReadableProduct();
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    populator.populate(persistable, readableProduct, persistable.getMerchantStore(), language);
    return readableProduct;
}
Also used : ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) 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) Date(java.util.Date)

Example 79 with Product

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

the class ProductCommonFacadeImpl method getProductByCode.

@Override
public ReadableProduct getProductByCode(MerchantStore store, String uniqueCode, Language language) throws Exception {
    Product product = productService.getByCode(uniqueCode, language);
    ReadableProduct readableProduct = new ReadableProduct();
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    populator.populate(product, readableProduct, product.getMerchantStore(), language);
    return readableProduct;
}
Also used : ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct)

Example 80 with Product

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

the class ProductCommonFacadeImpl method update.

@Override
public void update(Long productId, LightPersistableProduct product, MerchantStore merchant, Language language) {
    // Get product
    Product modified = productService.findOne(productId, merchant);
    // Update product with minimal set
    modified.setAvailable(product.isAvailable());
    for (ProductAvailability availability : modified.getAvailabilities()) {
        availability.setProductQuantity(product.getQuantity());
        if (!StringUtils.isBlank(product.getPrice())) {
            // set default price
            for (ProductPrice price : availability.getPrices()) {
                if (price.isDefaultPrice()) {
                    try {
                        price.setProductPriceAmount(pricingService.getAmount(product.getPrice()));
                    } catch (ServiceException e) {
                        throw new ServiceRuntimeException("Invalid product price format");
                    }
                }
            }
        }
    }
    try {
        productService.save(modified);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot update product ", e);
    }
}
Also used : ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ServiceException(com.salesmanager.core.business.exception.ServiceException) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

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