Forums / Templates, Stylesheets, Page Layout / Add order/invoice number to confirmation page

Add order/invoice number to confirmation page

Locked
Results 1 to 12 of 12
This thread is locked. New replies are disabled.
08 Apr 2008, 22:54
#1
microbe avatar

microbe

New Zenner

Join Date:
Aug 2007
Posts:
26
Plugin Contributions:
0

Add order/invoice number to confirmation page

Hey there,

Question about direct bank deposit page.

Customer places order, steps through cart and comes to step 3 of 3 - order confirmation.

It has all my bank details OK but there is no reference...matching payment to customer might become tricky.

In dirbank.php I have put in a line "Reference: " and the customer ID but what I would really like is the order number or invoice number.

Has it been generated by this point in execution? If so, where can I pick it up, even if setting a session variable earlier.

Thanks for any ideas.
09 Apr 2008, 01:40
#2
barco57 avatar

barco57

Totally Zenned

Join Date:
Apr 2006
Posts:
2,841
Plugin Contributions:
0

Re: Add order/invoice number to confirmation page

Order number has not been generated at this point. It is generated for the checkout success page. At the step 3 of 3 page I still have the ability to just leave and not confirm.
09 Apr 2008, 01:46
#3
microbe avatar

microbe

New Zenner

Join Date:
Aug 2007
Posts:
26
Plugin Contributions:
0

Re: Add order/invoice number to confirmation page

barco57:

Order number has not been generated at this point. It is generated for the checkout success page. At the step 3 of 3 page I still have the ability to just leave and not confirm.


Ah...that makes sense. Thanks for the reply. Perhaps I will just generate my own reference number.
17 Apr 2008, 03:25
#4
nuwanda avatar

nuwanda

New Zenner

Join Date:
Apr 2008
Posts:
24
Plugin Contributions:
0

Re: Add order/invoice number to confirmation page

The order number that is shown on the Checkout Success page (tpl_checkout_success_default.php) is in $zv_orders_id.

$zv_orders_id is generated in header_php.php with this code:

// find out the last order number generated for this customer account
$orders_query = "SELECT * FROM " . TABLE_ORDERS . "
                 WHERE customers_id = :customersID
                 ORDER BY date_purchased DESC LIMIT 1";
$orders_query = $db->bindVars($orders_query, ':customersID', $_SESSION['customer_id'], 'integer');
$orders = $db->Execute($orders_query);
$orders_id = $orders->fields['orders_id'];

// use order-id generated by the actual order process
// this uses the SESSION orders_id, or if doesn't exist, grabs most recent order # for this cust (needed for paypal et al).
// Needs reworking in v1.4 for checkout-rewrite
$zv_orders_id = (isset($_SESSION['order_number_created']) && $_SESSION['order_number_created'] >= 1) ? $_SESSION['order_number_created'] : $orders_id;
$orders_id = $zv_orders_id;


header_php.php is included in the Checkout Success page and that's why $zv_orders_id is available then but not before.

I'm guessin all you have to do is include the above code in the Checkout Confirmation page and you'll have the order id available then.

I haven't tested it though.

Any thoughts from the experts?
17 Apr 2008, 03:54
#5
nuwanda avatar

nuwanda

New Zenner

Join Date:
Apr 2008
Posts:
24
Plugin Contributions:
0

Re: Add order/invoice number to confirmation page

No, if you put it on the confirmation page, you get the previous order ID.

I'm missing something here since the next page--which uses the same code--gets the previous ID + 1, which is what you want.
17 Apr 2008, 04:05
#6
microbe avatar

microbe

New Zenner

Join Date:
Aug 2007
Posts:
26
Plugin Contributions:
0

Re: Add order/invoice number to confirmation page

I just dropped that code in dirbank.php as that is really when I want the reference number...if someone is doing a direct deposit.

Fatal error: Call to a member function bindVars() on a non-object


from the line

$orders_query = $db->bindVars($orders_query, ':customersID', $_SESSION['customer_id'], 'integer');


But I sense we are getting close to a solution and thank you for the suggestion.
18 Apr 2008, 23:32
#7
nuwanda avatar

nuwanda

New Zenner

Join Date:
Apr 2008
Posts:
24
Plugin Contributions:
0

Re: Add order/invoice number to confirmation page

Right, I hope this helps.

I modified the code in my post above to do a simple query on the orders table to retrieve the last order number used.

Here's the code:

$orders_query = "SELECT * FROM " . TABLE_ORDERS . "
                 ORDER BY date_purchased DESC LIMIT 1";
$orders = $db->Execute($orders_query);
$orders_id = $orders->fields['orders_id'];


And I placed it in /checkout_confirmation/header_php.php, although you could place it in the actual confirmation page markup I guess.

The code retrieves the LAST used order number, so you must add 1 to it so it matches the new order ID generated on the checkout success page, but that's no problem.

No data is altered in the process as the query only reads the orders table.

Testing: I tested the order ID using an existing test customer and also a newly created customer and it works fine, in both cases generating the new order ID - 1.

This of course is a brute force approach to the problem. I'm sure something more elegant exists using the proper procedures, but for the time being it will do.

If any of the Zen Cart experts know of a better solution, please let us know.
18 Apr 2008, 23:42
#8
microbe avatar

microbe

New Zenner

Join Date:
Aug 2007
Posts:
26
Plugin Contributions:
0

Re: Add order/invoice number to confirmation page

Thanks for that and you are right about brute force :frusty:- but it may not be a problem.

I think that if the cart has multiple people ordering at the same time there is a possibility of returning the wrong order number assuming an order number is generated when an order is commenced...but I might be wrong and it is generated at the point of checkout

You start your order (say order #1) add something to cart, go do more shopping, have lunch, maybe complete the order the next day even. Meanwhile someone else starts and completes and order (order #2).

Your then pull the most recent order number (the other person's = #2) and add one making your returned ID #3 where in fact the order was #1.

Now, as I say, this depends on when an order is given an order ID. Anyone know?
18 Apr 2008, 23:56
#9
nuwanda avatar

nuwanda

New Zenner

Join Date:
Apr 2008
Posts:
24
Plugin Contributions:
0

Re: Add order/invoice number to confirmation page

Yup, you're right, I should have realised.

I tested the scenario using FF and IE. I had one customer place and order up to the confirmation page where my code gave the order number.

I then had another customer place an order and of course at the confirmation page they got the same order number as the first customer, then they checked out and that order number was added to the database.

Then I went back and completed the order for my first customer and the order number on the checkout page was 1 higher--obviously--than it showed on the confirmation page.

So, back to square one: what I'll do in the meantime is add a highlighted note to my confirmation page that tells the customer to use the order number shown on the *next page* as their bank reference or cheque reference when paying. It's a little clunky for the customer but at least they'll get the correct order number.

Oh, the order number is obviously generated at checkout success stage.
19 Apr 2008, 00:05
#10
microbe avatar

microbe

New Zenner

Join Date:
Aug 2007
Posts:
26
Plugin Contributions:
0

Re: Add order/invoice number to confirmation page

I think the trick might be for a bit of code to generate our own reference number it we want it displayed before final checkout.

I am currently using CID-(customer ID) by dropping the following code into dirbank.php or where it is needed
"Reference: CID-" . $_SESSION['customer_id']


Given that it is relatively easy to match a customer ID to a sale it works, but it means looking up the customer ID if I am not sure.
19 Apr 2008, 01:44
#11
nuwanda avatar

nuwanda

New Zenner

Join Date:
Apr 2008
Posts:
24
Plugin Contributions:
0

Re: Add order/invoice number to confirmation page

Yes, that's a partial solution.

I think I'll just stick with putting a prominent reminder on the success page to use the order number as a ref.

It seems to me that this problem has never been addressed because maybe it's only countries like NZ/Australia that use direct deposit as a very common means of payment.
19 Apr 2008, 01:48
#12
microbe avatar

microbe

New Zenner

Join Date:
Aug 2007
Posts:
26
Plugin Contributions:
0

Re: Add order/invoice number to confirmation page

You could also add it to the confirmation email