imi / magento2-store-switch-all-store-views
此模块使所有商店视图在商店切换器中可用,无论它们属于哪个商店或网站。
Requires
- magento/module-cms: *
- magento/module-store: *
This package is auto-updated.
Last update: 2024-09-23 09:39:23 UTC
README
此Magento模块扩展了默认的商店切换器,并显示所有商店视图,无论它们关联的商店或网站。
它扩展了核心商店切换 Magento\Store\Block\Switcher
。
通过将 \IMI\StoreSwitch\ViewModel\StoreSwitchModel
作为参数传递给切换器块,并使用 IMI_StoreSwitch::switch/languages.phtml
模板,您可以在所有网站的商店之间切换。
可以在默认、网站和商店范围内启用或禁用切换器。相应的acl资源是 IMI_StoreSwitch::config
。
切换器默认禁用,可以通过配置值 imi_store_switch/general/enable
或在 Stores > iMi > Store Switch
的管理配置中启用。
仅显示国家代码或国家代码和名称
默认情况下,商店切换器看起来像这样
还有一个选项,仅显示商店视图中的国家代码。如果启用,可用的选项将仅显示国家代码,否则将显示名称和国家代码。
启用选项后,它看起来像这样
限制网站间的切换
您可以配置商店切换器,以便只能在一些网站之间切换,而不是所有网站。为此,您需要将配置变量 imi_store_switch/general/available_web_sites
设置为您要允许的网站的ID。
例如
n98-magerun2 config:store:set --scope websites --scope-id 1 imi_store_switch/general/available_web_sites 1,2
n98-magerun2 config:store:set --scope websites --scope-id 2 imi_store_switch/general/available_web_sites 1,2
n98-magerun2 config:store:set --scope websites --scope-id 3 imi_store_switch/general/available_web_sites 3
这将允许在ID为1和2的网站之间的商店视图中切换,但不能切换到ID为3(3中的商店视图仍然可用)。
默认情况下(如果未设置配置变量),您可以切换到所有其他网站。将其设置为空字符串或null以禁止切换到其他网站。
使用直接链接而不是重定向
您可以配置切换器使用直接链接而不是重定向方法。但是,这仅适用于不共享URL的商店。您可以通过在 Stores > Settings > Configuration > IMI > Store Switch > General > Use direct Links 下的管理面板或通过cli启用此功能。
n98-magerun2 config:store:set imi_store_switch/general/use_direct_links 1
安装
安装模块的最简单方法是从 packagist 运行
composer require imi/magento2-store-switch-all-store-views bin/magento module:enable IMI_StoreSwitch bin/magento setup:upgrade bin/magento cache:flush
如果您在生产模式下运行此操作,请运行
bin/magento setup:static-content:deploy bin/magento cache:flush
Porto 主题
这仅对Porto主题提供部分支持,不提供保修。
您可以在子主题的 default.xml
中尝试此布局更新
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="porto_header">
<block class="Magento\Store\Block\Switcher" name="store_language" as="store_language" template="IMI_StoreSwitch::switch/languages-porto.phtml">
<arguments>
<argument name="view_model" xsi:type="object">IMI\StoreSwitch\ViewModel\StoreSwitchModel</argument>
</arguments>
<action method="setTemplate" ifconfig="imi_store_switch/general/use_direct_links">
<argument name="template" xsi:type="string">IMI_StoreSwitch::switch/direct/languages-porto.phtml</argument>
</action>
</block>
</referenceContainer>
</body>
</page>
Hyvä 主题
这仅对Hyvä主题提供部分支持,不提供保修。
许可
© 2020 iMi digital GmbH。在 MIT 许可下发布。