I'd like to add a button (or link) to the /cart/checkout/complete page. I will write the code to print the report that I need; however, I don't know which function to hook into. I suppose it's a hook_form_alter, but which one?
You could actually put it in through the checkout completion message in the checkout message settings.
As a test, I edited the Continue shopping message: in .../admin/store/settings/checkout/edit/messages to:
<p><a href="http://localhost/dev/">Click to return to the front page.</a></p>
<?php
print_r('Hello World.');
?>
The order id is [order-id].The output is:
Click to return to the front page.
print_r('Hello World.');
?>
The order id is 89.
I've tried input format of both 'PHP code' and 'Full HTML w/ Flash'. Both return the same results.
Why won't the PHP code execute?
hehe You would try the one I just had to patch last week. 
The display part of that had the input format misnamed, so PHP wasn't getting evaluated. I just patched it recently, and the fix will be in the 1.4 release.
Well, that helps a bit in the 'sanity' department!
When do you expect 1.4 to be released? It there a specific patch for this that is otherwise available?
I'm still not out of the woods. I installed ubercart 1.4 and it seems to resolve the issue I described above. I'm still having problems using tokens within a PHP block. I've used this same technique in workflow_ng without a problem.
Here's some test code I have in ...admin/store/settings/checkout/edit/messages (Continue shopping message):
order-id: [order-id]<br/>
<?php
$ord_id = '[order-id]';
$sql = "SELECT * FROM {uc_order_products} WHERE (order_id = $ord_id)";
print_r('$ord_id: '.$ord_id.'<br/>');
print_r('$sql: '.$sql.'<br/>');
$result = db_query(db_rewrite_sql($sql));
while ($row = @ mysql_fetch_array($result, MYSQL_BOTH)) {
// Stuff goes here...
}
?>The screen output is:
order-id: 123
$ord_id: 123
$sql: SELECT * FROM {uc_order_products} WHERE (order_id = 123)Drupal issues an SQL warning:
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[order-id])' at line 1 query: SELECT * FROM uc_order_products WHERE (order_id = [order-id]) in E:\Webpages\xampp\htdocs\dev\includes\database.mysql.inc on line 172
As you can see, the print_r() of $sql indicates the $ord_id is being evaluated as '123', the value of the token [order-id]; however, the db_query(db_rewrite_sql($sql)) is evaluating $ord_id literally as '[order-id]'.
I'm stumped! Is the PHP evaluation different in ...admin/store/settings/checkout/edit/messages vs. workflow_ng?
They are different, in fact.
With workflow-ng, what you are putting in is always expected to be PHP code. Because it expects you to use tokens for the entities you passed in, it replaces the tokens first, and then evaluates the PHP. If they didn't, the token integration wouldn't work very well.
For checkout messages, you are expected to craft some HTML or text like a template. Here, the input is run through the filters to get rid of malicious code, and then tokens are replaced. Evaluating PHP is an input filter, so that happens before tokens are run.
Off the top of my head, I don't see a reason why this couldn't change, though.
Looks like I'm beating my head against the wall with this approach. Perhaps someone can lead me in the right direction.
What I need to do is add text, which will include a link, to the cart/checkout/complete page after the [continue_shopping] message. It doesn't appear that I can use the suggested approach, i.e. add it to the checkout message since my text will be conditional upon data in the MySQL database. I can run PHP code within the checkout message; however, I can't seem to grab the value of [order-id] which I need for my PHP code.
So, would it make sense to add a div to the template located below the messages in cart/checkout/complete? If so, I would appreciate some guidance on how and where to create the div.
On the other hand, if someone will help me figure out how to grab [order-id] within a PHP block in the [continue_shopping] message, I'll take that approach.
Thanks.
Did you ever get this figured out?
>> "how to grab [order-id] within a PHP block"
I solved this with a session variable in hook_order at save.
$_SESSION['uc_coupon_oid'] = $arg1->order_id;And the code used in admin/store/settings/checkout/edit/messages
<?php
$order = uc_order_load($_SESSION['uc_coupon_oid']);
$coupon_message = t("Your coupon(s) have been e-mailed to the following addresse(s):") ."<br /><br />";
foreach ($order->products as $product) {
if ($product->model == 'gavekort') {
$print_message = TRUE;
$coupon_message .= t("Coupon: ") .uc_currency_format($product->price) .t(" sent to ") .$product->data['email'] ."<br />";
}
}
if ($print_message) { print $coupon_message ."<br /><br />"; }
unset($_SESSION['uc_coupon_oid']);
?>
