Search in sources :

Example 86 with Product

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

the class ProductFacadeImpl method getProductBySeUrl.

@Override
public ReadableProduct getProductBySeUrl(MerchantStore store, String friendlyUrl, Language language) throws Exception {
    Product product = productService.getBySeUrl(store, friendlyUrl, LocaleUtils.getLocale(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 87 with Product

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

the class ProductFacadeImpl method relatedItems.

@Override
public List<ReadableProduct> relatedItems(MerchantStore store, Product product, Language language) throws Exception {
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    List<ProductRelationship> relatedItems = productRelationshipService.getByType(store, product, ProductRelationshipType.RELATED_ITEM);
    if (relatedItems != null && relatedItems.size() > 0) {
        List<ReadableProduct> items = new ArrayList<ReadableProduct>();
        for (ProductRelationship relationship : relatedItems) {
            Product relatedProduct = relationship.getRelatedProduct();
            ReadableProduct proxyProduct = populator.populate(relatedProduct, new ReadableProduct(), store, language);
            items.add(proxyProduct);
        }
        return items;
    }
    return null;
}
Also used : ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) 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)

Example 88 with Product

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

the class ProductFacadeV2Impl method getProductListsByCriterias.

@Override
public ReadableProductList getProductListsByCriterias(MerchantStore store, Language language, ProductCriteria criterias) throws Exception {
    // same as v1
    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) 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)

Example 89 with Product

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

the class ProductItemsFacadeImpl method listItemsByIds.

@Override
public ReadableProductList listItemsByIds(MerchantStore store, Language language, List<Long> ids, int startCount, int maxCount) throws Exception {
    if (CollectionUtils.isEmpty(ids)) {
        return new ReadableProductList();
    }
    ProductCriteria productCriteria = new ProductCriteria();
    productCriteria.setMaxCount(maxCount);
    productCriteria.setStartIndex(startCount);
    productCriteria.setProductIds(ids);
    com.salesmanager.core.model.catalog.product.ProductList products = productService.listByStore(store, language, productCriteria);
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    ReadableProductList productList = new ReadableProductList();
    for (Product product : products.getProducts()) {
        // create new proxy product
        ReadableProduct readProduct = populator.populate(product, new ReadableProduct(), store, language);
        productList.getProducts().add(readProduct);
    }
    productList.setNumber(Math.toIntExact(products.getTotalCount()));
    productList.setRecordsTotal(new Long(products.getTotalCount()));
    return productList;
}
Also used : ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) 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 90 with Product

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

the class ProductItemsFacadeImpl method listItemsByGroup.

@Override
public ReadableProductList listItemsByGroup(String group, MerchantStore store, Language language) throws Exception {
    // get product group
    List<ProductRelationship> groups = productRelationshipService.getByGroup(store, group, language);
    if (group != null) {
        List<Long> ids = new ArrayList<Long>();
        for (ProductRelationship relationship : groups) {
            Product product = relationship.getRelatedProduct();
            ids.add(product.getId());
        }
        ReadableProductList list = listItemsByIds(store, language, ids, 0, 0);
        List<ReadableProduct> prds = list.getProducts().stream().sorted(Comparator.comparing(ReadableProduct::getSortOrder)).collect(Collectors.toList());
        list.setProducts(prds);
        // no paging
        list.setTotalPages(1);
        return list;
    }
    return null;
}
Also used : ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct)

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