-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from ihorvansach/17-notification-banner
17 notification banner
- Loading branch information
Showing
11 changed files
with
323 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
app/code/Magento/LoginAsCustomer/CustomerData/LoginAsCustomer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\LoginAsCustomer\CustomerData; | ||
|
||
use Magento\Customer\CustomerData\SectionSourceInterface; | ||
use Magento\Customer\Model\Session; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
/** | ||
* Customer data for the logged_as_customer section | ||
*/ | ||
class LoginAsCustomer implements SectionSourceInterface | ||
{ | ||
/** | ||
* @var Session | ||
*/ | ||
private $customerSession; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* LoginAsCustomer constructor. | ||
* @param Session $customerSession | ||
* @param StoreManagerInterface $storeManager | ||
*/ | ||
public function __construct( | ||
Session $customerSession, | ||
StoreManagerInterface $storeManager | ||
) { | ||
$this->customerSession = $customerSession; | ||
$this->storeManager = $storeManager; | ||
} | ||
|
||
/** | ||
* Retrieve private customer data for the logged_as_customer section | ||
* @return array | ||
*/ | ||
public function getSectionData():array | ||
{ | ||
if (!$this->customerSession->getCustomerId()) { | ||
return []; | ||
} | ||
|
||
return [ | ||
'admin_user_id' => $this->customerSession->getLoggedAsCustomerAdmindId(), | ||
'website_name' => $this->storeManager->getWebsite()->getName() | ||
]; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
app/code/Magento/LoginAsCustomer/ViewModel/Configuration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\LoginAsCustomer\ViewModel; | ||
|
||
use Magento\Customer\Model\Context; | ||
|
||
/** | ||
* View model to get extension configuration in the template | ||
*/ | ||
class Configuration implements \Magento\Framework\View\Element\Block\ArgumentInterface | ||
{ | ||
|
||
/** | ||
* @var \Magento\LoginAsCustomer\Model\Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* Customer session | ||
* | ||
* @var \Magento\Framework\App\Http\Context | ||
*/ | ||
private $httpContext; | ||
|
||
/** | ||
* Configuration constructor. | ||
* @param \Magento\LoginAsCustomer\Model\Config $config | ||
* @param \Magento\Framework\App\Http\Context $httpContext | ||
*/ | ||
public function __construct( | ||
\Magento\LoginAsCustomer\Model\Config $config, | ||
\Magento\Framework\App\Http\Context $httpContext | ||
) { | ||
$this->config = $config; | ||
$this->httpContext = $httpContext; | ||
} | ||
|
||
/** | ||
* Retrieve true if login as a customer is enabled | ||
* @return bool | ||
*/ | ||
public function isEnabled():bool | ||
{ | ||
return $this->config->isEnabled() && $this->isLoggedIn(); | ||
} | ||
|
||
/** | ||
* Is logged in | ||
* | ||
* @return bool | ||
*/ | ||
private function isLoggedIn():bool | ||
{ | ||
return (bool)$this->httpContext->getValue(Context::CONTEXT_AUTH); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"Close Session","Close Session" | ||
"You are connected as <strong>%1</strong> on %2","You are connected as <strong>%1</strong> on %2" |
23 changes: 23 additions & 0 deletions
23
app/code/Magento/LoginAsCustomer/view/frontend/layout/default.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceContainer name="after.body.start"> | ||
<block name="login-as-customer-notice" template="Magento_LoginAsCustomer::html/notices.phtml"> | ||
<arguments> | ||
<argument name="config" xsi:type="object">Magento\LoginAsCustomer\ViewModel\Configuration</argument> | ||
</arguments> | ||
|
||
<container name="login-as-customer-notice-links"> | ||
<block class="Magento\Customer\Block\Account\AuthorizationLink" name="login-as-customer-logout-link" | ||
template="Magento_LoginAsCustomer::html/notices/logout-link.phtml" /> | ||
</container> | ||
</block> | ||
</referenceContainer> | ||
</body> | ||
</page> |
41 changes: 41 additions & 0 deletions
41
app/code/Magento/LoginAsCustomer/view/frontend/templates/html/notices.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/** | ||
* @var \Magento\Framework\View\Element\Template $block | ||
* @var \Magento\Framework\Escaper $escaper | ||
*/ | ||
?> | ||
<?php if ($block->getConfig()->isEnabled()) : ?> | ||
<div data-bind="scope: 'loginAsCustomer'" > | ||
<div class="lac-notification clearfix" data-bind="visible: isVisible" style="display: none"> | ||
<div class="top-container"> | ||
<div class="lac-notification-icon wrapper"> | ||
<img class="logo-img" src="<?= $escaper->escapeUrl($block->getViewFileUrl('Magento_LoginAsCustomer::images/magento-icon.svg')) ?>" alt="Magento" /> | ||
</div> | ||
<div class="lac-notification-text wrapper"> | ||
<span data-bind="html: notificationText"></span> | ||
</div> | ||
<div class="lac-notification-links wrapper"> | ||
<?= $block->getChildHtml('login-as-customer-notice-links') ?> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script type="text/x-magento-init"> | ||
{ | ||
"*": { | ||
"Magento_Ui/js/core/app": { | ||
"components": { | ||
"loginAsCustomer": { | ||
"component": "Magento_LoginAsCustomer/js/view/loginAsCustomer" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
<?php endif; ?> |
20 changes: 20 additions & 0 deletions
20
app/code/Magento/LoginAsCustomer/view/frontend/templates/html/notices/logout-link.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/** | ||
* @var \Magento\Customer\Block\Account\AuthorizationLink $block | ||
* @var \Magento\Framework\Escaper $escaper | ||
*/ | ||
$dataPostParam = ''; | ||
if ($block->isLoggedIn()) { | ||
$dataPostParam = sprintf(" data-post='%s'", $block->getPostParams()); | ||
} | ||
?> | ||
|
||
<a class="lac-notification-close-link" <?= /* @noEscape */ $block->getLinkAttributes() ?><?= /* @noEscape */ $dataPostParam ?>> | ||
<?= $escaper->escapeHtml(__('Close Session')) ?> | ||
</a> | ||
|
67 changes: 67 additions & 0 deletions
67
app/code/Magento/LoginAsCustomer/view/frontend/web/css/source/_module.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
& when (@media-common = true) { | ||
|
||
.lac-notification { | ||
background-color: #373330; | ||
color: #fff; | ||
font-size: 16px; | ||
|
||
.lac-notification-icon { | ||
float:left; | ||
margin: 10px 25px 10px 10px; | ||
|
||
.logo-img { | ||
display: block | ||
} | ||
} | ||
|
||
.lac-notification-text { | ||
float:left; | ||
padding: 15px 0; | ||
} | ||
|
||
.lac-notification-links { | ||
float: right; | ||
padding: 15px 0; | ||
a { | ||
color:#fff; | ||
font-size: 14px; | ||
} | ||
|
||
.lac-notification-close-link { | ||
&:after { | ||
content: ' '; | ||
vertical-align: middle; | ||
display: inline-block; | ||
background: url('../Magento_LoginAsCustomer/images/close.svg'); | ||
height: 12px; | ||
width: 12px; | ||
margin-left: 5px; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
.media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__m) { | ||
.lac-notification { | ||
padding: 5px 0; | ||
|
||
.lac-notification-icon { | ||
display: none; | ||
} | ||
|
||
.lac-notification-text, | ||
.lac-notification-links { | ||
float: none; | ||
text-align: center; | ||
padding: 5px 0; | ||
} | ||
|
||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
app/code/Magento/LoginAsCustomer/view/frontend/web/images/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
app/code/Magento/LoginAsCustomer/view/frontend/web/images/magento-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions
41
app/code/Magento/LoginAsCustomer/view/frontend/web/js/view/loginAsCustomer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
define([ | ||
'jquery', | ||
'uiComponent', | ||
'Magento_Customer/js/customer-data', | ||
'mage/translate' | ||
], function ($, Component, customerData) { | ||
'use strict'; | ||
|
||
return Component.extend({ | ||
|
||
defaults: { | ||
isVisible: false | ||
}, | ||
|
||
/** @inheritdoc */ | ||
initialize: function () { | ||
this._super(); | ||
|
||
this.customer = customerData.get('customer'); | ||
this.loginAsCustomer = customerData.get('logged_as_customer'); | ||
this.isVisible(this.loginAsCustomer().admin_user_id); | ||
|
||
this.notificationText = $.mage.__('You are connected as <strong>%1</strong> on %2') | ||
.replace('%1', this.customer().fullname) | ||
.replace('%2', this.loginAsCustomer().website_name); | ||
}, | ||
|
||
/** @inheritdoc */ | ||
initObservable: function () { | ||
this._super() | ||
.observe('isVisible'); | ||
|
||
return this; | ||
} | ||
}); | ||
}); |