Search in sources :

Example 71 with Product

use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.

the class UncacheableDataProcessor method addProductInventoryData.

protected void addProductInventoryData(Map<String, Object> attrMap, BroadleafTemplateContext context) {
    List<Long> outOfStockProducts = new ArrayList<>();
    List<Long> outOfStockSkus = new ArrayList<>();
    Set<Product> allProducts = new HashSet<>();
    Set<Sku> allSkus = new HashSet<>();
    Set<Product> products = (Set<Product>) context.getVariable("blcAllDisplayedProducts");
    Set<Sku> skus = (Set<Sku>) context.getVariable("blcAllDisplayedSkus");
    if (!CollectionUtils.isEmpty(products)) {
        allProducts.addAll(products);
    }
    if (!CollectionUtils.isEmpty(skus)) {
        allSkus.addAll(skus);
    }
    extensionManager.getProxy().modifyProductListForInventoryCheck(context, allProducts, allSkus);
    if (!allProducts.isEmpty()) {
        for (Product product : allProducts) {
            if (product.getDefaultSku() != null) {
                Boolean qtyAvailable = inventoryService.isAvailable(product.getDefaultSku(), 1);
                if (qtyAvailable != null && !qtyAvailable) {
                    outOfStockProducts.add(product.getId());
                } else {
                    InventoryServiceExtensionHandler handler = inventoryServiceExtensionManager.getProxy();
                    ExtensionResultHolder<Boolean> holder = new ExtensionResultHolder<>();
                    handler.isProductBundleAvailable(product, 1, holder);
                    Boolean available = holder.getResult();
                    if (available != null && !available) {
                        outOfStockProducts.add(product.getId());
                    }
                }
            }
        }
    } else {
        if (!allSkus.isEmpty()) {
            Map<Sku, Integer> inventoryAvailable = inventoryService.retrieveQuantitiesAvailable(allSkus);
            for (Map.Entry<Sku, Integer> entry : inventoryAvailable.entrySet()) {
                if (entry.getValue() == null || entry.getValue() < 1) {
                    outOfStockSkus.add(entry.getKey().getId());
                }
            }
        }
    }
    attrMap.put("outOfStockProducts", outOfStockProducts);
    attrMap.put("outOfStockSkus", outOfStockSkus);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) InventoryServiceExtensionHandler(org.broadleafcommerce.core.inventory.service.InventoryServiceExtensionHandler) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) HashMap(java.util.HashMap) Map(java.util.Map) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder) HashSet(java.util.HashSet)

Example 72 with Product

use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.

the class CategoryLinkedDataGeneratorImpl method addCategoryProductData.

protected void addCategoryProductData(final HttpServletRequest request, final JSONObject categoryData) throws JSONException {
    final List<Product> products = getProducts(request);
    final JSONArray itemList = new JSONArray();
    for (int i = 0; i < products.size(); i++) {
        JSONObject item = new JSONObject();
        item.put("@type", "ListItem");
        item.put("position", i + 1);
        item.put("url", products.get(i).getUrl());
        itemList.put(item);
        extensionManager.getProxy().addCategoryProductData(request, categoryData);
    }
    categoryData.put("itemListElement", itemList);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) Product(org.broadleafcommerce.core.catalog.domain.Product)

Example 73 with Product

use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.

the class ProductLinkedDataGeneratorImpl method getLinkedDataJsonInternal.

@Override
protected JSONArray getLinkedDataJsonInternal(final String url, final HttpServletRequest request, final JSONArray schemaObjects) throws JSONException {
    final Product product = getProduct(request);
    if (product != null) {
        final JSONObject productData = addProductData(request, product, url);
        addReviewData(request, product, productData);
        schemaObjects.put(productData);
    }
    return schemaObjects;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) Product(org.broadleafcommerce.core.catalog.domain.Product)

Example 74 with Product

use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.

the class DatabaseSearchServiceImpl method findSearchResultsByQuery.

@Override
public SearchResult findSearchResultsByQuery(String query, SearchCriteria searchCriteria) {
    SearchResult result = new SearchResult();
    setQualifiedKeys(searchCriteria);
    List<Product> products = catalogService.findFilteredActiveProductsByQuery(query, searchCriteria);
    List<SearchFacetDTO> facets = getSearchFacets();
    setActiveFacets(facets, searchCriteria);
    result.setProducts(products);
    result.setFacets(facets);
    result.setTotalResults(products.size());
    result.setPage(1);
    result.setPageSize(products.size());
    return result;
}
Also used : SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) Product(org.broadleafcommerce.core.catalog.domain.Product) SearchResult(org.broadleafcommerce.core.search.domain.SearchResult)

Example 75 with Product

use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.

the class DatabaseSearchServiceImpl method findSearchResultsByCategory.

@Override
public SearchResult findSearchResultsByCategory(Category category, SearchCriteria searchCriteria) {
    SearchResult result = new SearchResult();
    setQualifiedKeys(searchCriteria);
    List<Product> products = catalogService.findFilteredActiveProductsByCategory(category, searchCriteria);
    List<SearchFacetDTO> facets = getCategoryFacets(category);
    setActiveFacets(facets, searchCriteria);
    result.setProducts(products);
    result.setFacets(facets);
    result.setTotalResults(products.size());
    result.setPage(1);
    result.setPageSize(products.size());
    return result;
}
Also used : SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) Product(org.broadleafcommerce.core.catalog.domain.Product) SearchResult(org.broadleafcommerce.core.search.domain.SearchResult)

Aggregations

Product (org.broadleafcommerce.core.catalog.domain.Product)77 Sku (org.broadleafcommerce.core.catalog.domain.Sku)34 ArrayList (java.util.ArrayList)23 Category (org.broadleafcommerce.core.catalog.domain.Category)18 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)17 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)12 Order (org.broadleafcommerce.core.order.domain.Order)12 Transactional (org.springframework.transaction.annotation.Transactional)11 Test (org.testng.annotations.Test)11 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)10 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)9 Money (org.broadleafcommerce.common.money.Money)9 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)9 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)8 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)7 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)7 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 RelatedProduct (org.broadleafcommerce.core.catalog.domain.RelatedProduct)6 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)6