Skip to content

Commit 209cb5d

Browse files
committed
MC-33456: [Magento Cloud] Order Summary doesn't show the Subtotal including Tax
1 parent 4a8f99d commit 209cb5d

File tree

2 files changed

+182
-4
lines changed
  • app/code/Magento/Tax/Block/Sales/Order
  • dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order

2 files changed

+182
-4
lines changed

app/code/Magento/Tax/Block/Sales/Order/Tax.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function initTotals()
8282
$this->_order = $parent->getOrder();
8383
$this->_source = $parent->getSource();
8484

85-
$store = $this->getStore();
85+
$store = $this->_order->getStore();
8686
$allowTax = $this->_source->getTaxAmount() > 0 || $this->_config->displaySalesZeroTax($store);
8787
$grandTotal = (double)$this->_source->getGrandTotal();
8888
if (!$grandTotal || $allowTax && !$this->_config->displaySalesTaxWithGrandTotal($store)) {
@@ -131,7 +131,7 @@ public function getStore()
131131
*/
132132
protected function _initSubtotal()
133133
{
134-
$store = $this->getStore();
134+
$store = $this->_order->getStore();
135135
$parent = $this->getParentBlock();
136136
$subtotal = $parent->getTotal('subtotal');
137137
if (!$subtotal) {
@@ -213,7 +213,7 @@ protected function _initSubtotal()
213213
*/
214214
protected function _initShipping()
215215
{
216-
$store = $this->getStore();
216+
$store = $this->_order->getStore();
217217
/** @var \Magento\Sales\Block\Order\Totals $parent */
218218
$parent = $this->getParentBlock();
219219
$shipping = $parent->getTotal('shipping');
@@ -290,7 +290,7 @@ protected function _initDiscount()
290290
*/
291291
protected function _initGrandTotal()
292292
{
293-
$store = $this->getStore();
293+
$store = $this->_order->getStore();
294294
$parent = $this->getParentBlock();
295295
$grandototal = $parent->getTotal('grand_total');
296296
if (!$grandototal || !(double)$this->_source->getGrandTotal()) {
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Block\Adminhtml\Order;
9+
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\Phrase;
12+
use Magento\Framework\View\LayoutInterface;
13+
use Magento\Sales\Api\Data\OrderInterfaceFactory;
14+
use Magento\Sales\Block\Adminhtml\Order\Totals\Tax;
15+
use Magento\Sales\Model\Order;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* @magentoAppArea adminhtml
21+
*/
22+
class TotalsTest extends TestCase
23+
{
24+
/**
25+
* @var ObjectManagerInterface
26+
*/
27+
private $om;
28+
29+
/**
30+
* @var LayoutInterface
31+
*/
32+
private $layout;
33+
34+
/**
35+
* @var OrderInterfaceFactory
36+
*/
37+
private $orderFactory;
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
public function setUp()
43+
{
44+
$this->om = Bootstrap::getObjectManager();
45+
$this->layout = $this->om->get(LayoutInterface::class);
46+
$this->orderFactory = $this->om->get(OrderInterfaceFactory::class);
47+
}
48+
49+
/**
50+
* Test block totals including tax.
51+
*
52+
* @magentoConfigFixture default_store tax/sales_display/subtotal 2
53+
* @magentoConfigFixture default_store tax/sales_display/shipping 2
54+
*
55+
* @magentoDataFixture Magento/Sales/_files/order.php
56+
*
57+
* @return void
58+
*/
59+
public function testTotalsInclTax(): void
60+
{
61+
$order = $this->prepareOrderInclTax('100000001');
62+
63+
$blockTotals = $this->getBlockTotals()->setOrder($order);
64+
$this->assertSubtotal($blockTotals->toHtml(), (float) $order->getSubtotal());
65+
$this->assertShipping($blockTotals->toHtml(), (float) $order->getShippingAmount());
66+
67+
$blockTax = $this->getBlockTax();
68+
$blockTotals->setChild('child_tax_block', $blockTax);
69+
$blockTax->initTotals();
70+
71+
$this->assertSubtotal($blockTotals->toHtml(), (float) $order->getSubtotalInclTax());
72+
$this->assertShipping($blockTotals->toHtml(), (float) $order->getShippingInclTax());
73+
}
74+
75+
/**
76+
* Check if subtotal amount present in block.
77+
*
78+
* @param string $blockTotalsHtml
79+
* @param float $amount
80+
* @return void
81+
*/
82+
private function assertSubtotal(string $blockTotalsHtml, float $amount): void
83+
{
84+
$this->assertTrue(
85+
$this->isBlockContainsTotalAmount($blockTotalsHtml, __('Subtotal'), $amount),
86+
'Subtotal amount is missing or incorrect.'
87+
);
88+
}
89+
90+
/**
91+
* Check if shipping amount present in block.
92+
*
93+
* @param string $blockTotalsHtml
94+
* @param float $amount
95+
* @return void
96+
*/
97+
private function assertShipping(string $blockTotalsHtml, float $amount): void
98+
{
99+
$this->assertTrue(
100+
$this->isBlockContainsTotalAmount($blockTotalsHtml, __('Shipping & Handling'), $amount),
101+
'Shipping & Handling amount is missing or incorrect.'
102+
);
103+
}
104+
105+
/**
106+
* Prepare order for test.
107+
*
108+
* @param string $incrementId
109+
* @return Order
110+
*/
111+
private function prepareOrderInclTax(string $incrementId): Order
112+
{
113+
/** @var Order $order */
114+
$order = $this->orderFactory->create()->loadByIncrementId($incrementId);
115+
116+
$order->setSubtotalInclTax(110);
117+
$order->setBaseSubtotalInclTax(110);
118+
119+
$order->setShippingAmount(10);
120+
$order->setBaseShippingAmount(10);
121+
$order->setShippingInclTax(11);
122+
$order->setBaseShippingInclTax(11);
123+
124+
return $order;
125+
}
126+
127+
/**
128+
* Create block totals.
129+
*
130+
* @return Totals
131+
*/
132+
private function getBlockTotals(): Totals
133+
{
134+
/** @var Totals $block */
135+
$block = $this->layout->createBlock(Totals::class, 'block_totals');
136+
$block->setTemplate('Magento_Sales::order/totals.phtml');
137+
138+
return $block;
139+
}
140+
141+
/**
142+
* Create block tax.
143+
*
144+
* @return Tax
145+
*/
146+
private function getBlockTax(): Tax
147+
{
148+
/** @var Tax $block */
149+
$block = $this->layout->createBlock(Tax::class, 'block_tax');
150+
$block->setTemplate('Magento_Sales::order/totals/tax.phtml');
151+
152+
return $block;
153+
}
154+
155+
/**
156+
* Check if amount present in appropriate block node.
157+
*
158+
* @param string $blockTotalsHtml
159+
* @param Phrase $totalLabel
160+
* @param float $totalAmount
161+
* @return bool
162+
*/
163+
private function isBlockContainsTotalAmount(
164+
string $blockTotalsHtml,
165+
Phrase $totalLabel,
166+
float $totalAmount
167+
): bool {
168+
$dom = new \DOMDocument();
169+
$dom->loadHTML($blockTotalsHtml);
170+
$query = sprintf(
171+
"//tr[contains(., '%s')]//span[contains(text(), '%01.2f')]",
172+
$totalLabel,
173+
$totalAmount
174+
);
175+
176+
return (bool) (new \DOMXPath($dom))->query($query)->count();
177+
}
178+
}

0 commit comments

Comments
 (0)