Display total value of the orders for a client

  • Posts: 53
  • Thank you received: 2
10 years 9 months ago #144087

-- url of the page with the problem -- : www.vitaking.ro
-- HikaShop version -- : 2.2.3
-- Joomla version -- : 3.2
-- PHP version -- : 5.3.10
-- Browser(s) name and version -- : Chromium 31
-- Error-message(debug-mod must be tuned on) -- : Error_message

Hi,

We would like to display in the user orders history page the total value of all the orders, belonging to the current account. The problem is that if we are using the listing.php loop it gets displayed only the total value for the current pagination. Can you please give us some hint about how we can achieve this?

Regards,
Dezso Markon,
vitaking.ro

Please Log in or Create an account to join the conversation.

  • Posts: 73
  • Thank you received: 7
10 years 9 months ago #144102

You don't have the choice : you have to make a sql query to load all the prices.
Insert this code in the listing.php file :

$db = JFactory::getDBO();
$user_id = hikashop_loadUser();
$query = 'SELECT SUM(order_full_price) FROM  `#__hikashop_order` WHERE order_user_id = '.$user_id.';';
$db->setQuery($query);
$total= $db->loadObjectList();
The total you're looking for will be load in the $total[0] variable, I let you display it as your convenience.

The following user(s) said Thank You: otx

Please Log in or Create an account to join the conversation.

  • Posts: 53
  • Thank you received: 2
10 years 9 months ago #144111

Thank you!

Printing $total[0] renders the page inoperable.
My array looks like this: Array ( [0] => stdClass Object ( [SUM(order_full_price)] => 13874.35000 ))
So $total[0] it's not an integer or a value. I guess you know the solution for this ;)

Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
10 years 9 months ago #144234

instead of:
$total= $db->loadObjectList();
to:
$total= $db->loadResult();

and you'll get directly the price in the $total variable that you'll be able to print directly.

The following user(s) said Thank You: otx

Please Log in or Create an account to join the conversation.

  • Posts: 53
  • Thank you received: 2
10 years 9 months ago #144348

Thank you Nicolas, it's perfect!

Please Log in or Create an account to join the conversation.

Time to create page: 0.061 seconds
Powered by Kunena Forum