When a customer selects some options / attributes in the product view, the function commerce_cart_add_to_cart_form_attributes_refresh() is called to refresh the view of the product. In the function the product price is recalculated. This happens by creating a pseudo line item.
If we have some other attributes then the core ones, like in Product Bundle or like in Product Option, we need to be able to alter the calculation by adding some additional information to this line item.
But there is no hook or any other altering mechanism, than overwriting the function commerce_cart_add_to_cart_form_attributes_refresh. But if we had multiple modules, that like to modify this, we get into trouble.
I would like to see, if some sort of altering hook can be added in this function. For the above mentioned modules I solve this by adding a third module Product Attributes. But this hook thing should move into the core, because we can get into a situation, where some contributed modules are incompatible.
Comments
Comment #1
rszrama commentedNot a full answer, but just to give the issue some context, the reason we don't allow for a hook when calculating the sell price of a product is to force everything to occur through the single Rules event. This is the only way we could assume some level of predictability for sell price pre-calculation, and relying on Rules conditions / actions is the only way we can really begin to know what data is being used in these Rules (to determine if they're even available for pre-calculation). A hook might work if it was accompanied by additional info declaration for the pre-calculation system to know how the hook was being used... but I fear that would quickly become unmanageable.
Comment #2
cimo75 commentedHi can anybody help me with creating a rule that will recalculate the price of a product when there is a selection in a Commerce Option attribute? I got it all setup but I still miss the final price calculation.
tx
Simone
Comment #3
rszrama commentedI'm not sure when we added the hook in relation to this issue, but hook_commerce_product_calculate_sell_price_line_item_alter() exists and seems to do exactly what the original post was requesting. Closing this out as fixed.