From c6a2051f8359c6611518dc803ace3dfdc2c59cfb Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Mon, 23 Nov 2026 22:30:58 +0100 Subject: [PATCH] [BUGFIX] Show the taxes in the order views The cart tables of the order in the backend and in the frontend used properties which do not exist in the order models, so no tax column was rendered and the frontend showed neither shipping nor payment. The taxes of products, shipping and payment are shown in the column of their tax class. The tax class of an order discount is not stored, its row keeps empty tax columns. Resolves: #884 Co-Authored-By: Claude Opus 5.5 --- .../Backend/Order/Show/CartTable/Body.html | 18 +-- .../Backend/Order/Show/CartTable/Footer.html | 130 +++++++--------- .../Backend/Order/Show/CartTable/Header.html | 10 +- .../Order/Show/CartTable/TaxColumns.html | 15 ++ .../Private/Partials/Order/Show/Cart.html | 8 +- .../Private/Partials/Order/Show/Product.html | 16 +- .../Private/Partials/Order/Show/Summary.html | 86 +++++----- .../Partials/Order/Show/TaxColumns.html | 20 +++ .../Templates/Backend/Order/Cart.html | 5 + .../Fixtures/Templates/Order/Cart.html | 5 + .../Templates/Fixtures/OrderWithTaxes.php | 91 +++++++++++ .../Templates/OrderTaxColumnsTest.php | 147 ++++++++++++++++++ 12 files changed, 391 insertions(+), 160 deletions(-) create mode 100644 Resources/Private/Partials/Backend/Order/Show/CartTable/TaxColumns.html create mode 100644 Resources/Private/Partials/Order/Show/TaxColumns.html create mode 100644 Tests/Functional/Fixtures/Templates/Backend/Order/Cart.html create mode 100644 Tests/Functional/Fixtures/Templates/Order/Cart.html create mode 100644 Tests/Functional/Templates/Fixtures/OrderWithTaxes.php create mode 100644 Tests/Functional/Templates/OrderTaxColumnsTest.php diff --git a/Resources/Private/Partials/Backend/Order/Show/CartTable/Body.html b/Resources/Private/Partials/Backend/Order/Show/CartTable/Body.html index 3b3c6192..8ec7b86e 100644 --- a/Resources/Private/Partials/Backend/Order/Show/CartTable/Body.html +++ b/Resources/Private/Partials/Backend/Order/Show/CartTable/Body.html @@ -25,23 +25,13 @@ {product.gross} - - - - - {product.orderTax.tax} - - - - - - - + + arguments="{product: product, totalTaxes: orderItem.totalTax, currencySign: orderItem.currency}"/> - \ No newline at end of file + diff --git a/Resources/Private/Partials/Backend/Order/Show/CartTable/Footer.html b/Resources/Private/Partials/Backend/Order/Show/CartTable/Footer.html index 33139801..14a9417f 100644 --- a/Resources/Private/Partials/Backend/Order/Show/CartTable/Footer.html +++ b/Resources/Private/Partials/Backend/Order/Show/CartTable/Footer.html @@ -12,90 +12,70 @@ {orderItem.gross} - + - {orderTax.tax} + + + {tax.tax} + + - - - : {orderItem.shipping.name} - - - {orderItem.shipping.net} - - - {orderItem.shipping.gross} - - + + + + : {orderItem.shipping.name} + - - - {orderItem.shipping.orderTax.tax} - - - - - + {orderItem.shipping.net} - - - - - - : {orderItem.payment.name} - - - {orderItem.payment.net} - - - {orderItem.payment.gross} - - - - - {orderItem.payment.orderTax.tax} - - - - - + {orderItem.shipping.gross} - - + + + - - - - - - {orderDiscount.title} - - - {orderDiscount.net} - - - {orderDiscount.gross} - - - - - - {orderDiscount.orderTax.tax} - - - - - - - - - + + + + : {orderItem.payment.name} + + + {orderItem.payment.net} + + + {orderItem.payment.gross} + + + + + + + + {orderDiscount.title} + + + {orderDiscount.net} + + + {orderDiscount.gross} + + + The tax class of a discount is not stored in the order, so its tax can not be assigned to a column. + + + + + + + @@ -106,10 +86,10 @@ {orderItem.totalGross} - + - {orderTotalTax.tax} + {totalTax.tax} - \ No newline at end of file + diff --git a/Resources/Private/Partials/Backend/Order/Show/CartTable/Header.html b/Resources/Private/Partials/Backend/Order/Show/CartTable/Header.html index 7b0e1c6c..dcea0daa 100644 --- a/Resources/Private/Partials/Backend/Order/Show/CartTable/Header.html +++ b/Resources/Private/Partials/Backend/Order/Show/CartTable/Header.html @@ -23,10 +23,10 @@ - - - - + + + + - \ No newline at end of file + diff --git a/Resources/Private/Partials/Backend/Order/Show/CartTable/TaxColumns.html b/Resources/Private/Partials/Backend/Order/Show/CartTable/TaxColumns.html new file mode 100644 index 00000000..90ff855e --- /dev/null +++ b/Resources/Private/Partials/Backend/Order/Show/CartTable/TaxColumns.html @@ -0,0 +1,15 @@ + + + + One column per tax class of the order (totalTaxes), the tax is shown in the column of its tax class. + + + + + {tax} + + + + diff --git a/Resources/Private/Partials/Order/Show/Cart.html b/Resources/Private/Partials/Order/Show/Cart.html index 23257516..ec22b756 100644 --- a/Resources/Private/Partials/Order/Show/Cart.html +++ b/Resources/Private/Partials/Order/Show/Cart.html @@ -25,10 +25,10 @@ - + - + @@ -36,7 +36,7 @@ + arguments="{product: product, totalTaxes: orderItem.totalTax, currencySign: orderItem.currency}"/> diff --git a/Resources/Private/Partials/Order/Show/Product.html b/Resources/Private/Partials/Order/Show/Product.html index 4c55ff39..49165214 100644 --- a/Resources/Private/Partials/Order/Show/Product.html +++ b/Resources/Private/Partials/Order/Show/Product.html @@ -24,17 +24,7 @@ {product.gross} - - - - - {product.orderTax.tax} - - -   - - - - + - \ No newline at end of file + diff --git a/Resources/Private/Partials/Order/Show/Summary.html b/Resources/Private/Partials/Order/Show/Summary.html index a1ea5d4e..c2ef7905 100644 --- a/Resources/Private/Partials/Order/Show/Summary.html +++ b/Resources/Private/Partials/Order/Show/Summary.html @@ -12,62 +12,50 @@ {orderItem.gross} - + - {orderTax.tax} + + + {tax.tax} + + - - - - {orderItem.orderShipping.name} - - - {orderItem.orderShipping.net} - - - {orderItem.orderShipping.gross} - - + + + + + {orderItem.shipping.name} + - - - {orderItem.orderShipping.orderTax.tax} - - -   - - + {orderItem.shipping.net} - - + + {orderItem.shipping.gross} + + + + - - - - {orderItem.orderPayment.name} - - - {orderItem.orderPayment.net} - - - {orderItem.orderPayment.gross} - - + + + + + {orderItem.payment.name} + - - - {orderItem.orderPayment.orderTax.tax} - - -   - - + {orderItem.payment.net} - - + + {orderItem.payment.gross} + + + + @@ -79,10 +67,10 @@ {orderItem.totalGross} - + - {orderTotalTax.tax} + {totalTax.tax} - \ No newline at end of file + diff --git a/Resources/Private/Partials/Order/Show/TaxColumns.html b/Resources/Private/Partials/Order/Show/TaxColumns.html new file mode 100644 index 00000000..44c61867 --- /dev/null +++ b/Resources/Private/Partials/Order/Show/TaxColumns.html @@ -0,0 +1,20 @@ + + + + One column per tax class of the order (totalTaxes), the tax is shown in the column of its tax class. + + + + + + {tax} + + +   + + + + + diff --git a/Tests/Functional/Fixtures/Templates/Backend/Order/Cart.html b/Tests/Functional/Fixtures/Templates/Backend/Order/Cart.html new file mode 100644 index 00000000..50fb570f --- /dev/null +++ b/Tests/Functional/Fixtures/Templates/Backend/Order/Cart.html @@ -0,0 +1,5 @@ + + + + diff --git a/Tests/Functional/Fixtures/Templates/Order/Cart.html b/Tests/Functional/Fixtures/Templates/Order/Cart.html new file mode 100644 index 00000000..9d58d6c4 --- /dev/null +++ b/Tests/Functional/Fixtures/Templates/Order/Cart.html @@ -0,0 +1,5 @@ + + + + diff --git a/Tests/Functional/Templates/Fixtures/OrderWithTaxes.php b/Tests/Functional/Templates/Fixtures/OrderWithTaxes.php new file mode 100644 index 00000000..93420884 --- /dev/null +++ b/Tests/Functional/Templates/Fixtures/OrderWithTaxes.php @@ -0,0 +1,91 @@ + [ + [ + 'uid' => 1, + 'pid' => 1, + 'currency' => '€', + 'gross' => 34.50, + 'net' => 30.00, + 'total_gross' => 29.74, + 'total_net' => 26.00, + ], + ], + 'tx_cart_domain_model_order_taxclass' => [ + ['uid' => 1, 'pid' => 1, 'item' => 1, 'title' => 'normal', 'value' => '19', 'calc' => 0.19], + ['uid' => 2, 'pid' => 1, 'item' => 1, 'title' => 'reduced', 'value' => '7', 'calc' => 0.07], + ], + 'tx_cart_domain_model_order_product' => [ + [ + 'uid' => 1, + 'pid' => 1, + 'item' => 1, + 'sku' => 'book', + 'title' => 'Book', + 'count' => 1, + 'price' => 10.70, + 'gross' => 10.70, + 'net' => 10.00, + 'tax' => 0.70, + 'tax_class' => 2, + ], + [ + 'uid' => 2, + 'pid' => 1, + 'item' => 1, + 'sku' => 'shirt', + 'title' => 'Shirt', + 'count' => 1, + 'price' => 23.80, + 'gross' => 23.80, + 'net' => 20.00, + 'tax' => 3.80, + 'tax_class' => 1, + ], + ], + 'tx_cart_domain_model_order_shipping' => [ + [ + 'uid' => 1, + 'pid' => 1, + 'item' => 1, + 'name' => 'Standard', + 'gross' => 5.95, + 'net' => 5.00, + 'tax' => 0.95, + 'tax_class' => 1, + ], + ], + 'tx_cart_domain_model_order_payment' => [ + [ + 'uid' => 1, + 'pid' => 1, + 'item' => 1, + 'name' => 'Invoice', + 'gross' => 1.19, + 'net' => 1.00, + 'tax' => 0.19, + 'tax_class' => 1, + ], + ], + 'tx_cart_domain_model_order_discount' => [ + [ + 'uid' => 1, + 'pid' => 1, + 'item' => 1, + 'title' => 'Coupon', + 'code' => 'coupon', + 'gross' => -11.90, + 'net' => -10.00, + 'tax_class_id' => 1, + 'tax' => -1.90, + ], + ], + 'tx_cart_domain_model_order_tax' => [ + ['uid' => 1, 'pid' => 1, 'item' => 1, 'record_type' => 'tax', 'tax' => 0.70, 'tax_class' => 2], + ['uid' => 2, 'pid' => 1, 'item' => 1, 'record_type' => 'tax', 'tax' => 3.80, 'tax_class' => 1], + ['uid' => 3, 'pid' => 1, 'item' => 1, 'record_type' => 'total_tax', 'tax' => 3.04, 'tax_class' => 1], + ['uid' => 4, 'pid' => 1, 'item' => 1, 'record_type' => 'total_tax', 'tax' => 0.70, 'tax_class' => 2], + ], +]; diff --git a/Tests/Functional/Templates/OrderTaxColumnsTest.php b/Tests/Functional/Templates/OrderTaxColumnsTest.php new file mode 100644 index 00000000..8cefe6b1 --- /dev/null +++ b/Tests/Functional/Templates/OrderTaxColumnsTest.php @@ -0,0 +1,147 @@ +loadOrderItem())) + ); + } + + #[Test] + public function frontendRendersTheTaxesInTheColumnOfTheirTaxClass(): void + { + self::assertSame( + [ + ['VAT (19 %)', 'VAT (7 %)'], + ['', '0,70€'], + ['3,80€', ''], + ['3,80€', '0,70€'], + ['0,95€', ''], + ['0,19€', ''], + ['3,04€', '0,70€'], + ], + self::getTaxColumns(self::render('Order/Cart', $this->loadOrderItem())) + ); + } + + private function loadOrderItem(): Item + { + $this->importPHPDataSet(__DIR__ . '/Fixtures/OrderWithTaxes.php'); + + $orderItem = GeneralUtility::makeInstance(PersistenceManager::class)->getObjectByIdentifier(1, Item::class); + self::assertInstanceOf(Item::class, $orderItem); + + return $orderItem; + } + + private static function render(string $template, Item $orderItem): string + { + $extbaseRequestParameters = new ExtbaseRequestParameters(); + $extbaseRequestParameters->setControllerExtensionName('Cart'); + $request = new Request( + (new ServerRequest('https://example.com/')) + ->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE) + ->withAttribute('language', new SiteLanguage(0, 'en_US.UTF-8', new Uri('/'), [])) + ->withAttribute('extbase', $extbaseRequestParameters) + ); + + $view = GeneralUtility::makeInstance(ViewFactoryInterface::class)->create( + new ViewFactoryData( + templateRootPaths: ['EXT:cart/Tests/Functional/Fixtures/Templates/'], + partialRootPaths: ['EXT:cart/Resources/Private/Partials/'], + layoutRootPaths: ['EXT:cart/Resources/Private/Layouts/'], + request: $request, + ) + ); + $view->assign('settings', [ + 'format' => [ + 'currency' => [ + 'decimalSeparator' => ',', + 'thousandsSeparator' => '.', + 'decimals' => '2', + ], + ], + ]); + $view->assign('orderItem', $orderItem); + + return $view->render($template); + } + + /** + * @return list> the content of the last two cells (the tax columns) of each row + */ + private static function getTaxColumns(string $html): array + { + $document = new DOMDocument(); + $document->loadHTML('' . $html, LIBXML_NOERROR); + + $rows = []; + foreach ((new DOMXPath($document))->query('//tr') ?: [] as $row) { + self::assertInstanceOf(DOMElement::class, $row); + $cells = []; + foreach ($row->childNodes as $cell) { + if ($cell instanceof DOMElement && in_array($cell->tagName, ['td', 'th'], true)) { + $cells[] = trim($cell->textContent, " \t\n\r\0\x0B\u{a0}"); + } + } + $rows[] = array_slice($cells, -2); + } + + return $rows; + } +}