Search in sources :

Example 1 with PersistableProductType

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

the class ProductTypeFacadeImpl method save.

@Override
public Long save(PersistableProductType type, MerchantStore store, Language language) {
    Validate.notNull(type, "ProductType cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(type.getCode(), "ProductType code cannot be empty");
    try {
        if (this.exists(type.getCode(), store, language)) {
            throw new OperationNotAllowedException("Product type [" + type.getCode() + "] already exist for store [" + store.getCode() + "]");
        }
        ProductType model = persistableProductTypeMapper.convert(type, store, language);
        model.setMerchantStore(store);
        ProductType saved = productTypeService.saveOrUpdate(model);
        return saved.getId();
    } catch (Exception e) {
        throw new ServiceRuntimeException("An exception occured while saving product type", e);
    }
}
Also used : ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) PersistableProductType(com.salesmanager.shop.model.catalog.product.type.PersistableProductType) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with PersistableProductType

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

the class ProductTypeFacadeImpl method update.

@Override
public void update(PersistableProductType type, Long id, MerchantStore store, Language language) {
    Validate.notNull(type, "ProductType cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(id, "id cannot be empty");
    try {
        ProductType t = productTypeService.getById(id, store, language);
        if (t == null) {
            throw new ResourceNotFoundException("Product type [" + type.getCode() + "] does not exist for store [" + store.getCode() + "]");
        }
        type.setId(t.getId());
        type.setCode(t.getCode());
        ProductType model = persistableProductTypeMapper.merge(type, t, store, language);
        model.setMerchantStore(store);
        productTypeService.saveOrUpdate(model);
    } catch (Exception e) {
        throw new ServiceRuntimeException("An exception occured while saving product type", e);
    }
}
Also used : ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) PersistableProductType(com.salesmanager.shop.model.catalog.product.type.PersistableProductType) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 3 with PersistableProductType

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

the class PersistableProductTypeMapper method type.

private ProductType type(PersistableProductType type, ProductType destination) throws ServiceException {
    if (destination == null) {
        destination = new ProductType();
    }
    destination.setCode(type.getCode());
    destination.setId(type.getId());
    destination.setAllowAddToCart(type.isAllowAddToCart());
    destination.setVisible(type.isVisible());
    // destination.set
    List<com.salesmanager.core.model.catalog.product.type.ProductTypeDescription> descriptions = new ArrayList<com.salesmanager.core.model.catalog.product.type.ProductTypeDescription>();
    if (!CollectionUtils.isEmpty(type.getDescriptions())) {
        for (ProductTypeDescription d : type.getDescriptions()) {
            com.salesmanager.core.model.catalog.product.type.ProductTypeDescription desc = typeDescription(d, destination, d.getLanguage());
            descriptions.add(desc);
        }
        destination.setDescriptions(new HashSet<com.salesmanager.core.model.catalog.product.type.ProductTypeDescription>(descriptions));
    }
    return destination;
}
Also used : ProductTypeDescription(com.salesmanager.shop.model.catalog.product.type.ProductTypeDescription) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) PersistableProductType(com.salesmanager.shop.model.catalog.product.type.PersistableProductType) ArrayList(java.util.ArrayList)

Aggregations

ProductType (com.salesmanager.core.model.catalog.product.type.ProductType)3 PersistableProductType (com.salesmanager.shop.model.catalog.product.type.PersistableProductType)3 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 ReadableProductType (com.salesmanager.shop.model.catalog.product.type.ReadableProductType)2 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 ProductTypeDescription (com.salesmanager.shop.model.catalog.product.type.ProductTypeDescription)1 ArrayList (java.util.ArrayList)1