0

I have a complex calculation for item price in a custom line item that I'd like to keep in code rather than rules. Is there a hook that gets called before cart calculation so I can set unit price?

Where is cart pricing calculation done in commerce? trying to find where it's run in source.

Drupal 7 (using kickstart 2)

1

As Clive mentioned, there's hook_commerce_product_calculate_sell_price_line_item_alter() that lets you manipulate the line item prior to the sell price calculation process executing on it. However, whatever unit price you set via that hook may be overridden by Rules that you weren't intending to apply to those line items. In my opinion, the best thing to do would be to write a custom Rules action to encapsulate your pricing and call it in a sell price calculation rule.

  • thanks Ryan, that sounds good. have to get used to going to Rules rather than hooks. sounds like it's best to move all pricing and shipping business logic to rules to be most compatible. – troseman Mar 31 '17 at 21:06
  • Yeah, it was an unfortunate decision I made early in the 1.x dev process that added the dependency on Rules. I've been thinking about adding a way to remove that for a while ... should probably cut a 1.14 release and then make the Rules-less approach the first commit toward a 1.15. – Ryan Szrama Apr 1 '17 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.