PrestaShop 8.1.5 Megafox主题头部登录后不显示用户名求助
PrestaShop 8.1.5 + Megafox主题:登录后头部无法显示用户名
环境:PrestaShop 8.1.5 + Megafox主题
问题:网站头部用户信息为下拉菜单样式,用户登录后无法显示用户名,需求是仅登录时展示用户名。已尝试修改ps_customer.tpl、编辑ps_customersing.tpl移除欢迎消息,问题未解决。
问题表现
登录后头部仅显示"Account"和"Hi, Welcome ",未加载出用户名。
当前ps_customer.tpl代码
<div class="user-info dropdown js-dropdown"> <span class="user-info-title expand-more _gray-darker" data-toggle="dropdown"> <span class="account_title">{l s='Account' d='Shop.Theme.Global'}</span> {if $logged} <span class="register_text"><a href="{$my_account_url}">{l s='Hi, Welcome ' d='Shop.Theme.Global'}</a></span> {else} <span class="account_text">{l s='Login - Register' d='Shop.Theme.Global'}</span> {/if} </span> <ul class="dropdown-menu-"> {if $logged} <li> <a class="account dropdown-item" href="{$urls.pages.my_account}" title="{l s='View my customer account' d='Shop.Theme.Customeraccount'}" rel="nofollow" > <span class="">{$customerName}</span> </a> </li> <li> <a class="logout dropdown-item" href="{$urls.actions.logout}" rel="nofollow" > {l s='Logout' d='Shop.Theme.Actions'} </a> </li> {else} <li> <a class="dropdown-item" href="{$urls.pages.my_account}" title="{l s='Log in to your customer account' d='Shop.Theme.Customeraccount'}" rel="nofollow" > <span>{l s='Login' d='Shop.Theme.Actions'}</span> </a> </li> <li> <a href="{$urls.pages.register}"><span>{l s='Register' d='Shop.Theme.Global'}</span></a> </li> {/if} <li> {hook h='displayStWishlistTopLink'} </li> <li> {hook h='displayStCompareTopLink'} </li> </ul> </div>
修复步骤
修正用户名变量
PrestaShop 8.x默认通过$customer对象获取用户信息,而非$customerName。将下拉菜单中的{$customerName}替换为:{$customer->firstname}或显示全名:
{$customer->firstname} {$customer->lastname}在头部触发区显示用户名
若要在头部直接展示用户名,修改登录状态下的文本块:{if $logged} <span class="register_text"><a href="{$my_account_url}">{l s='Hi, ' d='Shop.Theme.Global'}{$customer->firstname}</a></span> {else} <span class="account_text">{l s='Login - Register' d='Shop.Theme.Global'}</span> {/if}强制清除缓存
修改模板后必须执行:- 后台进入高级参数 > 性能,点击「清除缓存」
- 清除浏览器本地缓存(Ctrl+Shift+R强制刷新)
排查主题自定义逻辑
Megafox主题可能对用户变量有二次封装,检查主题目录下的header.tpl或相关控制器文件,确认是否存在变量覆盖或未传递$customer的情况。
内容的提问来源于stack exchange,提问作者user2500183
相关产品推荐
相关产品推荐

