Search in sources :

Example 81 with Product

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

the class ProductDefinitionFacadeImpl method saveProductDefinition.

@Override
public Long saveProductDefinition(MerchantStore store, PersistableProductDefinition product, Language language) {
    Product target = null;
    if (product.getId() != null && product.getId().longValue() > 0) {
        target = productService.getById(product.getId());
    } else {
        target = new Product();
    }
    try {
        target = persistableProductDefinitionMapper.merge(product, target, store, language);
        if (target.getId() != null && target.getId() > 0) {
            productService.update(target);
        } else {
            productService.create(target);
            product.setId(target.getId());
        }
        return target.getId();
    } catch (Exception e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : Product(com.salesmanager.core.model.catalog.product.Product) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 82 with Product

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

the class ProductFacadeImpl method getProduct.

@Override
public ReadableProduct getProduct(MerchantStore store, String sku, Language language) throws Exception {
    Product product = productService.getByCode(sku, language);
    if (product == null) {
        return null;
    }
    ReadableProduct readableProduct = new ReadableProduct();
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    populator.populate(product, readableProduct, store, language);
    return readableProduct;
}
Also used : ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct)

Example 83 with Product

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

the class ProductFacadeImpl method getProductByCode.

@Override
public ReadableProduct getProductByCode(MerchantStore store, String uniqueCode, Language language) {
    Product product = productService.getByCode(uniqueCode, language);
    ReadableProduct readableProduct = new ReadableProduct();
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    try {
        populator.populate(product, readableProduct, product.getMerchantStore(), language);
    } catch (ConversionException e) {
        throw new ConversionRuntimeException("Product with code [" + uniqueCode + "] cannot be converted", e);
    }
    return readableProduct;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 84 with Product

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

the class ProductFacadeImpl method getProductPrice.

@Override
public ReadableProductPrice getProductPrice(Long id, ProductPriceRequest priceRequest, MerchantStore store, Language language) {
    Validate.notNull(id, "Product id cannot be null");
    Validate.notNull(priceRequest, "Product price request cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    try {
        Product model = productService.findOne(id, store);
        // TODO check if null
        List<Long> attrinutesIds = priceRequest.getOptions().stream().map(p -> p.getId()).collect(Collectors.toList());
        List<ProductAttribute> attributes = productAttributeService.getByAttributeIds(store, model, attrinutesIds);
        for (ProductAttribute attribute : attributes) {
            if (attribute.getProduct().getId().longValue() != id.longValue()) {
                // throw unauthorized
                throw new OperationNotAllowedException("Attribute with id [" + attribute.getId() + "] is not attached to product id [" + id + "]");
            }
        }
        FinalPrice price;
        price = pricingService.calculateProductPrice(model, attributes);
        ReadableProductPrice readablePrice = new ReadableProductPrice();
        ReadableFinalPricePopulator populator = new ReadableFinalPricePopulator();
        populator.setPricingService(pricingService);
        return populator.populate(price, readablePrice, store, language);
    } catch (Exception e) {
        throw new ServiceRuntimeException("An error occured while getting product price", e);
    }
}
Also used : ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) ProductFacade(com.salesmanager.shop.store.controller.product.facade.ProductFacade) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableFinalPricePopulator(com.salesmanager.shop.populator.catalog.ReadableFinalPricePopulator) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Product(com.salesmanager.core.model.catalog.product.Product) ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) ProductPriceRequest(com.salesmanager.shop.model.catalog.product.ProductPriceRequest) ProductRelationshipService(com.salesmanager.core.business.services.catalog.product.relationship.ProductRelationshipService) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Profile(org.springframework.context.annotation.Profile) List(java.util.List) LocaleUtils(com.salesmanager.shop.utils.LocaleUtils) Validate(org.apache.commons.lang3.Validate) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ProductRelationshipType(com.salesmanager.core.model.catalog.product.relationship.ProductRelationshipType) ConversionException(com.salesmanager.core.business.exception.ConversionException) Comparator(java.util.Comparator) ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) ReadableFinalPricePopulator(com.salesmanager.shop.populator.catalog.ReadableFinalPricePopulator) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 85 with Product

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

the class ProductFacadeImpl method getProductListsByCriterias.

@Override
public ReadableProductList getProductListsByCriterias(MerchantStore store, Language language, ProductCriteria criterias) throws Exception {
    Validate.notNull(criterias, "ProductCriteria must be set for this product");
    /**
     * This is for category *
     */
    if (CollectionUtils.isNotEmpty(criterias.getCategoryIds())) {
        if (criterias.getCategoryIds().size() == 1) {
            com.salesmanager.core.model.catalog.category.Category category = categoryService.getById(criterias.getCategoryIds().get(0));
            if (category != null) {
                String lineage = new StringBuilder().append(category.getLineage()).toString();
                List<com.salesmanager.core.model.catalog.category.Category> categories = categoryService.getListByLineage(store, lineage);
                List<Long> ids = new ArrayList<Long>();
                if (categories != null && categories.size() > 0) {
                    for (com.salesmanager.core.model.catalog.category.Category c : categories) {
                        ids.add(c.getId());
                    }
                }
                ids.add(category.getId());
                criterias.setCategoryIds(ids);
            }
        }
    }
    Page<Product> modelProductList = productService.listByStore(store, language, criterias, criterias.getStartPage(), criterias.getMaxCount());
    List<Product> products = modelProductList.getContent();
    List<Product> prds = products.stream().sorted(Comparator.comparing(Product::getSortOrder)).collect(Collectors.toList());
    products = prds;
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    ReadableProductList productList = new ReadableProductList();
    for (Product product : products) {
        // create new proxy product
        ReadableProduct readProduct = populator.populate(product, new ReadableProduct(), store, language);
        productList.getProducts().add(readProduct);
    }
    // productList.setTotalPages(products.getTotalCount());
    productList.setRecordsTotal(modelProductList.getTotalElements());
    productList.setNumber(productList.getProducts().size());
    productList.setTotalPages(modelProductList.getTotalPages());
    return productList;
}
Also used : ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ArrayList(java.util.ArrayList) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator)

Aggregations

Product (com.salesmanager.core.model.catalog.product.Product)120 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)53 ArrayList (java.util.ArrayList)45 Language (com.salesmanager.core.model.reference.language.Language)42 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)41 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)36 ServiceException (com.salesmanager.core.business.exception.ServiceException)35 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)35 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)33 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)33 PersistableProduct (com.salesmanager.shop.model.catalog.product.PersistableProduct)29 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)28 List (java.util.List)25 Date (java.util.Date)23 LightPersistableProduct (com.salesmanager.shop.model.catalog.product.LightPersistableProduct)22 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 Category (com.salesmanager.core.model.catalog.category.Category)20 Collectors (java.util.stream.Collectors)20 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)19 ConversionException (com.salesmanager.core.business.exception.ConversionException)17