Jump to content

Dashboard shows zero sales


Recommended Posts

Hi, are there any new suggestions about how to get the dashboard to show sales volume. mine is at zero. The graphs seem to be working ok as well as the Orders, Cart Value,Visits and Conversion Rate. I have tried everything icould find on teh forum to no avail. Prestashop v1.6.1.1

Link to comment
Share on other sites

Hi,

 

Easiest way I found to downgrade this module besides using a backup  --- download latest PS version 1.6.1.1 to your PC --- Extract on PC  ----  Go to Modules folder --- find and use the dashtrends module (0.7.5) from this download to replace the updated 0.8 version on your web server.

 

Don't update it until fixed. (It should show version 0.7.5 in BO Modules now)

 

I have done above and all working fine now.

It's missing the improvements added (ex tax wording and decimal point) but it shows Sales, Cart Value and Profit. 

Link to comment
Share on other sites

  • 1 month later...

I found this post and few similar other that Prestashop doesn't show sales statistics. I am experiencing the same problem even after upgrading Dashboard trends module to v0.8.1.
I only see stats for orders that has invoice generated. I don't generate invoice for all orders, but I need to see statistics.

I have two store - one is 1.6.0.9 and other 16.1.1 both are having the same problem with sales statistics.

Does anybody has any clue how to enable sales statistics for all orders, not just for those with invoices?

Link to comment
Share on other sites

  • 6 months later...

in statistics you see proper sales count?

Hello,

 

I am having this problem and it isn't recording in the sales count in statistics either. The only thing I had changed prior to this problem starting is a timezone as the time was an hour out since daylight savings here in the UK. I read somewhere else that I had to change the time zone, now sales numbers are not recorded anywhere, but the orders are being taken. 

 

I am on 1.6.1.1

 

Thanks for looking. 

 

EDIT: 

 

Ignore this. I just remembered that I had also changed the settings so an invoice is only available after shipment where as I allowed it from the initial order so this may be the issue. We wouldn't have shipped anything over the weekend so that wouldn't show on our sales now. 

Edited by djpat99 (see edit history)
Link to comment
Share on other sites

  • 5 months later...
  • 11 months later...
On 18/10/2017 at 2:49 PM, Israel A Santos said:

I have the same problem... downgrade did not work

The problem started on 2017-10-16

All days prior to 16 are ok

16,17 and 18 = 0 sales :/

 

- In AdminStats > Sales and Orders = ok ( click here and see print )

- In DashboardError ( click here and see print )

 

Prestashop 1.6.1.17

 

Hi! We have the same problem. It started at 2017-10-16 too. And 0 sales,, 0 visits, 0 all, however we have sales!  Did you find a solution?

PS 1.6.0.9

Link to comment
Share on other sites

  • 1 year later...

Tested in Prestashop 1.7.5.1, but probably same problem happens on other versions:

Looking at the code, the problem is quite obvious. Prestashop assumes that  "orders.invoice_date" is present. So if the invoice date is not set on your orders (let say you have disabled the invoices), the query won't find any records to sum, thus in some cases you get $0, or less than you expect.

I fixed it by replacing invoice_date with "date_add" which is the date when the order is created. Also the query checks if the order is valid.

With this fix there's no need to depend on invoices anymore.

What to do:

You need to update get getTotalSales method in:
controllers/admin/AdminStatsController.php

With:
 

public static function getTotalSales($date_from, $date_to, $granularity = false)
    {
        if ($granularity == 'day') {
            $sales = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 10) AS date, SUM(total_products / o.conversion_rate) AS sales
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 10)'
            );
            foreach ($result as $row) {
                $sales[strtotime($row['date'])] = $row['sales'];
            }

            return $sales;
        } elseif ($granularity == 'month') {
            $sales = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 7) AS date, SUM(total_products / o.conversion_rate) AS sales
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 7)'
            );
            foreach ($result as $row) {
                $sales[strtotime($row['date'] . '-01')] = $row['sales'];
            }

            return $sales;
        } else {
            return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
                '
			SELECT SUM(total_products / o.conversion_rate)
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o')
            );
        }
    }

 

Same thing happens with # of Orders, so here's the code (also in AdminStatsController.php😞

public static function getOrders($date_from, $date_to, $granularity = false)
    {
        if ($granularity == 'day') {
            $orders = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 10) AS date, COUNT(*) AS orders
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 10)'
            );
            foreach ($result as $row) {
                $orders[strtotime($row['date'])] = $row['orders'];
            }

            return $orders;
        } elseif ($granularity == 'month') {
            $orders = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 7) AS date, COUNT(*) AS orders
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 7)'
            );
            foreach ($result as $row) {
                $orders[strtotime($row['date'] . '-01')] = $row['orders'];
            }

            return $orders;
        } else {
            $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
                '
			SELECT COUNT(*) AS orders
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o')
            );
        }

        return $orders;
    }


Hope it helps. Good luck.

 

Edited by Mercader Virtual (see edit history)
  • Like 5
Link to comment
Share on other sites

  • 9 months later...
On 8/25/2019 at 4:39 AM, Mercader Virtual said:

Tested in Prestashop 1.7.5.1, but probably same problem happens on other versions:

Looking at the code, the problem is quite obvious. Prestashop assumes that  "orders.invoice_date" is present. So if the invoice date is not set on your orders (let say you have disabled the invoices), the query won't find any records to sum, thus in some cases you get $0, or less than you expect.

I fixed it by replacing invoice_date with "date_add" which is the date when the order is created. Also the query checks if the order is valid.

With this fix there's no need to depend on invoices anymore.

What to do:

You need to update get getTotalSales method in:
controllers/admin/AdminStatsController.php

With:
 


public static function getTotalSales($date_from, $date_to, $granularity = false)
    {
        if ($granularity == 'day') {
            $sales = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 10) AS date, SUM(total_products / o.conversion_rate) AS sales
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 10)'
            );
            foreach ($result as $row) {
                $sales[strtotime($row['date'])] = $row['sales'];
            }

            return $sales;
        } elseif ($granularity == 'month') {
            $sales = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 7) AS date, SUM(total_products / o.conversion_rate) AS sales
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 7)'
            );
            foreach ($result as $row) {
                $sales[strtotime($row['date'] . '-01')] = $row['sales'];
            }

            return $sales;
        } else {
            return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
                '
			SELECT SUM(total_products / o.conversion_rate)
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o')
            );
        }
    }

 

Same thing happens with # of Orders, so here's the code (also in AdminStatsController.php😞


public static function getOrders($date_from, $date_to, $granularity = false)
    {
        if ($granularity == 'day') {
            $orders = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 10) AS date, COUNT(*) AS orders
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 10)'
            );
            foreach ($result as $row) {
                $orders[strtotime($row['date'])] = $row['orders'];
            }

            return $orders;
        } elseif ($granularity == 'month') {
            $orders = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 7) AS date, COUNT(*) AS orders
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 7)'
            );
            foreach ($result as $row) {
                $orders[strtotime($row['date'] . '-01')] = $row['orders'];
            }

            return $orders;
        } else {
            $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
                '
			SELECT COUNT(*) AS orders
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o')
            );
        }

        return $orders;
    }


Hope it helps. Good luck.

 

Hi !
Thank you for the tip. Is this method is retroactive ? Will it display old orders after the update of these 2 files ?

Thanks a lot !

Link to comment
Share on other sites

26 minutes ago, Nesta92 said:

Hi !
Thank you for the tip. Is this method is retroactive ? Will it display old orders after the update of these 2 files ?

Thanks a lot !

Possibly!
Because the change filters data from the table, based on the date.

Create a backup of this file before making any changes.
Test and bring us your feedback ;)

Link to comment
Share on other sites

Just now, Israel A Santos said:

Possibly!
Because the change filters data from the table, based on the date.

Create a backup of this file before making any changes.
Test and bring us your feedback ;)

Thank you, just tried on Prestashop v1.7.6.5 but orders stats are still not correct. It only count orders with generated invoices :(

Link to comment
Share on other sites

  • 3 months later...

this solution not works for me... Version 1.7.6.7 neither after clean cache and update PHP.
It was PHP 7.1 and I updated to 7.2 trying to solve the issue. 
It was working well, but day 6-Sep stop to show sales and order stats. Don't run any update this day or later...
I already reseted the module millions of times and did NOTHING with the system this day.

I realy cannot find the issue...

Link to comment
Share on other sites

On 8/25/2019 at 4:39 AM, Mercader Virtual said:

Tested in Prestashop 1.7.5.1, but probably same problem happens on other versions:

Looking at the code, the problem is quite obvious. Prestashop assumes that  "orders.invoice_date" is present. So if the invoice date is not set on your orders (let say you have disabled the invoices), the query won't find any records to sum, thus in some cases you get $0, or less than you expect.

I fixed it by replacing invoice_date with "date_add" which is the date when the order is created. Also the query checks if the order is valid.

With this fix there's no need to depend on invoices anymore.

What to do:

You need to update get getTotalSales method in:
controllers/admin/AdminStatsController.php

With:
 


public static function getTotalSales($date_from, $date_to, $granularity = false)
    {
        if ($granularity == 'day') {
            $sales = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 10) AS date, SUM(total_products / o.conversion_rate) AS sales
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 10)'
            );
            foreach ($result as $row) {
                $sales[strtotime($row['date'])] = $row['sales'];
            }

            return $sales;
        } elseif ($granularity == 'month') {
            $sales = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 7) AS date, SUM(total_products / o.conversion_rate) AS sales
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 7)'
            );
            foreach ($result as $row) {
                $sales[strtotime($row['date'] . '-01')] = $row['sales'];
            }

            return $sales;
        } else {
            return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
                '
			SELECT SUM(total_products / o.conversion_rate)
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o')
            );
        }
    }

 

Same thing happens with # of Orders, so here's the code (also in AdminStatsController.php😞


public static function getOrders($date_from, $date_to, $granularity = false)
    {
        if ($granularity == 'day') {
            $orders = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 10) AS date, COUNT(*) AS orders
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 10)'
            );
            foreach ($result as $row) {
                $orders[strtotime($row['date'])] = $row['orders'];
            }

            return $orders;
        } elseif ($granularity == 'month') {
            $orders = array();
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
                '
			SELECT LEFT(`date_add`, 7) AS date, COUNT(*) AS orders
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o') . '
			GROUP BY LEFT(`date_add`, 7)'
            );
            foreach ($result as $row) {
                $orders[strtotime($row['date'] . '-01')] = $row['orders'];
            }

            return $orders;
        } else {
            $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
                '
			SELECT COUNT(*) AS orders
			FROM `' . _DB_PREFIX_ . 'orders` o
			LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON o.current_state = os.id_order_state
			WHERE `date_add` BETWEEN "' . pSQL($date_from) . ' 00:00:00" AND "' . pSQL($date_to) . ' 23:59:59" AND os.logable = 1 AND `valid` = 1
			' . Shop::addSqlRestriction(false, 'o')
            );
        }

        return $orders;
    }


Hope it helps. Good luck.

 

Dashtrends worked! PS 1.7.6.6 Tnx!

Dashgoals not working :(.

edit: found a solution :D here: https://github.com/PrestaShop/PrestaShop/issues/9662#issuecomment-475696541

Edited by Mistrz Yoda (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...