Page 1 of 1

Extending Broadleaf Inventory

Posted: Sat Feb 07, 2015 12:23 am
by gvsrini
I am trying to understand how to extend Broadleaf so that multiple Fulfilment locations (warehouses) can be added. I know that this is available in Commercial edition of Broadleaf, but I cannot afford it... :-)

I am planning to add few tables like blc_ext_fulfilment_locations (location_id,location_name) and blc_ext_fulfilment_location_inventory (location_id,sku_id,quantity).

The question is which is the right object to extend - InventoryServiceImpl or InventoryServiceExtensionHandler or CheckAvailabilityActivity as mentioned in http://www.broadleafcommerce.com/docs/c ... /inventory

I am assuming I should extend InventoryServiceImpl, but I am not able to get how the DAOs are actually getting called from the proxy in this call extensionManager.getProxy().retrieveQuantitiesAvailable.

Which piece of code do I modify so that I can retrieve Inventory from my table blc_ext_fulfilment_location_inventory instead of blc_sku.

I guess , below is the relevant code:

Code: Select all

@Service("blInventoryService")
public class InventoryServiceImpl implements ContextualInventoryService {

...

@Resource(name = "blInventoryServiceExtensionManager")
protected InventoryServiceExtensionManager extensionManager;

...

@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);
...
}
...
}

Re: Extending Broadleaf Inventory

Posted: Sat Feb 07, 2015 8:28 am
by gvsrini
I presume I have made some progress. I extended SkuImpl successfully and could use my customised table MY_SKU to hold inventory instead of BLC_SKU using the extended methods

Code: Select all

getQuantityAvailable()
and

Code: Select all

setQuantityAvailable(Integer quantityAvailable)
. Though this seems to be a step in the right direction, it does not fulfill my use case of handling multiple inventory locations/warehouses.

MY_SKU table needs to have an additional column - LOCATION_ID (as part of its Primary Key). I should obviously first be retrieving a record using the additional Location_id field. My use case will determine Location_id based on customer logged in. So, is MY_SKU the right object to work on, or do I need to do something drastically different to achieve my objective.

Any help to achieve the solution will be highly appreciated.

Re: Extending Broadleaf Inventory

Posted: Mon Feb 09, 2015 12:43 am
by phillipuniverse
InventoryServiceImpl is the right service to extend. You do not need to worry about the extension manager stuff if you are building it yourself.

Re: Extending Broadleaf Inventory

Posted: Wed Feb 11, 2015 7:52 am
by gvsrini
I thought I finished implemented everything when this thing struck me suddenly and now I seem to have no other option than to ask you!

I extended Order and stored warehouseId (chosen from the site front-end via a new page I created). This warehouseId, I need to pass to MyInventoryServiceImpl so that I can query my extended table and use it in my decrementInventory method as given below.

If I try to set warehouse id from my warehouse selection controller, it says MyInventoryImpl is actually a proxy and it cannot be casted to my inventory service bean.

My method in MyInventoryServiceImpl is like this:

@Resource(name = "blWarehouseSkuDao")
protected WarehouseSkuDaoImpl w;

...

@Override
public void decrementInventory(Map<Sku, Integer> skuQuantities,
Map<String, Object> context) throws InventoryUnavailableException {

for (Map.Entry<Sku, Integer> entry : skuQuantities.entrySet()) {
Sku sku = entry.getKey();
Integer value = entry.getValue();

WarehouseSkuImpl ws = w.getStock(warehouseId,sku.getId().intValue());
ws.setInventory(ws.getInventory()-value.intValue());

w.save(ws);
}

super.decrementInventory(skuQuantities, context);
}

Re: Extending Broadleaf Inventory

Posted: Wed Feb 11, 2015 10:58 pm
by gvsrini
Ok. I fixed it. I was using MyInventoryServiceImpl instead of the interface MyInventoryService.

Re: Extending Broadleaf Inventory

Posted: Sat Feb 14, 2015 12:07 am
by xudong
Hi, can you share the github gist of modification? thank you very much.

My country is not supported by broadleaf enterprise edition. :(