Search in sources :

Example 1 with LightPersistableProduct

use of com.salesmanager.shop.model.catalog.product.LightPersistableProduct 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)

Example 2 with LightPersistableProduct

use of com.salesmanager.shop.model.catalog.product.LightPersistableProduct in project shopizer by shopizer-ecommerce.

the class ProductFacadeImpl 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) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ServiceException (com.salesmanager.core.business.exception.ServiceException)2 Product (com.salesmanager.core.model.catalog.product.Product)2 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)2 ProductPrice (com.salesmanager.core.model.catalog.product.price.ProductPrice)2 LightPersistableProduct (com.salesmanager.shop.model.catalog.product.LightPersistableProduct)2 PersistableProduct (com.salesmanager.shop.model.catalog.product.PersistableProduct)2 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 ReadableProductPrice (com.salesmanager.shop.model.catalog.product.ReadableProductPrice)1