定制 siment/module-http-header-theme-switch 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

siment/module-http-header-theme-switch

Composer 安装命令:

composer require siment/module-http-header-theme-switch

包简介

Magento 2 module that enables automatic theme switching based on the X-UA-Device HTTP header. (Or any other header)

README 文档

README

Build status

Build Status Code Climate Test Coverage Issue Count

Magento 2 module that enables automatic theme switching based on X-UA-Device header. (Or any other header)

What does this module do?

This module makes sure that Magento's design exceptions logic checks the value of the header "X-UA-Device" in addition to "User-Agent" when determining what theme it should use. You can also configure it to listen to other headers than the pre-configured "X-UA-Device" header.

Why this module?

Short version

Because many web proxies, like Varnish, suggest to use the "X-UA-Device" header for device detection and Magento should respect it.

Longer version

Magento 2 allows for theme switching based on design exceptions which enables "you to specify an alternative theme for particular user-agents".

There are hundreds of user agents out there now and it makes it challenging to correctly identify which agents are coming from mobile, tablet and desktop devices.

There are great libraries for making detection easier - like the generic mobiledetect/mobiledetectlib and the excellent Magento module eadesignro/module-mobiledetect. Those modules will not work out of the box if you have a web proxy like Varnish installed.

That is why I wanted to use the Varnish Mobile Detect module which sends the "X-UA-Device" header from Varnish for device detection rather than tampering with the "User-Agent" header.

How to install

In Magento root:

$ composer require siment/module-http-header-theme-switch:"~1.0"
$ php bin/magento module:enable Siment_HttpHeaderThemeSwitch
$ php bin/magento cache:clean

Configuration

In Magento admin:

Stores -> (Settings) Configuration -> General -> Design -> HTTP Header Theme Switch -> HTTP Header:

HTTP header which will be matched for theme exceptions in addition to the standard header "User-Agent". Standard value is "HTTP_X_UA_DEVICE"

You define the matching rules under Content -> (Design) Configuration -> (Select a theme) Edit -> User Agent Rules

How to test

Make sure the Composer dependencies have been installed and that the "post-install-cmd" scripts have executed.

In module directory:

$ composer install
$ composer run-script post-install-cmd          # May not be necessary
$ vendor/bin/phpunit                            # For unit tests
$ vendor/bin/phpcs                              # For code sniffs
$ vendor/bin/phpmd src/,Test/ text phpmd.xml    # For mess detector

How to contribute

Create an issue or a pull request.

Changelog

See CHANGELOG.md

License

统计信息

  • 总下载量: 134
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: AFL-3.0
  • 更新时间: 2017-08-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固