Jump to content

Add Total Price at the Bottom of the Order Table

Recommended Posts

Version : prestashop 8.1.2


Hello everyone,

I'm working on the back office interface of our system and need some help. I have a table that lists all the orders, and I want to add a row at the bottom that shows the total price of all the orders displayed. Does anyone have advice or a code snippet on how to implement this feature? Any help would be greatly appreciated!


Thank you in advance!

Link to comment
Share on other sites

  • 1 month later...

Hello @Sandy Grassineau,

To add Total Price at the Bottom of the Order Table in PrestaShop back office please perform below steps :

Step 1: Navigate to the following path in your project's root directory and make the following changes:
Path: src\PrestaShopBundle\Controller\Admin\Sell\Order\OrderController.php
Screenshot: https://prnt.sc/ctoNCOWCwYmM


$totalPrice = 0;
foreach ($orderGrid->getData()->getRecords()->all() as $order) {
    if (isset($order['total_paid_tax_incl'])) {
        // Remove non-numeric characters except the decimal point
        $cleaned_total_paid_tax_incl = preg_replace('/[^0-9.]/', '', $order['total_paid_tax_incl']);

        // Convert to float to preserve decimal values
        $order_total_paid_tax_incl = (float)$cleaned_total_paid_tax_incl;

        // Add to total price
        $totalPrice += $order_total_paid_tax_incl;

Then, add this line: 'totalPrice' => $totalPrice as shown in the screenshot above.

Step 2: Now, we need to display the following below the order listing. Navigate to the following path from your project's root directory and add the code below:
Path: src\PrestaShopBundle\Resources\views\Admin\Common\Grid\Blocks\table.html.twig
Screenshot: https://prnt.sc/ouWNJwsQrpso


{% if grid.id == "order" %}
        <td colspan="10" class="text-right">
            <strong>{{ 'Order Total' }} : </strong>
            <strong>${{ totalPrice }}</strong>
{% endif %}

After making these changes, please clear the cache from the back office to see the changes in the PrestaShop Back Office.

Preview Output: https://prnt.sc/LU7loDdD2G7w

If you find our reply helpful, please hit Like it.
A North American PrestaShop Development Agency that delivers powerful results, innovation, and secure digital transformation.

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...