How to know total orders without tax

  • Posts: 177
  • Thank you received: 1
7 years 5 months ago #270505

-- HikaShop version -- : 3.1.0
-- Joomla version -- : latest

Hi guys,
i need to know trough SQL query how many orders i have in my db and calculate the total amount.

Looking inside db i discover that in the table _hikashop_order there is only the column named "order_full_price" that include all taxes. Is it right?
How can i know the total without taxes?

My query is:

SELECT SUM(order_full_price) FROM `#####_hikashop_order` WHERE order_status = "confirmed" 

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

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
7 years 5 months ago #270512

Hi,

There is no such data readily available in the database.
You would have to load the order_tax_info data, json_decode it, sum the different tax_amounts and substract the sum on the order_full_price.
If you have only one tax_amount per order all the time, you could do it in MySQL with some regex if it's imperative that it would be done in MySQL only.

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

  • Posts: 177
  • Thank you received: 1
7 years 5 months ago #270555

Hi Nicolas,
any help for the code?

I don't know hot to start to do it...

Thanks

Andrea

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

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
7 years 5 months ago #270556

Run the query:
SELECT * FROM `#__hikashop_order` WHERE order_status = "confirmed"
the you get an array of orders in PHP.
You loop on them like that:

$total without tax = 0;
foreach($orders as $order){
 $taxes = reset(json_decode($order->order_tax_info));
 $total without tax+= $order->order_full_price - $taxes->tax_amount;
}
echo $total without tax;
Of course that code is not tested. It's just an example of what it should look like. Please understand that this is outside the scope of our support.

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

  • Posts: 177
  • Thank you received: 1
7 years 5 months ago #270897

HI , sorry to be late.

I've tested this code:

<?php  $db = JFactory::getDbo(); 
$result = $db->setQuery("SELECT * FROM `*****_hikashop_order` WHERE order_status = 'confirmed'")->loadObject(); 
$total_without_tax = 0;
foreach($orders as $order){
 $taxes = reset(json_decode($order->order_tax_info));
 $total_without_tax+= $order->order_full_price - $taxes->tax_amount;
}
echo $total_without_tax;


?>
The output is 0 but is not true....

Any help ? :(

Last edit: 7 years 5 months ago by andreasuriani.

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

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
7 years 5 months ago #270901

Hi,

Please understand that we're not here to help you with PHP coding.
This is basic PHP...
The query results are stored in $result in your code, so you need to replace $orders by $result in your code.
Also, you're using loadObject which only returns one result instead of loadObjectList which will return all of them.

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

Time to create page: 0.063 seconds
Powered by Kunena Forum