主页
我想在登录后显示我的帐户。
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn()) {
// display your link here
}
----------------------从控制器-------------------
$this->_objectManager->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn()) {
// display your link here
}
我们可以轻松做到这一点 假设我们需要在登录后仅显示"我的帐户"链接我们必须覆盖自定义主题中的 authorization.phtml 文件,我们可以根据我们的要求放置我们的逻辑。
app/design/frontend/Namespace/Customtheme/Magento_Customer/templates/account/link/ authorization.phtml
覆盖此文件后,我们可以输入登录名 -
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/** @var MagentoCustomerBlockAccountAuthorizationLink $block */
$objectManagerlogin = MagentoFrameworkAppObjectManager::getInstance();
$baseurl = $objectManagerlogin->get('MagentoStoreModelStoreManagerInterface')->getStore(0)->getBaseUrl();
$dataPostParam = '';
if ($block->isLoggedIn()) {
$dataPostParam = sprintf(" data-post='%s'", $block->getPostParams());
}
?>
<?php if($block->isLoggedIn() && $baseurl || $block->isLoggedIn() ) : ?>
<li class="authorization-link" >
<a href="<?php echo $baseurl .'customer/account/logout'; ?>">Sign Out</a>
</li>
<li class="authorization-link custom-top-link-myaccount-mobile" >
<a href="<?php echo $baseurl .'customer/account/'; ?>">My Account</a>
</li>
<?php else : ?>
<li class="authorization-link" data-label="<?= $block->escapeHtmlAttr(__('or')) ?>">
<a <?= /* @noEscape */ $block->getLinkAttributes() ?><?= /* @noEscape */ $dataPostParam ?>>
<?= $block->escapeHtml($block->getLabel()) ?>
</a>
</li>
<?php endif; ?>
我希望它会起作用,如果您有任何问题,请告诉我