Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SKU cannot be added to cart, quantity available null #1570

Closed
ipapachristoudis opened this issue Oct 18, 2016 · 2 comments
Closed

SKU cannot be added to cart, quantity available null #1570

ipapachristoudis opened this issue Oct 18, 2016 · 2 comments

Comments

@ipapachristoudis
Copy link

ipapachristoudis commented Oct 18, 2016

We have successfully implemented a site based on 4.0.6 version of Broadleaf. Lately, we tried to upgrade to 4.0.14, but we face the problem that a SKU cannot be added to cart. In store we have some products and their additional skus produced on a product size option.

From a quick view of the matter, an InventoryUnavailableException is raised at service.workflow.CheckAvailabilityActivity.

Furthermore, in CheckAvailabilityActivity

  • inventoryService.isAvailable(sku, requestedQuantity, inventoryContext) always returns false
  • inventoryService.retrieveQuantityAvailable(sku, inventoryContext) always returns null

If we switch back to 4.0.6 everything works as expected.

All categories have InventoryType as CheckAvailability. Also setting one particular product and it's SKUs to have CheckAvailability option has no effect.

In front store, calling sku.getQuantityAvailable returns the correct value.

Any clue for the matter???

PS The same error affects all versions>4.0.6

@ipapachristoudis
Copy link
Author

ipapachristoudis commented Oct 18, 2016

Well, i found the solution to this.

There is a bug in InventoryServiceImpl, in retrieveQuantitiesAvailable(Collection skus, Map<String, Object> context) method.

The method checks some stuff, but doesn't set the available quantity when there is one.

The correct implementation of this method should be
`
public Map<Sku, Integer> retrieveQuantitiesAvailable(Collection 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<Sku, Integer>();
        for (Sku sku : skus) {
            if (checkBasicAvailablility(sku)) {
                if (InventoryType.CHECK_QUANTITY.equals(sku.getInventoryType())) {
                    if (sku.getQuantityAvailable() == null) {
                        inventories.put(sku, 0);
                    }else{
                        inventories.put(sku, sku.getQuantityAvailable());
                    }
                } else if (sku.getInventoryType() == null || InventoryType.ALWAYS_AVAILABLE.equals(sku.getInventoryType())) {

                    inventories.put(sku, null);
                } else {
                    inventories.put(sku, 0);
                }
            } else {
                inventories.put(sku, 0);
            }
        }

        return inventories;
    } else {
        return holder.getResult();
    }
}

`

@Thanhbobo411
Copy link

sorry, can you explain for me?
I did like you but it still does not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants