Skip to content

Commit d1aaa1e

Browse files
committed
MC-38031: Checkout with Multiple Addresses - Review Page does not follow the configured total sort order
1 parent 3c3c8ed commit d1aaa1e

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

app/code/Magento/Multishipping/Block/Checkout/Overview.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Quote\Model\Quote\Address;
1111
use Magento\Checkout\Helper\Data as CheckoutHelper;
1212
use Magento\Framework\App\ObjectManager;
13+
use Magento\Quote\Model\Quote\Address\Total\Collector;
14+
use Magento\Store\Model\ScopeInterface;
1315

1416
/**
1517
* Multishipping checkout overview information
@@ -430,7 +432,7 @@ public function getBillingAddressTotals()
430432
public function renderTotals($totals, $colspan = null)
431433
{
432434
//check if the shipment is multi shipment
433-
$totals = $this->getMultishippingTotals($totals);
435+
$totals = $this->sortTotals($this->getMultishippingTotals($totals));
434436

435437
if ($colspan === null) {
436438
$colspan = 3;
@@ -481,4 +483,37 @@ protected function _getRowItemRenderer($type)
481483
}
482484
return $renderer;
483485
}
486+
487+
/**
488+
* Sort total information based on configuration settings.
489+
*
490+
* @param array $totals
491+
* @return array
492+
*/
493+
private function sortTotals($totals): array
494+
{
495+
$sortedTotals = [];
496+
$sorts = $this->_scopeConfig->getValue(
497+
Collector::XML_PATH_SALES_TOTALS_SORT,
498+
ScopeInterface::SCOPE_STORES
499+
);
500+
501+
foreach ($sorts as $code => $sortOrder) {
502+
$sorted[$sortOrder] = $code;
503+
}
504+
ksort($sorted);
505+
506+
foreach ($sorted as $code) {
507+
if (isset($totals[$code])) {
508+
$sortedTotals[$code] = $totals[$code];
509+
}
510+
}
511+
512+
$notSorted = array_diff(array_keys($totals), array_keys($sortedTotals));
513+
foreach ($notSorted as $code) {
514+
$sortedTotals[$code] = $totals[$code];
515+
}
516+
517+
return $sortedTotals;
518+
}
484519
}

app/code/Magento/Multishipping/Test/Unit/Block/Checkout/OverviewTest.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\Multishipping\Test\Unit\Block\Checkout;
1010

11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\Framework\Pricing\PriceCurrencyInterface;
1213
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1314
use Magento\Framework\UrlInterface;
@@ -67,6 +68,11 @@ class OverviewTest extends TestCase
6768
*/
6869
private $urlBuilderMock;
6970

71+
/**
72+
* @var MockObject
73+
*/
74+
private $scopeConfigMock;
75+
7076
protected function setUp(): void
7177
{
7278
$objectManager = new ObjectManager($this);
@@ -85,14 +91,16 @@ protected function setUp(): void
8591
$this->createMock(Multishipping::class);
8692
$this->quoteMock = $this->createMock(Quote::class);
8793
$this->urlBuilderMock = $this->getMockForAbstractClass(UrlInterface::class);
94+
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
8895
$this->model = $objectManager->getObject(
8996
Overview::class,
9097
[
9198
'priceCurrency' => $this->priceCurrencyMock,
9299
'totalsCollector' => $this->totalsCollectorMock,
93100
'totalsReader' => $this->totalsReaderMock,
94101
'multishipping' => $this->checkoutMock,
95-
'urlBuilder' => $this->urlBuilderMock
102+
'urlBuilder' => $this->urlBuilderMock,
103+
'_scopeConfig' => $this->scopeConfigMock
96104
]
97105
);
98106
}
@@ -187,4 +195,44 @@ public function testGetVirtualProductEditUrl()
187195
$this->urlBuilderMock->expects($this->once())->method('getUrl')->with('checkout/cart', [])->willReturn($url);
188196
$this->assertEquals($url, $this->model->getVirtualProductEditUrl());
189197
}
198+
199+
/**
200+
* Test sort total information
201+
*
202+
* @return void
203+
*/
204+
public function testSortCollectors(): void
205+
{
206+
$sorts = [
207+
'discount' => 40,
208+
'subtotal' => 10,
209+
'tax' => 20,
210+
'shipping' => 30,
211+
];
212+
213+
$this->scopeConfigMock->method('getValue')
214+
->with('sales/totals_sort', 'stores')
215+
->willReturn($sorts);
216+
217+
$totalsNotSorted = [
218+
'subtotal' => [],
219+
'shipping' => [],
220+
'tax' => [],
221+
];
222+
223+
$totalsExpected = [
224+
'subtotal' => [],
225+
'tax' => [],
226+
'shipping' => [],
227+
];
228+
229+
$method = new \ReflectionMethod($this->model, 'sortTotals');
230+
$method->setAccessible(true);
231+
$result = $method->invoke($this->model, $totalsNotSorted);
232+
233+
$this->assertEquals(
234+
$totalsExpected,
235+
$result
236+
);
237+
}
190238
}

0 commit comments

Comments
 (0)