Reputation: 1087
is it possible get last order id to order success page.? i just want to get last order id, so i can set a link to my template file success.tpl
that link will be go to last order info page..
i had tried something from controller/checkout/success.php
$this->load->model('checkout/order');
$order_last_id = $this->db->getLastId();
$this->data['order_info'] = $this->url->link('account/order/info', 'order_id=' . $order_last_id, 'SSL');
but, bad luck i get url with 0
order id
index.php?route=account/order/info&order_id=0
any one can help me for get last order id.?
thanks...
Upvotes: 3
Views: 7564
Reputation: 2490
I get orderID for opencart-2.0.3.1 as follows
/*after this this line: $this->model_account_activity->addActivity('order_guest', $activity_data);} */
$orderID = $this->session->data['order_id'];
Upvotes: 0
Reputation: 21
As long as you haven't edited the core files...
Add just before line 5 of /catalog/controller/checkout/success.php:
$this->data['order_id'] = $this->session->data['order_id'];
The problem you have is you're assuming that the user is logged in, and not a guest user, to get around this, check the user is a logged-in user, by adding this to your success.tpl
<p><?php echo "Your order ID is "; ?>
<?php if($logged) { ?>
<a href="index.php?route=account/order/info&order_id=<?php echo $order_id; ?>">
<?php } ?>
<?php echo $order_id; ?>
<?php if($logged) { ?>
</a>
<?php } ?>
</p>
This way, a link is created if they're logged in. If not, it just shows the ID number without the link.
Upvotes: 2
Reputation: 15151
Open /catalog/controller/checkout/success.php
and before this code
$this->cart->clear();
put
$this->data['order_id'] = $this->session->data['order_id'];
Then in your template use an if to test if the $order_id
isn't empty
<?php if(!empty($order_id)): ?>
... CODE HERE using $order ID ...
<?php endif; ?>
Upvotes: 10