Search in sources :

Example 6 with ProductInstance

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

the class ProductInstanceFacadeImpl method delete.

@Override
public void delete(Long productInstance, Long productId, MerchantStore store) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(productInstance, "ProductInstance id cannot be null");
    Validate.notNull(productId, "Product id cannot be null");
    Optional<ProductInstance> instanceModel = this.getProductInstance(productInstance, productId, store);
    if (instanceModel.isEmpty()) {
        throw new ResourceNotFoundException("ProductInstance with id [" + productInstance + "] not found for store [" + store.getCode() + "] and productId [" + productId + "]");
    }
    try {
        productInstanceService.delete(instanceModel.get());
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot delete product instance [" + productInstance + "]  for store [" + store.getCode() + "] and productId [" + productId + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) 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) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 7 with ProductInstance

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

the class ProductInstanceGroupFacadeImpl method delete.

@Override
public void delete(Long productInstanceGroup, Long productId, MerchantStore store) {
    ProductInstanceGroup group = this.group(productInstanceGroup, store);
    if (group == null) {
        throw new ResourceNotFoundException("Product instance group [" + group.getId() + " not found for store [" + store.getCode() + "]");
    }
    try {
        // null all group from instances
        for (ProductInstance instance : group.getProductInstances()) {
            Optional<ProductInstance> p = productInstanceService.getById(instance.getId(), store);
            if (p.isEmpty()) {
                throw new ResourceNotFoundException("Product instance [" + instance.getId() + " not found for store [" + store.getCode() + "]");
            }
            instance.setProductInstanceGroup(null);
            productInstanceService.save(instance);
        }
        // now delete
        productInstanceGroupService.delete(group);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot remove product instance group [" + productInstanceGroup + "] for store [" + store.getCode() + "]");
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductInstanceGroup(com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup) ReadableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.ReadableProductInstanceGroup) PersistableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.PersistableProductInstanceGroup) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 8 with ProductInstance

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

the class PersistableProductIntanceGroupMapper method merge.

@Override
public ProductInstanceGroup merge(PersistableProductInstanceGroup source, ProductInstanceGroup destination, MerchantStore store, Language language) {
    Validate.notNull(source, "PersistableProductInstanceGroup cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Validate.notNull(source.getProductInstances(), "Product instances cannot be null");
    if (destination == null) {
        destination = new ProductInstanceGroup();
    }
    destination.setId(source.getId());
    List<ProductInstance> productInstances = productInstanceService.getByIds(source.getProductInstances(), store);
    for (ProductInstance p : productInstances) {
        p.setProductInstanceGroup(destination);
    }
    // images are not managed from this object
    if (source.getId() != null) {
        List<ProductInstanceImage> images = productInstanceImageService.listByProductInstanceGroup(source.getId(), store);
        destination.setImages(images);
    }
    destination.setMerchantStore(store);
    destination.setProductInstances(new HashSet<ProductInstance>(productInstances));
    return destination;
}
Also used : ProductInstanceImage(com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage) ProductInstanceGroup(com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup) PersistableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.PersistableProductInstanceGroup) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance)

Example 9 with ProductInstance

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

the class ReadableProductInstanceGroupMapper method merge.

@Override
public ReadableProductInstanceGroup merge(ProductInstanceGroup source, ReadableProductInstanceGroup destination, MerchantStore store, Language language) {
    Validate.notNull(source, "ProductInstanceGroup cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    if (destination == null) {
        destination = new ReadableProductInstanceGroup();
    }
    destination.setId(source.getId());
    Set<ProductInstance> instances = source.getProductInstances();
    destination.setProductInstances(instances.stream().map(i -> this.instance(i, store, language)).collect(Collectors.toList()));
    // image id should be unique in the list
    destination.setImages(source.getImages().stream().map(i -> this.image(i, store, language)).collect(Collectors.toList()));
    return destination;
}
Also used : ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) ReadableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.ReadableProductInstanceGroup)

Example 10 with ProductInstance

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

the class ReadableProductInstanceMapper method merge.

@Override
public ReadableProductInstance merge(ProductInstance source, ReadableProductInstance destination, MerchantStore store, Language language) {
    Validate.notNull(source, "Product instance cannot be null");
    Validate.notNull(source.getProduct(), "Product cannot be null");
    if (destination == null) {
        destination = new ReadableProductInstance();
    }
    destination.setSortOrder(source.getSortOrder() != null ? source.getSortOrder().intValue() : 0);
    destination.setAvailable(source.isAvailable());
    destination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
    destination.setId(source.getId());
    destination.setDefaultSelection(source.isDefaultSelection());
    destination.setProductId(source.getProduct().getId());
    destination.setSku(source.getSku());
    destination.setSortOrder(source.getSortOrder());
    destination.setCode(source.getCode());
    // get product
    Product baseProduct = source.getProduct();
    if (baseProduct == null) {
        throw new ResourceNotFoundException("Product instances do not include the parent product [" + destination.getSku() + "]");
    }
    destination.setProductShipeable(baseProduct.isProductShipeable());
    // destination.setStore(null);
    destination.setStore(store.getCode());
    destination.setVariant(readableProductVariationMapper.convert(source.getVariant(), store, language));
    destination.setVariantValue(readableProductVariationMapper.convert(source.getVariantValue(), store, language));
    if (source.getProductInstanceGroup() != null) {
        Set<String> nameSet = new HashSet<>();
        List<ReadableImage> instanceImages = source.getProductInstanceGroup().getImages().stream().map(i -> this.image(i, store, language)).filter(e -> nameSet.add(e.getImageUrl())).collect(Collectors.toList());
        destination.setImages(instanceImages);
    }
    if (!CollectionUtils.isEmpty(source.getAvailabilities())) {
        List<ReadableInventory> inventories = source.getAvailabilities().stream().map(i -> readableInventoryMapper.convert(i, store, language)).collect(Collectors.toList());
        destination.setInventory(inventories);
    }
    return destination;
}
Also used : ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) DateUtil(com.salesmanager.shop.utils.DateUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) CollectionUtils(org.apache.commons.collections.CollectionUtils) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ReadableProductVariationMapper(com.salesmanager.shop.mapper.catalog.ReadableProductVariationMapper) FileContentType(com.salesmanager.core.model.content.FileContentType) Mapper(com.salesmanager.shop.mapper.Mapper) Validate(org.jsoup.helper.Validate) Product(com.salesmanager.core.model.catalog.product.Product) Set(java.util.Set) ReadableInventoryMapper(com.salesmanager.shop.mapper.inventory.ReadableInventoryMapper) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) Collectors(java.util.stream.Collectors) ReadableInventory(com.salesmanager.shop.model.catalog.product.inventory.ReadableInventory) List(java.util.List) Component(org.springframework.stereotype.Component) ProductInstanceImage(com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ReadableInventory(com.salesmanager.shop.model.catalog.product.inventory.ReadableInventory) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) HashSet(java.util.HashSet)

Aggregations

ProductInstance (com.salesmanager.core.model.catalog.product.instance.ProductInstance)12 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)10 ReadableProductInstance (com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance)9 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)7 ServiceException (com.salesmanager.core.business.exception.ServiceException)6 Product (com.salesmanager.core.model.catalog.product.Product)5 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)5 Language (com.salesmanager.core.model.reference.language.Language)5 PersistableProductInstance (com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 ProductInstanceService (com.salesmanager.core.business.services.catalog.product.instance.ProductInstanceService)4 ReadableProductInstanceMapper (com.salesmanager.shop.mapper.catalog.product.ReadableProductInstanceMapper)4 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)4 ProductFacade (com.salesmanager.shop.store.controller.product.facade.ProductFacade)4 HashSet (java.util.HashSet)4 Validate (org.apache.commons.lang3.Validate)4 Page (org.springframework.data.domain.Page)4 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)3