Ubercart allows interaction with orders using hook_order, in a nodeapi way.

Unfortunately there's no presave stage of this hook, so there's no direct way to modify an order before it's saved to database.

This simple patch adds a new op value for hook_order, 'presave', that's called just before order is saved to database.

Code added:

uc_order_module_invoke('presave', $order, NULL);
CommentFileSizeAuthor
ubcercart_order_presave.patch842 bytestunic
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tunic’s picture

Status: Active » Needs review

Changing status to 'needs review' because there's a patch attachted.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Trivial patch, and a useful feature.

Island Usurper’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs documentation

Thanks. Committed trivial patch. This $op should be documented in hooks.php, too.

longwave’s picture

Also needs porting to 7.x.

longwave’s picture

Status: Needs work » Fixed

Ported to 7.x and documented in both branches.

Status: Fixed » Closed (fixed)

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

dgtlmoon’s picture

I see this is not documented in http://www.ubercart.org/docs/api/hook_order

how can I change the documentation?

dgtlmoon’s picture

I found this hook because the 'save' $op did not appear to do what the documentation says it does..

save When an order object is being saved, the hook gets invoked with this op to let other modules do any necessary saving. $arg1 is a reference to the order object.

So what is the difference with presave? or does save happen after it has been written to the database?

tunic’s picture

Issue tags: -Needs documentation

It is documented in docs/hooks.php as said above:

 - presave: Before an order object is saved, the hook gets invoked with this
       op to let other modules alter order data before it is written to the
       database. $order is a reference to the order object.

Ubercart.org doc is a little bit outdatted, I think.

dgtlmoon’s picture

Thanks.

Yeah kind of annoying.