Sandy Grassineau Posted April 14 Share Posted April 14 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 More sharing options...
WebDesk Solution Posted June 6 Share Posted June 6 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.phpScreenshot: https://prnt.sc/ctoNCOWCwYmMCode: $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.twigScreenshot: https://prnt.sc/ouWNJwsQrpsoCode: {% 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 More sharing options...
ventura Posted June 6 Share Posted June 6 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 More sharing options...
Sandy Grassineau Posted June 6 Author Share Posted June 6 (edited) Hello, Thanks for your advice ! I tried to create a module (attached) but I got this error: attempted to load class “DecoratedOrderController” from namespace “TotalPrice\Controller”. Did you forget a “use” statement for another namespace? totalprice.zip totalprice.zip Edited June 6 by Sandy Grassineau (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now