Search in sources :

Example 6 with ProductVariation

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

the class ProductVariationFacadeImpl method update.

@Override
public void update(Long variationId, PersistableProductVariation var, MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Validate.notNull(var, "PersistableProductVariation cannot be null");
    Optional<ProductVariation> p = productVariationService.getById(store, variationId, language);
    if (p.isEmpty()) {
        throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
    }
    ProductVariation productVariant = p.get();
    productVariant.setId(variationId);
    productVariant.setCode(var.getCode());
    ProductVariation model = persistableProductVariationMapper.merge(var, productVariant, store, language);
    try {
        model.setMerchantStore(store);
        productVariationService.save(model);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while creating ProductVariation", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductVariation(com.salesmanager.core.model.catalog.product.variation.ProductVariation) ReadableProductVariation(com.salesmanager.shop.model.catalog.product.variation.ReadableProductVariation) PersistableProductVariation(com.salesmanager.shop.model.catalog.product.variation.PersistableProductVariation) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 7 with ProductVariation

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

the class ProductVariationFacadeImpl method get.

@Override
public ReadableProductVariation get(Long id, MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    ProductVariation variation = productVariationService.getById(store, id, language);
    if (variation == null) {
        throw new ResourceNotFoundException("ProductVariation not found for id [" + id + "] and store [" + store.getCode() + "]");
    }
    return readableProductVariationMapper.convert(variation, store, language);
}
Also used : ProductVariation(com.salesmanager.core.model.catalog.product.variation.ProductVariation) ReadableProductVariation(com.salesmanager.shop.model.catalog.product.variation.ReadableProductVariation) PersistableProductVariation(com.salesmanager.shop.model.catalog.product.variation.PersistableProductVariation) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Aggregations

ProductVariation (com.salesmanager.core.model.catalog.product.variation.ProductVariation)7 PersistableProductVariation (com.salesmanager.shop.model.catalog.product.variation.PersistableProductVariation)5 ReadableProductVariation (com.salesmanager.shop.model.catalog.product.variation.ReadableProductVariation)5 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)5 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)5 ServiceException (com.salesmanager.core.business.exception.ServiceException)4 Product (com.salesmanager.core.model.catalog.product.Product)2 ProductInstanceService (com.salesmanager.core.business.services.catalog.product.instance.ProductInstanceService)1 ProductVariationService (com.salesmanager.core.business.services.catalog.product.variation.ProductVariationService)1 ProductInstance (com.salesmanager.core.model.catalog.product.instance.ProductInstance)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 PersistableProductInstanceMapper (com.salesmanager.shop.mapper.catalog.product.PersistableProductInstanceMapper)1 ReadableProductInstanceMapper (com.salesmanager.shop.mapper.catalog.product.ReadableProductInstanceMapper)1 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)1 PersistableProductInstance (com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance)1 ReadableProductInstance (com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance)1 ReadableEntityList (com.salesmanager.shop.model.entity.ReadableEntityList)1 ConstraintException (com.salesmanager.shop.store.api.exception.ConstraintException)1 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)1