Search in sources :

Example 1 with InventoryType

use of org.broadleafcommerce.core.inventory.service.type.InventoryType in project BroadleafCommerce by BroadleafCommerce.

the class InventoryServiceImpl method retrieveQuantitiesAvailable.

@Override
public Map<Sku, Integer> retrieveQuantitiesAvailable(Collection<Sku> skus, Map<String, Object> context) {
    ExtensionResultHolder<Map<Sku, Integer>> holder = new ExtensionResultHolder<Map<Sku, Integer>>();
    ExtensionResultStatusType res = extensionManager.getProxy().retrieveQuantitiesAvailable(skus, context, holder);
    if (ExtensionResultStatusType.NOT_HANDLED.equals(res)) {
        Map<Sku, Integer> inventories = new HashMap<>();
        for (Sku sku : skus) {
            Integer quantityAvailable = 0;
            if (checkBasicAvailablility(sku)) {
                InventoryType skuInventoryType = sku.getInventoryType();
                if (InventoryType.CHECK_QUANTITY.equals(skuInventoryType)) {
                    if (sku.getQuantityAvailable() != null) {
                        quantityAvailable = sku.getQuantityAvailable();
                    }
                } else if (sku.getInventoryType() == null || InventoryType.ALWAYS_AVAILABLE.equals(skuInventoryType)) {
                    quantityAvailable = null;
                }
            }
            inventories.put(sku, quantityAvailable);
        }
        return inventories;
    } else {
        return holder.getResult();
    }
}
Also used : HashMap(java.util.HashMap) InventoryType(org.broadleafcommerce.core.inventory.service.type.InventoryType) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) Sku(org.broadleafcommerce.core.catalog.domain.Sku) HashMap(java.util.HashMap) Map(java.util.Map) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)1 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)1 Sku (org.broadleafcommerce.core.catalog.domain.Sku)1 InventoryType (org.broadleafcommerce.core.inventory.service.type.InventoryType)1