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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations