Skip to content

Commit 2ba5492

Browse files
committed
Merge remote-tracking branch 'origin/magento/magento2-login-as-customer#58' into login-as-customer-bugsfixing2
2 parents 63bae63 + 520e8ab commit 2ba5492

File tree

12 files changed

+247
-34
lines changed

12 files changed

+247
-34
lines changed

app/code/Magento/LoginAsCustomer/Test/Mftf/ActionGroup/AdminLoginAsCustomerLoginFromCustomerPageManualChooseActionGroup.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
</annotations>
1515
<arguments>
1616
<argument name="customerId" type="string"/>
17-
<argument name="storeViewName" type="string" defaultValue="default"/>
17+
<argument name="storeName" type="string" defaultValue="default"/>
1818
</arguments>
1919

2020
<amOnPage url="{{AdminEditCustomerPage.url(customerId)}}" stepKey="gotoCustomerPage"/>
2121
<waitForPageLoad stepKey="waitForCustomerPageLoad"/>
2222
<click selector="{{AdminCustomerMainActionsSection.loginAsCustomer}}" stepKey="clickLoginAsCustomerLink"/>
23-
<see selector="{{AdminConfirmationModalSection.title}}" userInput="Login as Customer: Select Store View" stepKey="seeModal"/>
24-
<see selector="{{AdminConfirmationModalSection.message}}" userInput="Actions taken while in &quot;Login as Customer&quot; will affect actual customer data." stepKey="seeModalMessage"/>
25-
<selectOption selector="{{AdminLoginAsCustomerConfirmationModalSection.storeView}}" userInput="{{storeViewName}}" stepKey="selectStoreView"/>
23+
<see selector="{{AdminConfirmationModalSection.title}}" userInput="Login as Customer: Select Store" stepKey="seeModal"/>
24+
<see selector="{{AdminConfirmationModalSection.message}}" userInput="Actions taken while in &quot;Login as Customer&quot; will affect actual customer data." stepKey="seeModalMessage"/>
25+
<selectOption selector="{{AdminLoginAsCustomerConfirmationModalSection.store}}" userInput="{{storeName}}" stepKey="selectStore"/>
2626
<click selector="{{AdminConfirmationModalSection.ok}}" stepKey="clickLogin"/>
2727
<switchToNextTab stepKey="switchToNewTab"/>
2828
<waitForPageLoad stepKey="waitForPageLoad"/>

app/code/Magento/LoginAsCustomer/Test/Mftf/Section/AdminLoginAsCustomerConfirmationModalSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="AdminLoginAsCustomerConfirmationModalSection">
12-
<element name="storeView" type="select" selector="//select[@id='lac-confirmation-popup-store-id']"/>
12+
<element name="store" type="select" selector="//select[@id='lac-confirmation-popup-store-id']"/>
1313
</section>
1414
</sections>

app/code/Magento/LoginAsCustomer/Test/Mftf/Test/AdminLoginAsCustomerAutoDetectionTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<test name="AdminLoginAsCustomerAutoDetectionTest">
1212
<annotations>
1313
<features value="Login as Customer"/>
14-
<stories value="Select Store View based on 'Store View To Login In' setting"/>
14+
<stories value="Select Store based on 'Store View To Login In' setting"/>
1515
<title
1616
value="Admin user directly login into customer account with store View To Login In = Auto detection"/>
1717
<description

app/code/Magento/LoginAsCustomer/Test/Mftf/Test/AdminLoginAsCustomerManualChooseStoreCodeInUrlTest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<test name="AdminLoginAsCustomerManualChooseStoreCodeInUrlTest" extends="AdminLoginAsCustomerManualChooseTest">
1212
<annotations>
1313
<features value="Login as Customer"/>
14-
<stories value="Select Store View based on 'Store View To Login In' setting"/>
14+
<stories value="Select Store based on 'Store View To Login In' setting"/>
1515
<title
1616
value="Admin user directly login into customer account with store View To Login In = Manual Choose when store code is added to url"/>
1717
<description
@@ -29,8 +29,8 @@
2929
command="config:set {{StorefrontDisableAddStoreCodeToUrls.path}} {{StorefrontDisableAddStoreCodeToUrls.value}}"
3030
stepKey="disableAddStoreCodeToUrls" after="enableLoginAsCustomerAutoDetection"/>
3131
</after>
32-
<actionGroup ref="AssertStorefrontStoreCodeInUrlActionGroup" stepKey="seeCustomStoreCodeInUrl" after="assertCustomStoreView">
33-
<argument name="storeCode" value="{{customStore.code}}"/>
32+
<actionGroup ref="AssertStorefrontStoreCodeInUrlActionGroup" stepKey="seeCustomStoreViewCodeInUrl" after="assertCustomStoreView">
33+
<argument name="storeCode" value="{{customStoreEN.code}}"/>
3434
</actionGroup>
3535
</test>
3636
</tests>

app/code/Magento/LoginAsCustomer/Test/Mftf/Test/AdminLoginAsCustomerManualChooseTest.xml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111
<test name="AdminLoginAsCustomerManualChooseTest">
1212
<annotations>
1313
<features value="Login as Customer"/>
14-
<stories value="Select Store View based on 'Store View To Login In' setting"/>
14+
<stories value="Select Store based on 'Store View To Login In' setting"/>
1515
<title
1616
value="Admin user directly login into customer account with store View To Login In = Manual Choose"/>
1717
<description
1818
value="Verify admin user can directly login into customer account to Custom store view when Store View To Login In = Manual Choose"/>
1919
<severity value="CRITICAL"/>
2020
<group value="login_as_customer"/>
21-
<skip>
22-
<issueId value="https://github.com/magento/magento2-login-as-customer/issues/58"/>
23-
</skip>
2421
</annotations>
2522
<before>
2623
<createData entity="Simple_US_Customer_Assistance_Allowed" stepKey="createCustomer"/>
@@ -30,11 +27,23 @@
3027
stepKey="enableLoginAsCustomerManualChoose"/>
3128
<magentoCLI command="cache:flush config" stepKey="flushCacheBeforeTestRun"/>
3229
<actionGroup ref="AdminLoginActionGroup" stepKey="adminLogin"/>
33-
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createCustomStoreView"/>
30+
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createCustomStore">
31+
<argument name="website" value="{{_defaultWebsite.name}}"/>
32+
<argument name="storeGroupName" value="{{customStoreGroup.name}}"/>
33+
<argument name="storeGroupCode" value="{{customStoreGroup.code}}"/>
34+
</actionGroup>
35+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createFirstCustomStoreView">
36+
<argument name="StoreGroup" value="customStoreGroup"/>
37+
<argument name="customStore" value="customStoreEN"/>
38+
</actionGroup>
39+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createSecondCustomStoreView">
40+
<argument name="StoreGroup" value="customStoreGroup"/>
41+
<argument name="customStore" value="customStoreFR"/>
42+
</actionGroup>
3443
</before>
3544
<after>
36-
<actionGroup ref="AdminDeleteStoreViewActionGroup" stepKey="deleteCustomStoreView">
37-
<argument name="customStore" value="customStore"/>
45+
<actionGroup ref="DeleteCustomStoreActionGroup" stepKey="deleteCustomStore">
46+
<argument name="storeGroupName" value="customStoreGroup.name"/>
3847
</actionGroup>
3948
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
4049
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 0"
@@ -49,7 +58,7 @@
4958
<actionGroup ref="AdminLoginAsCustomerLoginFromCustomerPageManualChooseActionGroup"
5059
stepKey="loginAsCustomerFromCustomerPage">
5160
<argument name="customerId" value="$$createCustomer.id$$"/>
52-
<argument name="storeViewName" value="{{customStore.name}}"/>
61+
<argument name="storeName" value="{{customStoreGroup.name}}"/>
5362
</actionGroup>
5463

5564
<!-- Assert Customer logged on on custom store view -->
@@ -58,7 +67,7 @@
5867
<argument name="customerEmail" value="$$createCustomer.email$$"/>
5968
</actionGroup>
6069
<actionGroup ref="StorefrontAssertCustomerOnStoreViewActionGroup" stepKey="assertCustomStoreView">
61-
<argument name="storeViewName" value="{{customStore.name}}"/>
70+
<argument name="storeViewName" value="{{customStoreEN.name}}"/>
6271
</actionGroup>
6372

6473
<!-- Log out Customer and close tab -->

app/code/Magento/LoginAsCustomer/Test/Mftf/Test/StorefrontLoginAsCustomerSeeSpecialPriceOnCategoryTest.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
<description value="Login as customer sees special prices on category"/>
1717
<severity value="CRITICAL"/>
1818
<group value="login_as_customer"/>
19-
<skip>
20-
<issueId value="https://github.com/magento/magento2-login-as-customer/pull/193"/>
21-
</skip>
2219
</annotations>
2320
<before>
2421
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 1"

app/code/Magento/LoginAsCustomerAdminUi/Block/Adminhtml/ConfirmationPopup.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
namespace Magento\LoginAsCustomerAdminUi\Block\Adminhtml;
99

1010
use Magento\Backend\Block\Template;
11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\Serialize\Serializer\Json;
13+
use Magento\LoginAsCustomerAdminUi\Ui\Customer\Component\ConfirmationPopup\Options;
1214
use Magento\LoginAsCustomerApi\Api\ConfigInterface;
1315
use Magento\Store\Ui\Component\Listing\Column\Store\Options as StoreOptions;
1416

@@ -35,24 +37,32 @@ class ConfirmationPopup extends Template
3537
*/
3638
private $json;
3739

40+
/**
41+
* @var Options
42+
*/
43+
private $options;
44+
3845
/**
3946
* @param Template\Context $context
4047
* @param StoreOptions $storeOptions
4148
* @param ConfigInterface $config
4249
* @param Json $json
4350
* @param array $data
51+
* @param Options|null $options
4452
*/
4553
public function __construct(
4654
Template\Context $context,
4755
StoreOptions $storeOptions,
4856
ConfigInterface $config,
4957
Json $json,
50-
array $data = []
58+
array $data = [],
59+
?Options $options = null
5160
) {
5261
parent::__construct($context, $data);
5362
$this->storeOptions = $storeOptions;
5463
$this->config = $config;
5564
$this->json = $json;
65+
$this->options = $options ?? ObjectManager::getInstance()->get(Options::class);
5666
}
5767

5868
/**
@@ -65,14 +75,14 @@ public function getJsLayout()
6575
$showStoreViewOptions = $this->config->isStoreManualChoiceEnabled();
6676

6777
$layout['components']['lac-confirmation-popup']['title'] = $showStoreViewOptions
68-
? __('Login as Customer: Select Store View')
78+
? __('Login as Customer: Select Store')
6979
: __('You are about to Login as Customer');
7080
$layout['components']['lac-confirmation-popup']['content'] =
7181
__('Actions taken while in "Login as Customer" will affect actual customer data.');
7282

7383
$layout['components']['lac-confirmation-popup']['showStoreViewOptions'] = $showStoreViewOptions;
7484
$layout['components']['lac-confirmation-popup']['storeViewOptions'] = $showStoreViewOptions
75-
? $this->storeOptions->toOptionArray()
85+
? $this->options->toOptionArray()
7686
: [];
7787

7888
return $this->json->serialize($layout);

app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Backend\App\Action\Context;
1212
use Magento\Backend\Model\Auth\Session;
1313
use Magento\Customer\Api\CustomerRepositoryInterface;
14+
use Magento\Customer\Model\Config\Share;
1415
use Magento\Framework\App\Action\HttpGetActionInterface;
1516
use Magento\Framework\App\ObjectManager;
1617
use Magento\Framework\Controller\Result\Redirect;
@@ -27,6 +28,7 @@
2728
use Magento\LoginAsCustomerApi\Api\SaveAuthenticationDataInterface;
2829
use Magento\LoginAsCustomerApi\Api\SetLoggedAsCustomerCustomerIdInterface;
2930
use Magento\Store\Model\StoreManagerInterface;
31+
use Magento\Store\Model\StoreSwitcher\ManageStoreCookie;
3032

3133
/**
3234
* Login as customer action
@@ -83,6 +85,16 @@ class Login extends Action implements HttpGetActionInterface
8385
*/
8486
private $url;
8587

88+
/**
89+
* @var Share
90+
*/
91+
private $share;
92+
93+
/**
94+
* @var ManageStoreCookie
95+
*/
96+
private $manageStoreCookie;
97+
8698
/**
8799
* @var SetLoggedAsCustomerCustomerIdInterface
88100
*/
@@ -103,6 +115,8 @@ class Login extends Action implements HttpGetActionInterface
103115
* @param SaveAuthenticationDataInterface $saveAuthenticationData
104116
* @param DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser
105117
* @param Url $url
118+
* @param Share $share
119+
* @param ManageStoreCookie $manageStoreCookie
106120
* @param SetLoggedAsCustomerCustomerIdInterface $setLoggedAsCustomerCustomerId
107121
* @param IsLoginAsCustomerEnabledForCustomerInterface $isLoginAsCustomerEnabled
108122
*
@@ -118,6 +132,8 @@ public function __construct(
118132
SaveAuthenticationDataInterface $saveAuthenticationData,
119133
DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser,
120134
Url $url,
135+
?Share $share = null,
136+
?ManageStoreCookie $manageStoreCookie = null,
121137
?SetLoggedAsCustomerCustomerIdInterface $setLoggedAsCustomerCustomerId = null,
122138
?IsLoginAsCustomerEnabledForCustomerInterface $isLoginAsCustomerEnabled = null
123139
) {
@@ -131,6 +147,8 @@ public function __construct(
131147
$this->saveAuthenticationData = $saveAuthenticationData;
132148
$this->deleteAuthenticationDataForUser = $deleteAuthenticationDataForUser;
133149
$this->url = $url;
150+
$this->share = $share ?? ObjectManager::getInstance()->get(Share::class);
151+
$this->manageStoreCookie = $manageStoreCookie ?? ObjectManager::getInstance()->get(ManageStoreCookie::class);
134152
$this->setLoggedAsCustomerCustomerId = $setLoggedAsCustomerCustomerId
135153
?? ObjectManager::getInstance()->get(SetLoggedAsCustomerCustomerIdInterface::class);
136154
$this->isLoginAsCustomerEnabled = $isLoginAsCustomerEnabled
@@ -173,9 +191,11 @@ public function execute(): ResultInterface
173191
if ($this->config->isStoreManualChoiceEnabled()) {
174192
$storeId = (int)$this->_request->getParam('store_id');
175193
if (empty($storeId)) {
176-
$this->messageManager->addNoticeMessage(__('Please select a Store View to login in.'));
194+
$this->messageManager->addNoticeMessage(__('Please select a Store to login in.'));
177195
return $resultRedirect->setPath('customer/index/edit', ['id' => $customerId]);
178196
}
197+
} elseif ($this->share->isGlobalScope()) {
198+
$storeId = (int)$this->storeManager->getDefaultStoreView()->getId();
179199
} else {
180200
$storeId = (int)$customer->getStoreId();
181201
}
@@ -211,10 +231,17 @@ public function execute(): ResultInterface
211231
*/
212232
private function getLoginProceedRedirectUrl(string $secret, int $storeId): string
213233
{
214-
$store = $this->storeManager->getStore($storeId);
234+
$targetStore = $this->storeManager->getStore($storeId);
215235

216-
return $this->url
217-
->setScope($store)
236+
$redirectUrl = $this->url
237+
->setScope($targetStore)
218238
->getUrl('loginascustomer/login/index', ['secret' => $secret, '_nosid' => true]);
239+
240+
if (!$targetStore->isUseStoreInUrl()) {
241+
$fromStore = $this->storeManager->getStore();
242+
$redirectUrl = $this->manageStoreCookie->switch($fromStore, $targetStore, $redirectUrl);
243+
}
244+
245+
return $redirectUrl;
219246
}
220247
}

0 commit comments

Comments
 (0)