In the api documentation for commerce_cart_order_new(), it states:

* @param $uid
* The uid of the user for whom to create the order. If left 0, the order will
* be created for the current user and associated with his or her session.

From what I can tell, if no uid is passed, $uid defaults to 0 which creates an order for the anonymous user, not the current user.

commerce_cart_order_new() calls commerce_order_new() but that doesn't do anything special with a $uid == 0 either...

I know we can just pass in $user->uid to be safe, but was just wondering if the documentation is correct or is the code correct?

Thanks

Comments

rszrama’s picture

Title: Arg: $uid for commerce_cart_order_new() » Parameter documentation for commerce_cart_order_new() is out of date
Category: bug » task
Status: Active » Fixed

I answered this in the Commerce Q&A before seeing you posted it here. For code topics like this where there's a discrepancy in the docs, you only need to post a documentation task to the queue - no need to post in both places.

(Still put API usage support requests in Q&A, though. : )

Here was my answer there in case you didn't see it. I'm going to delete the Question since we have the issue here for record:


In this case, it looks to me like the parameter documentation and function behavior are slightly mismatched. The order ID would indeed be saved to the current user's session, but the order itself would not be created for the current user. That would only be true in the event that the current user is anonymous.

I think the best thing to do will be to update the documentation to read that it will be created for an anonymous user and associated with the current user's session if he or she is anonymous. In fact, I'll update that right now. : )

Commit: http://drupalcode.org/project/commerce.git/commitdiff/365eed9

Status: Fixed » Closed (fixed)

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