Skip to content

Commit 89d1372

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop
- merged latest code from mainline branch
2 parents 81fb477 + 86dc050 commit 89d1372

File tree

5 files changed

+100
-7
lines changed

5 files changed

+100
-7
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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\Quote\Model\Quote;
9+
10+
use Magento\Quote\Model\Quote;
11+
12+
class QuantityCollector
13+
{
14+
/**
15+
* Collect items qty
16+
*
17+
* @param Quote $quote
18+
* @return Quote
19+
*/
20+
public function collectItemsQtys(Quote $quote)
21+
{
22+
$quoteItems = $quote->getAllVisibleItems();
23+
$quote->setItemsCount(0);
24+
$quote->setItemsQty(0);
25+
$quote->setVirtualItemsQty(0);
26+
27+
foreach ($quoteItems as $item) {
28+
if ($item->getParentItem()) {
29+
continue;
30+
}
31+
32+
$children = $item->getChildren();
33+
if ($children && $item->isShipSeparately()) {
34+
foreach ($children as $child) {
35+
if ($child->getProduct()->getIsVirtual()) {
36+
$quote->setVirtualItemsQty($quote->getVirtualItemsQty() + $child->getQty() * $item->getQty());
37+
}
38+
}
39+
}
40+
41+
if ($item->getProduct()->getIsVirtual()) {
42+
$quote->setVirtualItemsQty($quote->getVirtualItemsQty() + $item->getQty());
43+
}
44+
$quote->setItemsCount($quote->getItemsCount() + 1);
45+
$quote->setItemsQty((float)$quote->getItemsQty() + $item->getQty());
46+
}
47+
48+
return $quote;
49+
}
50+
}

app/code/Magento/Quote/Model/Quote/TotalsCollector.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
namespace Magento\Quote\Model\Quote;
99

10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Quote\Model\Quote\Address\Total\Collector;
1112
use Magento\Quote\Model\Quote\Address\Total\CollectorFactory;
1213
use Magento\Quote\Model\Quote\Address\Total\CollectorInterface;
1314

1415
/**
15-
* Class TotalsCollector
16+
* Composite object for collecting total.
1617
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1718
*/
1819
class TotalsCollector
@@ -68,6 +69,11 @@ class TotalsCollector
6869
*/
6970
protected $shippingAssignmentFactory;
7071

72+
/**
73+
* @var QuantityCollector
74+
*/
75+
private $quantityCollector;
76+
7177
/**
7278
* @param Collector $totalCollector
7379
* @param CollectorFactory $totalCollectorFactory
@@ -78,6 +84,7 @@ class TotalsCollector
7884
* @param \Magento\Quote\Model\ShippingFactory $shippingFactory
7985
* @param \Magento\Quote\Model\ShippingAssignmentFactory $shippingAssignmentFactory
8086
* @param \Magento\Quote\Model\QuoteValidator $quoteValidator
87+
* @param QuantityCollector $quantityCollector
8188
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8289
*/
8390
public function __construct(
@@ -89,7 +96,8 @@ public function __construct(
8996
\Magento\Quote\Model\Quote\TotalsCollectorList $collectorList,
9097
\Magento\Quote\Model\ShippingFactory $shippingFactory,
9198
\Magento\Quote\Model\ShippingAssignmentFactory $shippingAssignmentFactory,
92-
\Magento\Quote\Model\QuoteValidator $quoteValidator
99+
\Magento\Quote\Model\QuoteValidator $quoteValidator,
100+
QuantityCollector $quantityCollector = null
93101
) {
94102
$this->totalCollector = $totalCollector;
95103
$this->totalCollectorFactory = $totalCollectorFactory;
@@ -100,6 +108,8 @@ public function __construct(
100108
$this->shippingFactory = $shippingFactory;
101109
$this->shippingAssignmentFactory = $shippingAssignmentFactory;
102110
$this->quoteValidator = $quoteValidator;
111+
$this->quantityCollector = $quantityCollector
112+
?: ObjectManager::getInstance()->get(QuantityCollector::class);
103113
}
104114

105115
/**
@@ -132,7 +142,7 @@ public function collect(\Magento\Quote\Model\Quote $quote)
132142
['quote' => $quote]
133143
);
134144

135-
$this->_collectItemsQtys($quote);
145+
$this->quantityCollector->collectItemsQtys($quote);
136146

137147
$total->setSubtotal(0);
138148
$total->setBaseSubtotal(0);
@@ -206,6 +216,8 @@ protected function _validateCouponCode(\Magento\Quote\Model\Quote $quote)
206216
*
207217
* @param \Magento\Quote\Model\Quote $quote
208218
* @return $this
219+
* @deprecated
220+
* @see \Magento\Quote\Model\Quote\QuantityCollector
209221
*/
210222
protected function _collectItemsQtys(\Magento\Quote\Model\Quote $quote)
211223
{
@@ -273,7 +285,7 @@ public function collectAddressTotals(
273285
/** @var CollectorInterface $collector */
274286
$collector->collect($quote, $shippingAssignment, $total);
275287
}
276-
288+
277289
$this->eventManager->dispatch(
278290
'sales_quote_address_collect_totals_after',
279291
[

app/code/Magento/Security/Model/AdminSessionsManager.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Magento\Security\Model;
99

1010
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
11-
use \Magento\Security\Model\ResourceModel\AdminSessionInfo\CollectionFactory;
11+
use Magento\Security\Model\ResourceModel\AdminSessionInfo\CollectionFactory;
1212

1313
/**
1414
* Admin Sessions Manager Model
@@ -174,8 +174,15 @@ public function processLogout()
174174
public function getCurrentSession()
175175
{
176176
if (!$this->currentSession) {
177+
$adminSessionInfoId = $this->authSession->getAdminSessionInfoId();
178+
if (!$adminSessionInfoId) {
179+
$this->createNewSession();
180+
$adminSessionInfoId = $this->authSession->getAdminSessionInfoId();
181+
$this->logoutOtherUserSessions();
182+
}
183+
177184
$this->currentSession = $this->adminSessionInfoFactory->create();
178-
$this->currentSession->load($this->authSession->getAdminSessionInfoId(), 'id');
185+
$this->currentSession->load($adminSessionInfoId, 'id');
179186
}
180187

181188
return $this->currentSession;

app/code/Magento/Security/Test/Unit/Model/AdminSessionsManagerTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,32 @@ public function testCleanExpiredSessions()
335335
*/
336336
public function testGetLogoutReasonMessage($expectedResult, $sessionStatus)
337337
{
338-
$this->adminSessionInfoFactoryMock->expects($this->once())
338+
$this->adminSessionInfoFactoryMock->expects($this->exactly(2))
339339
->method('create')
340340
->willReturn($this->currentSessionMock);
341+
$this->authSessionMock->expects($this->any())
342+
->method('getUser')
343+
->willReturn($this->userMock);
344+
$this->currentSessionMock->expects($this->once())
345+
->method('setData')
346+
->willReturn($this->currentSessionMock);
347+
$this->currentSessionMock->expects($this->once())
348+
->method('save')
349+
->willReturn($this->currentSessionMock);
350+
$this->adminSessionInfoCollectionFactoryMock->expects($this->once())
351+
->method('create')
352+
->willReturn($this->adminSessionInfoCollectionMock);
353+
$this->adminSessionInfoCollectionMock->expects($this->once())->method('filterByUser')
354+
->willReturnSelf();
355+
$this->adminSessionInfoCollectionMock->expects($this->once())
356+
->method('filterExpiredSessions')
357+
->willReturnSelf();
358+
$this->adminSessionInfoCollectionMock->expects($this->once())
359+
->method('loadData')
360+
->willReturnSelf();
361+
$this->adminSessionInfoCollectionMock->expects($this->once())
362+
->method('setDataToAll')
363+
->willReturnSelf();
341364
$this->currentSessionMock->expects($this->once())
342365
->method('getStatus')
343366
->willReturn($sessionStatus);

dev/tests/integration/testsuite/Magento/Backend/Model/Auth/SessionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected function setUp(): void
3939
->setCurrentScope(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
4040
$this->auth = $this->objectManager->create(\Magento\Backend\Model\Auth::class);
4141
$this->authSession = $this->objectManager->create(\Magento\Backend\Model\Auth\Session::class);
42+
$this->authSession->setUser($this->objectManager->create(\Magento\User\Model\User::class));
4243
$this->auth->setAuthStorage($this->authSession);
4344
$this->auth->logout();
4445
}

0 commit comments

Comments
 (0)