Search in sources :

Example 1 with ProductVariation

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

the class ProductVariationFacadeImpl method delete.

@Override
public void delete(Long variationId, MerchantStore store) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(variationId, "variationId cannot be null");
    ProductVariation opt = productVariationService.getById(variationId);
    if (opt == null) {
        throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
    }
    if (!opt.getMerchantStore().getCode().equals(store.getCode())) {
        throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
    }
    try {
        productVariationService.delete(opt);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while deleting 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 2 with ProductVariation

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

the class ProductVariationFacadeImpl method exists.

@Override
public boolean exists(String code, MerchantStore store) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(code, "code cannot be null");
    ProductVariation var = productVariationService.getByCode(store, code);
    if (var != null) {
        return true;
    }
    return false;
}
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)

Example 3 with ProductVariation

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

the class PersistableProductInstanceMapper method merge.

@Override
public ProductInstance merge(PersistableProductInstance source, ProductInstance destination, MerchantStore store, Language language) {
    // 
    Long productVariant = source.getVariant();
    Long productVariantValue = source.getVariantValue();
    Optional<ProductVariation> variant = productVariationService.getById(store, productVariant);
    Optional<ProductVariation> variantValue = productVariationService.getById(store, productVariantValue);
    if (variant.isEmpty()) {
        throw new ResourceNotFoundException("ProductVariant [" + productVariant + "] + not found for store [" + store.getCode() + "]");
    }
    destination.setVariant(variant.get());
    if (variantValue.isEmpty()) {
        throw new ResourceNotFoundException("ProductVariant [" + productVariantValue + "] + not found for store [" + store.getCode() + "]");
    }
    destination.setVariantValue(variantValue.get());
    destination.setCode(variant.get().getCode() + ":" + variantValue.get().getCode());
    destination.setAvailable(source.isAvailable());
    destination.setDefaultSelection(source.isDefaultSelection());
    destination.setSku(source.getSku());
    if (StringUtils.isBlank(source.getDateAvailable())) {
        source.setDateAvailable(DateUtil.formatDate(new Date()));
    }
    if (source.getDateAvailable() != null) {
        try {
            destination.setDateAvailable(DateUtil.getDate(source.getDateAvailable()));
        } catch (Exception e) {
            throw new ServiceRuntimeException("Cant format date [" + source.getDateAvailable() + "]");
        }
    }
    destination.setSortOrder(source.getSortOrder());
    Product product = productService.getById(source.getProductId());
    if (product == null) {
        throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]");
    }
    if (product.getMerchantStore().getId() != store.getId()) {
        throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]");
    }
    destination.setProduct(product);
    return destination;
}
Also used : ProductVariation(com.salesmanager.core.model.catalog.product.variation.ProductVariation) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Date(java.util.Date) 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 4 with ProductVariation

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

the class ProductInstanceFacadeImpl method create.

@Override
public Long create(PersistableProductInstance productInstance, Long productId, MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(productInstance, "ProductInstance cannot be null");
    Validate.notNull(productId, "Product id cannot be null");
    // variation and variation value should not be of same product option code
    if (productInstance.getVariant() != null && productInstance.getVariant().longValue() > 0 && productInstance.getVariantValue() != null && productInstance.getVariantValue().longValue() > 0) {
        List<ProductVariation> variations = productVariationService.getByIds(Arrays.asList(productInstance.getVariant(), productInstance.getVariantValue()), store);
        boolean differentOption = variations.stream().map(i -> i.getProductOption().getCode()).distinct().count() > 1;
        if (!differentOption) {
            throw new ConstraintException("Product option of instance.variant and instance.variantValue must be different");
        }
    }
    productInstance.setProductId(productId);
    productInstance.setId(null);
    ProductInstance instance = persistableProductInstanceMapper.convert(productInstance, store, language);
    try {
        productInstanceService.save(instance);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot save product instance for store [" + store.getCode() + "] and productId [" + productId + "]", e);
    }
    return instance.getId();
}
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) ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductVariation(com.salesmanager.core.model.catalog.product.variation.ProductVariation) 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) ConstraintException(com.salesmanager.shop.store.api.exception.ConstraintException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 5 with ProductVariation

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

the class ProductVariationFacadeImpl method create.

@Override
public Long create(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");
    if (this.exists(var.getCode(), store)) {
        throw new OperationNotAllowedException("Option set with code [" + var.getCode() + "] already exist");
    }
    ProductVariation p = persistableProductVariationMapper.convert(var, store, language);
    p.setMerchantStore(store);
    try {
        productVariationService.saveOrUpdate(p);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while creating ProductOptionSet", e);
    }
    return p.getId();
}
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) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

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