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

Code:

$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

Code:

{% if grid.id == "order" %}
<tfoot>
    <tr>
        <td colspan="10" class="text-right">
            <strong>{{ 'Order Total' }} : </strong>
        </td>
        <td>
            <strong>${{ totalPrice }}</strong>
        </td>
    </tr>
</tfoot>
{% 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

Link to comment
Share on other sites

awesome approach
It would be advisable to do it through a module that overwrite with a decorator

src/PrestaShopBundle/Controller/Admin/Sell/Order/OrderController.php 


and  also override 

src\PrestaShopBundle\Resources\views\Admin\Common\Grid\Blocks\table.html.twig


to preserve maintainability and scalability

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