Skip to content

Commit 729080d

Browse files
committed
Merge remote-tracking branch 'origin/MC-38031' into 2.4-develop-pr43
2 parents 2f25dce + ae19b0d commit 729080d

File tree

2 files changed

+89
-2
lines changed

2 files changed

+89
-2
lines changed

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

Lines changed: 40 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
@@ -429,9 +431,12 @@ public function getBillingAddressTotals()
429431
*/
430432
public function renderTotals($totals, $colspan = null)
431433
{
432-
//check if the shipment is multi shipment
434+
// check if the shipment is multi shipment
433435
$totals = $this->getMultishippingTotals($totals);
434436

437+
// sort totals by configuration settings
438+
$totals = $this->sortTotals($totals);
439+
435440
if ($colspan === null) {
436441
$colspan = 3;
437442
}
@@ -481,4 +486,38 @@ protected function _getRowItemRenderer($type)
481486
}
482487
return $renderer;
483488
}
489+
490+
/**
491+
* Sort total information based on configuration settings.
492+
*
493+
* @param array $totals
494+
* @return array
495+
*/
496+
private function sortTotals($totals): array
497+
{
498+
$sortedTotals = [];
499+
$sorts = $this->_scopeConfig->getValue(
500+
Collector::XML_PATH_SALES_TOTALS_SORT,
501+
ScopeInterface::SCOPE_STORES
502+
);
503+
504+
$sorted = [];
505+
foreach ($sorts as $code => $sortOrder) {
506+
$sorted[$sortOrder] = $code;
507+
}
508+
ksort($sorted);
509+
510+
foreach ($sorted as $code) {
511+
if (isset($totals[$code])) {
512+
$sortedTotals[$code] = $totals[$code];
513+
}
514+
}
515+
516+
$notSorted = array_diff(array_keys($totals), array_keys($sortedTotals));
517+
foreach ($notSorted as $code) {
518+
$sortedTotals[$code] = $totals[$code];
519+
}
520+
521+
return $sortedTotals;
522+
}
484523
}

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)