Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Show the Total the Customer Has Spent with Store


fat_dog

Recommended Posts

Hi,

 

I'm looking for the code I need to display the total the customer has ever spent with the store. For instance, "You have spent with us in total, ?7.63".

 

Basically it is the amount as displayed in customer_stats.php in admin - but I want to be able to display it per customer in their account.

 

Can anyone help please?

Link to comment
Share on other sites

look into your catalog\account_history.php extend the query to include the value column

 

$history_query_raw = "select o.orders_id, ot.value,.......

 

and then simply add it within the while loop below

 

$the_total += $history[value];

 

and afterwards display it.

 

echo $currencies->display_price($the_total,0);

Link to comment
Share on other sites

hi,

 

thanks for the reply. I'm probably being an idiot but I've added the code and the order value returns ?0.00. What am I doing wrong?

 

<?php
 $orders_total = tep_count_customer_orders();

 if ($orders_total > 0) {
$history_query_raw = "select o.orders_id, ot.value, o.date_purchased, o.delivery_name, o.billing_name, ot.text as order_total, s.orders_status_name from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_TOTAL . " ot, " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . (int)$customer_id . "' and o.orders_id = ot.orders_id and ot.class = 'ot_total' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' order by orders_id DESC";
$history_split = new splitPageResults($history_query_raw, MAX_DISPLAY_ORDER_HISTORY);
$history_query = tep_db_query($history_split->sql_query);

while ($history = tep_db_fetch_array($history_query)) {
  $products_query = tep_db_query("select count(*) as count from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$history['orders_id'] . "'");
  $products = tep_db_fetch_array($products_query);
  $the_total += $history[value];

  if (tep_not_null($history['delivery_name'])) {
	$order_type = TEXT_ORDER_SHIPPED_TO;
	$order_name = $history['delivery_name'];
  } else {
	$order_type = TEXT_ORDER_BILLED_TO;
	$order_name = $history['billing_name'];
  }
?>
<?php echo $currencies->display_price($the_total,0); ?>

Link to comment
Share on other sites

you did nothing wrong, I had a mistake missed the quotes from the value.

 

Use this

$the_total += $history['value'];

 

should be ok.

Link to comment
Share on other sites

woohoo! it works a treat!

 

Thank you VERY VERY much, I'm using this to create another page for the loyalty contrib called account_rewards.php that shows a table of the discount rates and what the customer is currently entitled too.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...