1

I'm looking for a way to programmatically alter the unit price for products when adding them to an order via the backend (via a hook). I've seen some examples that make use of the cart hooks, but those aren't called via the backend.

Basically -- when someone chooses to add a line item and selects a product, when they add that product to the order, I want to be able to adjust the unit price. I've tried every hook I can think of and nothing seems to impact that process.

I've also tried to achieve this with rules, but there doesn't seem to be any event that is triggered when a product is selected and loaded to the order form. There are events for updating, creating, etc. -- but they are all triggered on save.

This is running on Drupal 7 with Commerce 7.

  • Is there a rules event called "Calculate the sell price of a product"? – Sam152 Jul 26 '17 at 12:15
  • drupal commerce on 7 or 8? – troseman Jul 30 '17 at 1:31
  • commerce 7. I'll update the description. – lcdservices Jul 30 '17 at 19:09
  • I have managed to implent this in my commerce quotation sandbox (drupal.org/sandbox/neograph734/2716607). With commerce you can set the unit price and total of every line item in an order and recalculate the order total. But I believe the update cart function overrid the changes so you had to include an exception. (It has been a while since I updated it.) You might be able to extract some code. I would recommend against using the complete module as it is not yet perfectly stable. – Neograph734 Jul 31 '17 at 13:23

Your Answer

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

Browse other questions tagged or ask your own question.