【问题标题】:Change theme based on visitor browser根据访问者浏览器更改主题
【发布时间】:2015-07-07 11:04:20
【问题描述】:

我使用的主题不支持 6、7、8、9、10 等旧 IE 版本,因此我想以编程方式更改 Magento 主题(皮肤、布局和默认)和默认 CMS 主页(如果访问者)正在使用以前的浏览器之一,如果不是,访问者将使用默认主题。

谢谢

【问题讨论】:

    标签: magento magento-1.7 magento-1.9


    【解决方案1】:
    <frontend>
        <events>
            <controller_action_layout_load_before>
                <observers>
                    <magento_test>
                        <class>magento_test/observer</class>
                        <method>changeLayoutEvent</method>
                    </magento_test>
                </observers>
            </controller_action_layout_load_before>
        </events>
    </frontend>
    
    public function changeLayoutEvent($observer) {
      if(preg_match('/(?i)msie [1-10]/',$_SERVER['HTTP_USER_AGENT'])) {
           // if IE<=10
            Mage::getDesign()->setArea('frontend')
            ->setPackageName('default')
            ->setTheme('modern');
        } else {
            // if IE>10
            Mage::getDesign()->setArea('frontend')
            ->setPackageName('mycustompackagename')
            ->setTheme('mycustomtheme');
        } 
     }
    

    要更改默认 CMS 主页,请检查:Programmatically set the current home CMS/Page in Magento in PHP

    希望这会有所帮助!

    【讨论】:

    • 它是一种魅力,但我怎样才能设置默认的 CMS 主页?
    • 已更新答案。如果有帮助,请接受答案
    • 如果我启用了缓存网站在我切换主题时加载不佳,因为它缓存了另一个主题,请告知
    • 在切换主题代码后以编程方式清除缓存。
    • 这不是一个实用的解决方案,因为每个请求都会清除缓存,因此它将作为缓存被禁用。
    猜你喜欢
    • 2014-01-22
    • 1970-01-01
    • 2021-07-12
    • 2012-12-07
    • 2012-03-05
    • 2011-12-03
    • 2021-01-27
    • 2013-06-07
    • 2014-12-03
    相关资源
    最近更新 更多