Zen Cart Logo
Forums / General Questions / Tracking customer transaction number

Tracking customer transaction number

Views: 953

Results 1 to 7 of 7
18 Dec 2013, 6:35 PM
#1
johnny_roastbeef avatar

johnny_roastbeef

New Zenner

Join Date:
Dec 2010
Posts:
56
Plugin Contributions:
0

Tracking customer transaction number

I would like to track how many orders a customer has made. The reason is that we would like to send a new customer kit with the first order, special promotional material with subsequent orders or even a small gift when a customer reaches a milestone. I know we can review each customer's history manually but that is not easy. It would be beneficial if there was a way to print a customer's number of orders on their invoice some where. Any suggestions?

18 Dec 2013, 7:53 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,084
Plugin Contributions:
56

Re: Tracking customer transaction number

Do you want the count of all orders that the customer has **placed **or the count of orders that the customer has paid for? What if the customer indicated that they were going to pay by check/moneyorder but the check never arrived? What if the customer placed an order that was subsequently refunded?

18 Dec 2013, 8:27 PM
#3
johnny_roastbeef avatar

johnny_roastbeef

New Zenner

Join Date:
Dec 2010
Posts:
56
Plugin Contributions:
0

Re: Tracking customer transaction number

We only accept instant transactions through CC or PayPal, so those numbers would be the same. Even if a customer has received a full or partial refund for a previous order the tally should be the same. A new customer should get a welcome packet and repeat customers would be entitled to coupons, even if they chose to return a product for some reason. Actually we get very few returns but rather an occasional exchange if an item is broken or of the wrong size. I'm happy to be "pretty" close in the calculation.

18 Dec 2013, 9:06 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,084
Plugin Contributions:
56

Re: Tracking customer transaction number

From the admin's invoice.php, you can add the following code just above the ?> above the <doctype statement:

  $c_info = $db->Execute("SELECT customers_id FROM " . TABLE_ORDERS . " WHERE orders_id = " . (int)$oID);
  $cID = ($c_info->EOF) ? 0 : $c_info->fields['customers_id'];
  $order_count = $db->Execute("SELECT count(*) as count FROM " . TABLE_ORDERS . " WHERE customers_id = $cID");

and then modify this fragment further down

  <tr>
    <td><table border="0" cellspacing="0" cellpadding="2">
      <tr>
        <td class="main"><strong><?php echo ENTRY_DATE_PURCHASED; ?></strong></td>
        <td class="main"><?php echo zen_date_long($order->info['date_purchased']); ?></td>
      </tr>
      <tr>
        <td class="main"><b><?php echo ENTRY_PAYMENT_METHOD; ?></b></td>
        <td class="main"><?php echo $order->info['payment_method']; ?></td>
      </tr>
    </table></td>
  </tr>

to include

  <tr>
    <td><table border="0" cellspacing="0" cellpadding="2">
      <tr>
        <td class="main"><strong>Number of orders:</strong></td>
        <td class="main"><?php echo $order_count->fields['count']; ?></td>
      </tr>
      <tr>
        <td class="main"><strong><?php echo ENTRY_DATE_PURCHASED; ?></strong></td>
        <td class="main"><?php echo zen_date_long($order->info['date_purchased']); ?></td>
      </tr>
      <tr>
        <td class="main"><b><?php echo ENTRY_PAYMENT_METHOD; ?></b></td>
        <td class="main"><?php echo $order->info['payment_method']; ?></td>
      </tr>
    </table></td>
  </tr>
18 Dec 2013, 10:24 PM
#5
gilby avatar

gilby

Totally Zenned

Join Date:
Aug 2005
Location:
Vic, Oz
Posts:
1,816
Plugin Contributions:
0

Re: Tracking customer transaction number

lat9:

From the admin's invoice.php, you can add the following code just above the ?> above the <doctype statement:

$c_info = $db->Execute("SELECT customers_id FROM " . TABLE_ORDERS . " WHERE orders_id = " . (int)$oID);
$cID = ($c_info->EOF) ? 0 : $c_info->fields['customers_id'];
$order_count = $db->Execute("SELECT count(*) as count FROM " . TABLE_ORDERS . " WHERE customers_id = $cID");

If the customer places 3 orders at the same time when you come to print them they will all have "3" on them.
I use a different method that generates a list of their orders and determines the position of that order in their total orders.
If the customer has only placed one order it is labelled as a "New Customer"
If the customer has placed 3 as above.
The first will be labelled 1 of 3
The second 2 of 3
The third 3 of 3.
Over time the numbering will change but you will always know when viewing the order the current status of the customer. (I also display this on the orders page)
18 Dec 2013, 11:13 PM
#6
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Tracking customer transaction number

I don't see a downside for the OP's purposes. All that is important is the current total number of orders, and if when they are printed out there are three invoices and the total reads "3", it should be obvious that the customer is new. It doesn't seem likely if the orders are attended to regularly that confusion would ever arise.

24 Jan 2014, 6:15 PM
#7
johnny_roastbeef avatar

johnny_roastbeef

New Zenner

Join Date:
Dec 2010
Posts:
56
Plugin Contributions:
0

Re: Tracking customer transaction number

I have implemented this code but unfortunately, when try to open the invoice I just get a blank page. Since coding is beyond my abilities, I have had to remove it.