Skip to content

Commit 55a912a

Browse files
author
Oleksii Korshenko
authored
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #12810: Stop the profiler when returning early in \Magento\Eav\Model\Config::getAttribute (by @nicka101) - #12738: #12719: Use full name in welcome message (by @xpoback) - #12739: #6113: Validate range-words in Form component (UI Component) (by @zamoroka) - #12758: #5035 Cannot subscribe to events with a number in name (by @Mobecls) - #12759: Fix Back to Sign in url on confirmation form (by @StasKozar) - #12732: Fix issue when tracking link returns 404 page in admin panel (by @ihor-sviziev) - #12630: Add customer login url from Customer Url model to checkout config so … (by @quisse) - magento-engcom/magento2ce#1022: 6965: \Magento\Directory\Model\PriceCurrency::format() fails without conversion rate (by @nmalevanec) - #12826: Fix PhpDoc to show correct parameter types (by @FreekVandeursen) Fixed GitHub Issues: - #12719: Welcome message is shown with customer's first and last names after confirming account (reported by @alena-marchenko) has been fixed in #12738 by @xpoback in 2.2-develop branch Related commits: 1. 6b9c39c - #6113: Validate range-words in Form component (UI Component) (reported by @robinhuy) has been fixed in #12739 by @zamoroka in 2.2-develop branch Related commits: 1. 465e14b 2. 8bc807f 3. e9dcb03 - #5035: I can not to subscribe on change of all sections in Stores ->Configuration using event admin_system_config_changed_section (reported by @katesuykovskaya) has been fixed in #12758 by @Mobecls in 2.2-develop branch Related commits: 1. 937b26d 2. 85fa671 - #12715: Storefront Back to Sign in button does not work as expected (reported by @alena-marchenko) has been fixed in #12759 by @StasKozar in 2.2-develop branch Related commits: 1. 946382c 2. faee0fc - #12206: Tracking link returns 404 page in admin panel (reported by @catstantin) has been fixed in #12732 by @ihor-sviziev in 2.2-develop branch Related commits: 1. ecf27be 2. 5e4bf42 - #12627: Referer is not added to login url in checkout config (reported by @quisse) has been fixed in #12630 by @quisse in 2.2-develop branch Related commits: 1. 6f7219f 2. 2602e7e 3. 115ba8e 4. 97f77e6 5. bb3932c 6. 8986107 7. 5c87fb0 8. 4350858 - #6965: \Magento\Directory\Model\PriceCurrency::format() fails without conversion rate (reported by @Vinai) has been fixed in magento-engcom/magento2ce#1022 by @nmalevanec in 2.2-develop branch Related commits: 1. 2c4fa07 2. ed5ffed
2 parents 8c9e245 + 2defd0e commit 55a912a

File tree

17 files changed

+373
-52
lines changed

17 files changed

+373
-52
lines changed

app/code/Magento/Customer/Controller/Account/Confirmation.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
*/
77
namespace Magento\Customer\Controller\Account;
88

9+
use Magento\Customer\Model\Url;
910
use Magento\Framework\App\Action\Context;
1011
use Magento\Customer\Model\Session;
12+
use Magento\Framework\App\ObjectManager;
1113
use Magento\Framework\View\Result\PageFactory;
1214
use Magento\Store\Model\StoreManagerInterface;
1315
use Magento\Customer\Api\AccountManagementInterface;
@@ -35,24 +37,32 @@ class Confirmation extends \Magento\Customer\Controller\AbstractAccount
3537
*/
3638
protected $resultPageFactory;
3739

40+
/**
41+
* @var Url
42+
*/
43+
private $customerUrl;
44+
3845
/**
3946
* @param Context $context
4047
* @param Session $customerSession
4148
* @param PageFactory $resultPageFactory
4249
* @param StoreManagerInterface $storeManager
4350
* @param AccountManagementInterface $customerAccountManagement
51+
* @param Url $customerUrl
4452
*/
4553
public function __construct(
4654
Context $context,
4755
Session $customerSession,
4856
PageFactory $resultPageFactory,
4957
StoreManagerInterface $storeManager,
50-
AccountManagementInterface $customerAccountManagement
58+
AccountManagementInterface $customerAccountManagement,
59+
Url $customerUrl = null
5160
) {
5261
$this->session = $customerSession;
5362
$this->resultPageFactory = $resultPageFactory;
5463
$this->storeManager = $storeManager;
5564
$this->customerAccountManagement = $customerAccountManagement;
65+
$this->customerUrl = $customerUrl ?: ObjectManager::getInstance()->get(Url::class);
5666
parent::__construct($context);
5767
}
5868

@@ -98,6 +108,8 @@ public function execute()
98108
$resultPage = $this->resultPageFactory->create();
99109
$resultPage->getLayout()->getBlock('accountConfirmation')->setEmail(
100110
$this->getRequest()->getParam('email', $email)
111+
)->setLoginUrl(
112+
$this->customerUrl->getLoginUrl()
101113
);
102114
return $resultPage;
103115
}

app/code/Magento/Customer/Model/Checkout/ConfigProvider.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Checkout\Model\ConfigProviderInterface;
99
use Magento\Customer\Model\Url;
10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\UrlInterface;
1112
use Magento\Store\Model\StoreManagerInterface;
1213
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -22,6 +23,7 @@ class ConfigProvider implements ConfigProviderInterface
2223

2324
/**
2425
* @var UrlInterface
26+
* @deprecated
2527
*/
2628
protected $urlBuilder;
2729

@@ -30,19 +32,28 @@ class ConfigProvider implements ConfigProviderInterface
3032
*/
3133
protected $scopeConfig;
3234

35+
/**
36+
* @var Url
37+
*/
38+
private $customerUrl;
39+
3340
/**
3441
* @param UrlInterface $urlBuilder
3542
* @param StoreManagerInterface $storeManager
3643
* @param ScopeConfigInterface $scopeConfig
44+
* @param Url|null $customerUrl
3745
*/
3846
public function __construct(
3947
UrlInterface $urlBuilder,
4048
StoreManagerInterface $storeManager,
41-
ScopeConfigInterface $scopeConfig
49+
ScopeConfigInterface $scopeConfig,
50+
Url $customerUrl = null
4251
) {
4352
$this->urlBuilder = $urlBuilder;
4453
$this->storeManager = $storeManager;
4554
$this->scopeConfig = $scopeConfig;
55+
$this->customerUrl = $customerUrl ?? ObjectManager::getInstance()
56+
->get(Url::class);
4657
}
4758

4859
/**
@@ -78,7 +89,7 @@ protected function isAutocompleteEnabled()
7889
*/
7990
protected function getLoginUrl()
8091
{
81-
return $this->urlBuilder->getUrl(Url::ROUTE_ACCOUNT_LOGIN);
92+
return $this->customerUrl->getLoginUrl();
8293
}
8394

8495
/**
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Test\Unit\Controller\Account;
8+
9+
use Magento\Customer\Controller\Account\Confirmation;
10+
use Magento\Framework\App\Request\Http;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
12+
13+
class ConfirmationTest extends \PHPUnit\Framework\TestCase
14+
{
15+
/**
16+
* @var Confirmation
17+
*/
18+
private $model;
19+
20+
/**
21+
* @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $customerSessionMock;
24+
25+
/**
26+
* @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $contextMock;
29+
30+
/**
31+
* @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $resultPageFactoryMock;
34+
35+
/**
36+
* @var \Magento\Customer\Model\Url|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $customerUrlMock;
39+
40+
/**
41+
* @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $requestMock;
44+
45+
public function setUp()
46+
{
47+
$this->customerSessionMock = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
48+
->disableOriginalConstructor()
49+
->setMethods(['isLoggedIn'])
50+
->getMock();
51+
$this->contextMock = $this->getMockBuilder(\Magento\Framework\App\Action\Context::class)
52+
->disableOriginalConstructor()
53+
->setMethods(['getRequest'])
54+
->getMock();
55+
$this->requestMock = $this->getMockBuilder(Http::class)
56+
->disableOriginalConstructor()
57+
->setMethods(['getPost', 'getParam'])
58+
->getMock();
59+
$this->contextMock->expects($this->any())
60+
->method('getRequest')
61+
->willReturn($this->requestMock);
62+
63+
$this->resultPageFactoryMock = $this->getMockBuilder(\Magento\Framework\View\Result\PageFactory::class)
64+
->disableOriginalConstructor()
65+
->setMethods(['create'])
66+
->getMock();
67+
$this->customerUrlMock = $this->getMockBuilder(\Magento\Customer\Model\Url::class)
68+
->disableOriginalConstructor()
69+
->setMethods(['getLoginUrl'])
70+
->getMock();
71+
$this->model = (new ObjectManagerHelper($this))->getObject(
72+
Confirmation::class,
73+
[
74+
'context' => $this->contextMock,
75+
'customerSession' => $this->customerSessionMock,
76+
'resultPageFactory' => $this->resultPageFactoryMock,
77+
'customerUrl' => $this->customerUrlMock,
78+
]
79+
);
80+
}
81+
82+
public function testGetLoginUrl()
83+
{
84+
$this->customerSessionMock->expects($this->once())
85+
->method('isLoggedIn')
86+
->willReturn(false);
87+
88+
$this->requestMock->expects($this->once())->method('getPost')->with('email')->willReturn(null);
89+
90+
$resultPageMock = $this->getMockBuilder(\Magento\Framework\View\Result\Page::class)
91+
->disableOriginalConstructor()
92+
->setMethods(['getLayout'])
93+
->getMock();
94+
95+
$this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($resultPageMock);
96+
97+
$layoutMock = $this->getMockBuilder(\Magento\Framework\View\Layout::class)
98+
->disableOriginalConstructor()
99+
->setMethods(['getBlock'])
100+
->getMock();
101+
102+
$resultPageMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
103+
104+
$blockMock = $this->getMockBuilder(\Magento\Framework\View\Element\Template::class)
105+
->disableOriginalConstructor()
106+
->setMethods(['setEmail', 'setLoginUrl'])
107+
->getMock();
108+
109+
$layoutMock->expects($this->once())->method('getBlock')->with('accountConfirmation')->willReturn($blockMock);
110+
111+
$blockMock->expects($this->once())->method('setEmail')->willReturnSelf();
112+
$blockMock->expects($this->once())->method('setLoginUrl')->willReturnSelf();
113+
114+
$this->model->execute();
115+
}
116+
}

app/code/Magento/Customer/Test/Unit/Model/Checkout/ConfigProviderTest.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class ConfigProviderTest extends \PHPUnit\Framework\TestCase
4141
*/
4242
protected $store;
4343

44+
/**
45+
* @var Url|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $customerUrl;
48+
4449
protected function setUp()
4550
{
4651
$this->storeManager = $this->getMockForAbstractClass(
@@ -49,12 +54,14 @@ protected function setUp()
4954
'',
5055
false
5156
);
57+
5258
$this->urlBuilder = $this->getMockForAbstractClass(
5359
\Magento\Framework\UrlInterface::class,
5460
[],
5561
'',
5662
false
5763
);
64+
5865
$this->scopeConfig = $this->getMockForAbstractClass(
5966
\Magento\Framework\App\Config\ScopeConfigInterface::class,
6067
[],
@@ -71,10 +78,13 @@ protected function setUp()
7178
['getBaseUrl']
7279
);
7380

81+
$this->customerUrl = $this->createMock(\Magento\Customer\Model\Url::class);
82+
7483
$this->provider = new ConfigProvider(
7584
$this->urlBuilder,
7685
$this->storeManager,
77-
$this->scopeConfig
86+
$this->scopeConfig,
87+
$this->customerUrl
7888
);
7989
}
8090

@@ -83,9 +93,8 @@ public function testGetConfigWithoutRedirect()
8393
$loginUrl = 'http://url.test/customer/login';
8494
$baseUrl = 'http://base-url.test';
8595

86-
$this->urlBuilder->expects($this->exactly(2))
87-
->method('getUrl')
88-
->with(Url::ROUTE_ACCOUNT_LOGIN)
96+
$this->customerUrl->expects($this->exactly(2))
97+
->method('getLoginUrl')
8998
->willReturn($loginUrl);
9099
$this->storeManager->expects($this->once())
91100
->method('getStore')
@@ -112,9 +121,8 @@ public function testGetConfig()
112121
$loginUrl = 'http://base-url.test/customer/login';
113122
$baseUrl = 'http://base-url.test';
114123

115-
$this->urlBuilder->expects($this->exactly(2))
116-
->method('getUrl')
117-
->with(Url::ROUTE_ACCOUNT_LOGIN)
124+
$this->customerUrl->expects($this->exactly(2))
125+
->method('getLoginUrl')
118126
->willReturn($loginUrl);
119127
$this->storeManager->expects($this->once())
120128
->method('getStore')

app/code/Magento/Directory/Model/PriceCurrency.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ public function format(
7777
$scope = null,
7878
$currency = null
7979
) {
80-
return $this->getCurrency($scope, $currency)
81-
->formatPrecision($amount, $precision, [], $includeContainer);
80+
return $this->createCurrency($scope, $currency)->formatPrecision($amount, $precision, [], $includeContainer);
8281
}
8382

8483
/**
@@ -101,20 +100,7 @@ public function convertAndFormat(
101100
*/
102101
public function getCurrency($scope = null, $currency = null)
103102
{
104-
if ($currency instanceof Currency) {
105-
$currentCurrency = $currency;
106-
} elseif (is_string($currency)) {
107-
$currency = $this->currencyFactory->create()
108-
->load($currency);
109-
$baseCurrency = $this->getStore($scope)
110-
->getBaseCurrency();
111-
$currentCurrency = $baseCurrency->getRate($currency) ? $currency : $baseCurrency;
112-
} else {
113-
$currentCurrency = $this->getStore($scope)
114-
->getCurrentCurrency();
115-
}
116-
117-
return $currentCurrency;
103+
return $this->createCurrency($scope, $currency, true);
118104
}
119105

120106
/**
@@ -157,4 +143,30 @@ public function round($price)
157143
{
158144
return round($price, 2);
159145
}
146+
147+
/**
148+
* Get currency considering currency rate configuration.
149+
*
150+
* @param null|string|bool|int|\Magento\Framework\App\ScopeInterface $scope
151+
* @param \Magento\Framework\Model\AbstractModel|string|null $currency
152+
* @param bool $includeRate
153+
*
154+
* @return Currency
155+
*/
156+
private function createCurrency($scope, $currency, bool $includeRate = false)
157+
{
158+
if ($currency instanceof Currency) {
159+
$currentCurrency = $currency;
160+
} elseif (is_string($currency)) {
161+
$currentCurrency = $this->currencyFactory->create()->load($currency);
162+
if ($includeRate) {
163+
$baseCurrency = $this->getStore($scope)->getBaseCurrency();
164+
$currentCurrency = $baseCurrency->getRate($currentCurrency) ? $currentCurrency : $baseCurrency;
165+
}
166+
} else {
167+
$currentCurrency = $this->getStore($scope)->getCurrentCurrency();
168+
}
169+
170+
return $currentCurrency;
171+
}
160172
}

app/code/Magento/Eav/Model/Config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ public function getAttribute($entityType, $code)
503503
}
504504

505505
if (isset($this->attributes[$entityTypeCode][$code])) {
506+
\Magento\Framework\Profiler::stop('EAV: ' . __METHOD__);
506507
return $this->attributes[$entityTypeCode][$code];
507508
}
508509

0 commit comments

Comments
 (0)