cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 Issue with Lifetime Sales Calculation

Magento 2 Issue with Lifetime Sales Calculation

Greetings Magento Community,

 

      As a Magento beginner, I've come across an issue that seems to be unique in my investigation, and I'm reaching out for guidance. Orders with a 'state' set to processing and 'status' marked as complete are not being included in the calculation for the total sales.

How can I retrieve the total of all orders with a 'complete' status to display it on the Magento admin dashboard?Could someone shed light on the inner workings of Magento's calculation process for Lifetime Sales?

I've scoured the internet but haven't found a similar case, and any insights or advice from the community would be immensely helpful.

Thank you in advance for your assistance and expertise!

1 REPLY 1

Re: Magento 2 Issue with Lifetime Sales Calculation

To retrieve the total sales from all orders with status "complete" in Magento, you can create a custom module with an admin dashboard widget that does a direct SQL query to the sales_order table.

The key steps would be:

1. Create a module with config.xml declaring a new admin dashboard widget

2. In the module's Block/Adminhtml folder create a new PHP file for the dashboard widget logic

3. Use a constructor to instantiate a connection to the read adapter resource model

4. Write a SELECT SQL query to sum the base_grand_total field from the sales_order table where the status equals 'complete'.

5. Return the query result into a formatted money or float amount to display

6. Set caching with lifetime and tags to improve performance

This will directly retrieve a sum of all completed order grand totals from the database for the dashboard, bypassing any business logic that may skip orders during calculation.

Avid learner and technical marketer at devrims.com