Shopware 6子商店本地字体配置求助:主店正常子店失效
Shopware 6子商店本地字体配置失效问题排查与解决
针对你遇到的主商店字体正常、子商店按相同步骤配置后失效的问题,以下是需要检查的关键环节和修复方案:
1. 确认子商店主题关联正确
- 进入Shopware后台「设置 > 主题管理」,检查子商店对应的活跃主题,确保它依赖你的UniTheme插件,或者直接将UniTheme设置为子商店的活跃主题。子商店可能默认使用了独立主题,导致插件样式未被加载。
2. 验证字体路径生成是否正确
- 找到子商店编译后的CSS文件(路径一般为
public/theme/[子商店ID]/assets/),搜索@font-face中的字体URL,确认实际生成的路径是否指向bundles/unitheme/assets/fonts/下的文件。 - 如果路径错误,可尝试将
$my-asset-path改为相对路径:
避免依赖$my-asset-path: '../../bundles/unitheme/assets' !default;$sw-asset-theme-url在子商店环境下的变量差异。
3. 指定子商店ID执行命令
默认的assets:install和theme:compile仅处理主商店,需明确指定子商店ID确保资源部署到对应环境:
# 查看所有商店ID ./console sales-channel:list # 安装子商店资产 ./console assets:install --shop-id=你的子商店ID # 编译子商店主题 ./console theme:compile --shop-id=你的子商店ID
4. 彻底清理缓存
- 清除子商店的服务端缓存:
./console cache:clear --shop-id=你的子商店ID - 强制刷新浏览器缓存(Ctrl+F5),避免旧CSS文件被浏览器缓存。
5. 修正@font-face配置错误
你的base.scss中存在几处错误,可能导致字体加载失败,修正后代码如下:
@font-face { font-family: 'DIN-Regular'; src: url('#{$my-asset-path}/fonts/DIN-Regular.otf'); src: local('DIN-Regular'), local('DIN-Regular'), url('#{$my-asset-path}/fonts/DIN-Regular.otf') format('opentype'); font-weight: 100; font-style: normal; } @font-face { font-family: 'Hind-Regular'; src: url('#{$my-asset-path}/fonts/Hind-Regular.eot'); src: local('Hind-Regular'), local('Hind-Regular'), url('#{$my-asset-path}/fonts/Hind-Regular.eot?#iefix') format('embedded-opentype'), url('#{$my-asset-path}/fonts/Hind-Regular.woff2') format('woff2'), url('#{$my-asset-path}/fonts/Hind-Regular.woff') format('woff'), url('#{$my-asset-path}/fonts/Hind-Regular.ttf') format('truetype'); font-weight: 500; font-style: normal; } @font-face { font-family: 'FrankRuhlLibre-Regular'; src: url('#{$my-asset-path}/fonts/FrankRuhlLibre-Regular.ttf'); src: local('FrankRuhlLibre-Regular'), local('FrankRuhlLibre-Regular'), url('#{$my-asset-path}/fonts/FrankRuhlLibre-Regular.ttf') format('truetype'); font-weight: 100; font-style: normal; } @font-face { font-family: SkemaProOmni; src: url('#{$my-asset-path}/fonts/SkemaProOmni-Medium.ttf') format('truetype'); }
修正点说明:
Hind-Regular的本地字体名称从Roboto Medium改为匹配的Hind-RegularFrankRuhlLibre-Regular的本地字体名称修正为自身名称,同时格式从opentype改为对应ttf的truetypeSkemaProOmni的格式引号修正为标准单引号
6. 检查字体文件权限
确保shopware/custom/plugins/UniTheme/src/Resources/public/assets/fonts/下的字体文件权限为644,文件夹权限为755,保证Web服务器能正常读取这些文件。
内容的提问来源于stack exchange,提问作者4m Media
相关产品推荐
相关产品推荐

