It would be great to get a technical overview of the module and how it integrates with the commerce_stock modules.
Also more details about what commerce_stock modules should be used and any configuration for example I assume you don't use the simple stock and simple stock rules and have a replacement set of rules that use the core stock action.
Keep up the good work :)

CommentFileSizeAuthor
#3 commerce_stock_reserve_flow_chart.png72.66 KBpjcdawkins

Comments

pjcdawkins’s picture

Yes, good point. Actually it is designed to work with Simple Stock and Simple Stock Rules, although it could work without them. I should make some kind of flow diagram. Have a good look at the commerce_stock_reserve() function for a start.

The main tricky bit is working out whether (and when) the product's stock itself should be altered. By default the product's stock is changed directly when stock is reserved or released, so that anything reacting on the stock level (like commerce_ssr's validation rules) works as normal.

The latest -dev is going to be the best version to work with right now.

pjcdawkins’s picture

This module actually (mildly) tampers with commerce_ssr's validation rules to make them account for reserved stock - see commerce_stock_reserve.rules_defaults.inc

pjcdawkins’s picture

Status: Active » Needs review
StatusFileSize
new72.66 KB

This is intended to clarify the sort of times when stock should be reserved or released. It's not really a "technical overview" yet.

Module flow chart

guy_schneerson’s picture

Status: Needs review » Reviewed & tested by the community

Hi @pjcdawkins - great diagram, it clears up the approach and the integration with simple stock looks spot on.
I don't know if we need more Technical overview than what you provided (its more then what most project got)
when I get more time will install and take the module for a proper spin.

pjcdawkins’s picture

Status: Reviewed & tested by the community » Fixed

Thanks. I've added this image to the project page.

And here's what happens in detail when stock is reserved or released.

Reserve stock for a line item

commerce_stock_reserve($line_item)

  1. check that it's a product line item, the product has stock enabled, and there is enough stock available
  2. decrement the product's stock via commerce_stock_reserve_set_product_stock()
  3. insert/update into {commerce_stock_reserve} the line item ID, product ID, the amount reserved (== line item quantity), and time reserved

Release stock for a line item

commerce_stock_reserve($line_item, TRUE)

  1. find the amount reserved for the line item in {commerce_stock_reserve}
  2. increment the product's stock via commerce_stock_reserve_set_product_stock()
  3. delete the record in {commerce_stock_reserve}
guy_schneerson’s picture

Hi @pjcdawkins
Thanks for the explanation, I did at the time have a quick look at the code but only after looking at the diagram it started falling into place.
Hope to find more time soon to look at it more closely and actually installing and using your module, looks like its a great addition. .

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.