Skip to content

Commit 6af218c

Browse files
authored
Merge branch '2.4-develop' into delivery-bunch-w21
2 parents e08cf64 + 8f06e91 commit 6af218c

File tree

18 files changed

+711
-54
lines changed

18 files changed

+711
-54
lines changed

app/code/Magento/Checkout/CustomerData/Cart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class Cart extends \Magento\Framework\DataObject implements SectionSourceInterface
1717
{
1818
/**
19-
* @var \Magento\Customer\Model\Session
19+
* @var \Magento\Checkout\Model\Session
2020
*/
2121
protected $checkoutSession;
2222

app/code/Magento/CustomerGraphQl/etc/graphql/di.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
</argument>
2222
</arguments>
2323
</type>
24+
<type name="Magento\CustomerGraphQl\Model\Context\AddUserInfoToContext">
25+
<arguments>
26+
<argument name="session" xsi:type="object">Magento\Customer\Model\Session\Proxy</argument>
27+
</arguments>
28+
</type>
29+
<type name="Magento\CustomerGraphQl\Plugin\ClearCustomerSessionAfterRequest">
30+
<arguments>
31+
<argument name="session" xsi:type="object">Magento\Customer\Model\Session\Proxy</argument>
32+
</arguments>
33+
</type>
2434
<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
2535
<arguments>
2636
<argument name="extendedConfigData" xsi:type="array">

app/code/Magento/DirectoryGraphQl/Controller/HttpHeaderProcessor/CurrencyProcessor.php

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CurrencyProcessor implements HttpHeaderProcessorInterface
3030

3131
/**
3232
* @var SessionManagerInterface
33+
* @deprecated
3334
*/
3435
private $session;
3536

@@ -65,37 +66,21 @@ public function __construct(
6566
public function processHeaderValue(string $headerValue) : void
6667
{
6768
try {
68-
if (!empty($headerValue)) {
69-
$headerCurrency = strtoupper(ltrim(rtrim($headerValue)));
70-
/** @var \Magento\Store\Model\Store $currentStore */
71-
$currentStore = $this->storeManager->getStore();
72-
if (in_array($headerCurrency, $currentStore->getAvailableCurrencyCodes(true))) {
73-
$currentStore->setCurrentCurrencyCode($headerCurrency);
74-
} else {
75-
/** @var \Magento\Store\Model\Store $store */
76-
$store = $this->storeManager->getStore() ?? $this->storeManager->getDefaultStoreView();
77-
//skip store not found exception as it will be handled in graphql validation
78-
$this->logger->warning(__('Currency not allowed for store %1', [$store->getCode()]));
79-
$this->httpContext->setValue(
80-
HttpContext::CONTEXT_CURRENCY,
81-
$headerCurrency,
82-
$store->getDefaultCurrency()->getCode()
83-
);
84-
}
69+
$currentStore = $this->storeManager->getStore();
70+
$defaultCode = $currentStore->getDefaultCurrency()->getCode();
71+
if (empty($headerValue)) {
72+
$this->httpContext->setValue(
73+
HttpContext::CONTEXT_CURRENCY,
74+
$currentStore->getCurrentCurrency()->getCode(),
75+
$defaultCode
76+
);
8577
} else {
86-
if ($this->session->getCurrencyCode()) {
87-
/** @var \Magento\Store\Model\Store $currentStore */
88-
$currentStore = $this->storeManager->getStore() ?? $this->storeManager->getDefaultStoreView();
89-
$currentStore->setCurrentCurrencyCode($this->session->getCurrencyCode());
90-
} else {
91-
/** @var \Magento\Store\Model\Store $store */
92-
$store = $this->storeManager->getStore() ?? $this->storeManager->getDefaultStoreView();
93-
$this->httpContext->setValue(
94-
HttpContext::CONTEXT_CURRENCY,
95-
$store->getCurrentCurrency()->getCode(),
96-
$store->getDefaultCurrency()->getCode()
97-
);
78+
$headerCurrency = strtoupper(trim($headerValue));
79+
if (!in_array($headerCurrency, $currentStore->getAvailableCurrencyCodes(true))) {
80+
//skip store not found exception as it will be handled in graphql validation
81+
$this->logger->warning(__('Currency not allowed for store %1', [$currentStore->getCode()]));
9882
}
83+
$this->httpContext->setValue(HttpContext::CONTEXT_CURRENCY, $headerCurrency, $defaultCode);
9984
}
10085
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
10186
//skip store not found exception as it will be handled in graphql validation

app/code/Magento/DirectoryGraphQl/etc/graphql/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616
</argument>
1717
</arguments>
1818
</type>
19+
<type name="Magento\DirectoryGraphQl\Controller\HttpHeaderProcessor\CurrencyProcessor">
20+
<arguments>
21+
<argument name="session" xsi:type="object">Magento\Framework\Session\Generic\Proxy</argument>
22+
</arguments>
23+
</type>
1924
</config>

app/code/Magento/Downloadable/Controller/Download/Link.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ protected function _getCustomerSession()
3838
*/
3939
public function execute()
4040
{
41-
$session = $this->_getCustomerSession();
42-
4341
$id = $this->getRequest()->getParam('id', 0);
4442
/** @var PurchasedLink $linkPurchasedItem */
4543
$linkPurchasedItem = $this->_objectManager->create(
@@ -53,6 +51,7 @@ public function execute()
5351
return $this->_redirect('*/customer/products');
5452
}
5553
if (!$this->_objectManager->get(\Magento\Downloadable\Helper\Data::class)->getIsShareable($linkPurchasedItem)) {
54+
$session = $this->_getCustomerSession();
5655
$customerId = $session->getCustomerId();
5756
if (!$customerId) {
5857
/** @var \Magento\Catalog\Model\Product $product */

app/code/Magento/Downloadable/Test/Unit/Controller/Download/LinkTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ protected function setUp(): void
180180
*/
181181
public function testAbsentLinkId(): void
182182
{
183-
$this->objectManager->expects($this->once())
183+
$this->objectManager->expects($this->never())
184184
->method('get')
185185
->with(Session::class)
186186
->willReturn($this->session);
@@ -229,8 +229,8 @@ public function testGetLinkForGuestCustomer(): void
229229
$this->session->expects($this->once())->method('authenticate')->willReturn(true);
230230
$this->objectManager
231231
->method('get')
232-
->withConsecutive([Session::class], [Data::class])
233-
->willReturnOnConsecutiveCalls($this->session, $this->helperData);
232+
->withConsecutive([Data::class], [Session::class])
233+
->willReturnOnConsecutiveCalls($this->helperData, $this->session);
234234
$this->objectManager
235235
->method('create')
236236
->withConsecutive([Item::class], [Product::class], [UrlInterface::class])
@@ -262,8 +262,8 @@ public function testGetLinkForWrongCustomer(): void
262262
$this->session->expects($this->once())->method('getCustomerId')->willReturn('customer_id');
263263
$this->objectManager
264264
->method('get')
265-
->withConsecutive([Session::class], [Data::class])
266-
->willReturnOnConsecutiveCalls($this->session, $this->helperData);
265+
->withConsecutive([Data::class], [Session::class])
266+
->willReturnOnConsecutiveCalls($this->helperData, $this->session);
267267
$this->objectManager
268268
->method('create')
269269
->withConsecutive([Item::class], [Purchased::class])
@@ -295,8 +295,8 @@ public function testExceptionInUpdateLinkStatus($mimeType, $disposition): void
295295
->willReturnSelf();
296296
$this->objectManager
297297
->method('get')
298-
->withConsecutive([\Magento\Customer\Model\Session::class], [Data::class], [Download::class])
299-
->willReturnOnConsecutiveCalls($this->session, $this->helperData, $this->downloadHelper);
298+
->withConsecutive([Data::class], [Download::class])
299+
->willReturnOnConsecutiveCalls($this->helperData, $this->downloadHelper);
300300
$this->objectManager
301301
->method('create')
302302
->withConsecutive([Item::class])
@@ -383,8 +383,8 @@ public function testLinkNotAvailable($messageType, $status, $notice): void
383383
$this->linkPurchasedItem->expects($this->once())->method('getId')->willReturn(5);
384384
$this->objectManager
385385
->method('get')
386-
->withConsecutive([Session::class], [Data::class])
387-
->willReturnOnConsecutiveCalls($this->session, $this->helperData);
386+
->withConsecutive([Data::class], [Session::class])
387+
->willReturnOnConsecutiveCalls($this->helperData, $this->session);
388388
$this->objectManager
389389
->method('create')
390390
->with(Item::class)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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\GraphQl\Model\Config;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
12+
/**
13+
* Session disable in graphql configuration model.
14+
*/
15+
class DisableSession
16+
{
17+
private const XML_PATH_GRAPHQL_DISABLE_SESSION = 'graphql/session/disable';
18+
19+
/**
20+
* @var ScopeConfigInterface
21+
*/
22+
private $scopeConfig;
23+
24+
/**
25+
* @param ScopeConfigInterface $scopeConfig
26+
*/
27+
public function __construct(ScopeConfigInterface $scopeConfig)
28+
{
29+
$this->scopeConfig = $scopeConfig;
30+
}
31+
32+
/**
33+
* Get config value is session disabled for grapqhl area.
34+
*
35+
* @param string $scopeType
36+
* @param null|int|string $scopeCode
37+
* @return bool
38+
*/
39+
public function isDisabled($scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null): bool
40+
{
41+
$value = $this->scopeConfig->getValue(
42+
self::XML_PATH_GRAPHQL_DISABLE_SESSION,
43+
$scopeType,
44+
$scopeCode
45+
);
46+
47+
if ($value === '1') {
48+
return true;
49+
}
50+
51+
return false;
52+
}
53+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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\GraphQl\Plugin;
9+
10+
use Magento\Framework\App\Area;
11+
use Magento\Framework\App\State;
12+
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\Session\SessionStartChecker;
14+
use Magento\GraphQl\Model\Config\DisableSession as DisableSessionConfig;
15+
16+
/**
17+
* Disable session in graphql area if configured.
18+
*/
19+
class DisableSession
20+
{
21+
/**
22+
* @var DisableSessionConfig
23+
*/
24+
private $disableSessionConfig;
25+
26+
/**
27+
* @var State
28+
*/
29+
private $appState;
30+
31+
/**
32+
* @param DisableSessionConfig $disableSessionConfig
33+
* @param State $appState
34+
*/
35+
public function __construct(
36+
DisableSessionConfig $disableSessionConfig,
37+
State $appState
38+
) {
39+
$this->disableSessionConfig = $disableSessionConfig;
40+
$this->appState = $appState;
41+
}
42+
43+
/**
44+
* Prevents session starting while in graphql area and session is disabled in config.
45+
*
46+
* @param SessionStartChecker $subject
47+
* @param bool $result
48+
* @return bool
49+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
50+
* @SuppressWarnings(PHPMD.EmptyCatchBlock)
51+
*/
52+
public function afterCheck(SessionStartChecker $subject, bool $result): bool
53+
{
54+
if (!$result) {
55+
return false;
56+
}
57+
try {
58+
if ($this->appState->getAreaCode() === Area::AREA_GRAPHQL && $this->disableSessionConfig->isDisabled()) {
59+
$result = false;
60+
}
61+
} catch (LocalizedException $e) {} finally { //@codingStandardsIgnoreLine
62+
return $result;
63+
}
64+
}
65+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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\GraphQl\Test\Unit\Model\Config;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use Magento\GraphQl\Model\Config\DisableSession;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test for DisableSession config model.
18+
*/
19+
class DisableSessionTest extends TestCase
20+
{
21+
/**
22+
* @var ScopeConfigInterface|MockObject
23+
*/
24+
private $scopeConfigMock;
25+
26+
/**
27+
* @var DisableSession
28+
*/
29+
private $model;
30+
31+
/**
32+
* @inheirtDoc
33+
*/
34+
public function setUp(): void
35+
{
36+
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
37+
$this->model = (new ObjectManager($this))->getObject(
38+
DisableSession::class,
39+
['scopeConfig' => $this->scopeConfigMock]
40+
);
41+
}
42+
43+
/**
44+
* @dataProvider disableSessionDataProvider
45+
*/
46+
public function testisSessionDisabled($configValue, $expectedResult)
47+
{
48+
$this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn($configValue);
49+
$this->assertEquals($expectedResult, $this->model->isDisabled());
50+
}
51+
52+
/**
53+
* Data provider for session disabled config test.
54+
* @return array[]
55+
*/
56+
public function disableSessionDataProvider()
57+
{
58+
return [
59+
['configValue' => '1', true],
60+
['configValue' => '0', false],
61+
['configValue' => '11', false],
62+
['configValue' => null, false],
63+
['configValue' => '', false],
64+
['configValue' => 'adfjsadf', false],
65+
];
66+
}
67+
}

0 commit comments

Comments
 (0)