use of org.broadleafcommerce.common.extension.ExtensionResultHolder 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);
}
Aggregations