2017 © Pedro Peláez
 

magento2-module 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)

image

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)

  • Saturday, November 11, 2017
  • by siment
  • Repository
  • 1 Watchers
  • 4 Stars
  • 134 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

siment/module-http-header-theme-switch

Build status

Build Status Code Climate Test Coverage Issue Count, (*1)

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

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., (*3)

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., (*4)

Longer version

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

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., (*6)

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., (*7)

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., (*8)

How to install

In Magento root:, (*9)

$ 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:, (*10)

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

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

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

How to test

Make sure the Composer dependencies have been installed and that the "post-install-cmd" scripts have executed., (*14)

In module directory:, (*15)

$ 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., (*16)

Changelog

See CHANGELOG.md, (*17)

License

The Versions

11/11 2017

dev-upgrade-to-2.2

dev-upgrade-to-2.2

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

  Sources   Download

AFL-3.0

The Requires

  • magento/framework ~100.1|~101.0
  • magento/module-store ~100.1.0|~100.2.0
  • php 7.0.2|7.0.4|~7.0.6|~7.1.0

 

The Development Requires

by Simen Thorsrud

03/09 2017

dev-master

9999999-dev

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

  Sources   Download

AFL-3.0

The Requires

  • magento/framework ~100.1.0
  • magento/module-store ~100.1.0

 

The Development Requires

by Simen Thorsrud

03/09 2017

1.0.4

1.0.4.0

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

  Sources   Download

AFL-3.0

The Requires

  • magento/framework ~100.1.0
  • magento/module-store ~100.1.0

 

The Development Requires

by Simen Thorsrud

27/08 2017

1.0.3

1.0.3.0

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

  Sources   Download

AFL-3.0

The Requires

  • magento/framework ~100.1.0
  • magento/module-store ~100.1.0

 

The Development Requires

by Simen Thorsrud

27/08 2017

1.0.2

1.0.2.0

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

  Sources   Download

MIT

The Requires

  • magento/framework ~100.1.0
  • magento/module-store ~100.1.0

 

The Development Requires

by Simen Thorsrud

27/08 2017

1.0.1

1.0.1.0

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

  Sources   Download

MIT

The Requires

  • magento/framework ~100.1.0
  • magento/module-store ~100.1.0

 

The Development Requires

by Simen Thorsrud

27/08 2017

1.0.0

1.0.0.0

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

  Sources   Download

MIT

The Requires

  • magento/framework ~100.1.0
  • magento/module-store ~100.1.0

 

The Development Requires

by Simen Thorsrud