I finally posted the proposal for dynamic price pre-calculation after deleting it on accident once and then traveling home from a week in Michigan. : P
Focusing on the need to populate a table with data based on Rule applicability, I neglected to specify precisely how we would determine which Rules apply to which prices, what module would contain the code, and how these prices would then be displayed. Part of the problem is that dynamic pricing itself wasn't complete - there is a price object and Rules to manipulate it, but the calculated price doesn't appear anywhere. : )
So, this issue here is something of a meta-issue and will be broken apart as necessary. The gist of it is we need the following items resolved before dynamic price pre-calculation can happen:
- Convert the Price altering actions to use a line item instead of a price object.
- Find an appropriate home for the Rules event (right now it's in Price, but that won't do based on module dependencies... my hunch is Product Reference will have to do it unless we abstract it out to Line Item).
- Determine what entities have prices that need to be dynamically calculated (see, the line item has two price fields, products will have one or more, and none of these will be displayed in the same way).
The actual task of knowing what price needs to be dynamically calculated, finding the applicable Rules, and populate the commerce_calculated_price table isn't that difficult once the other pieces are in place.
Comments
Comment #1
rszrama commentedThis commit primarily addresses number two but by extension takes care of number three. The way it played out was code that depended on building product line items needed to stay in the Product Reference module. This is the module that defines the product line item type, and it's also the module that handles displaying product fields in nodes where a user will need to see a calculated sell price anyways. So, the event was moved there and the interaction with the Price module comes through the use of hooks (that need to be documented):
Those names suck, but I don't know how to shorten them without making them more confusing. Wanted this to land, and then will run through and update all the old actions to work directly on the line item unit price instead of a random price object. We will need to log changes to the price's data array somehow in the future.
Oh, and it's worth noting that this system is extensible, so other modules can let the Price module know they govern other calculated price fields just the same.
https://github.com/rszrama/drupalcommerce/commit/568560f01377332df756d67...
Comment #2
rszrama commentedAnd now number one is nailed as well:
https://github.com/rszrama/drupalcommerce/commit/32f13e97ad74bda89ca2bf7...
(Also, in case anyone is keeping score, the Product Reference Rules include file got bypassed on an earlier commit. If you're looking for it, it's in this commit.)
Comment #3
rszrama commentedJust a note that the first go at a database table and API level support for figuring out all the permutations of Rules / products to pre-calculate prices for is in this commit:
https://github.com/rszrama/drupalcommerce/commit/08b2a82b3fe7e0139fb4a82...
I still need to figure out how to execute only the actions from a subset of the available Rules for the event...
Comment #4
rszrama commentedAnd with this commit, the API function is actually saving to the database. Holy smokes, I think it works!
https://github.com/rszrama/drupalcommerce/commit/068a9ec76bb744adef0e1b4...
Now it just needs a UI and View integration. : D
Comment #5
rszrama commentedOk, got a little bit of the UI in, but I've realized I need to do some API refactoring to enable batching of sell price calculation and to get some queries out of the form builder / submit handler functions. After that I'll just need to implement basic Views support and call it beta ready.
https://github.com/rszrama/drupalcommerce/commit/c03ea5b8d3b6f7734d2046f...
Comment #6
rszrama commentedActually, I think we can safely consider this ticket closed. I'm going to spawn a few child issues that pertain to integrating pre-calculated prices into Views and to improving the API / UI, but the actual task of performing the calculation has been accomplished.