├── LICENSE
├── Plugin
└── StoreCodeBodyClassPlugin.php
├── README.md
├── composer.json
├── etc
├── frontend
│ └── events.xml
└── module.xml
└── registration.php
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Sam Granger
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Plugin/StoreCodeBodyClassPlugin.php:
--------------------------------------------------------------------------------
1 |
6 | */
7 |
8 | namespace SamGranger\StoreCodeBodyClass\Plugin;
9 |
10 | use Magento\Framework\Event\ObserverInterface;
11 | use Magento\Framework\Event\Observer;
12 | use Magento\Framework\View\Page\Config;
13 | use Magento\Store\Model\StoreManagerInterface;
14 |
15 |
16 | class StoreCodeBodyClassPlugin implements ObserverInterface
17 | {
18 | protected $config;
19 | protected $storeManager;
20 |
21 | public function __construct(
22 | Config $config,
23 | StoreManagerInterface $storeManager
24 | ){
25 | $this->config = $config;
26 | $this->storeManager = $storeManager;
27 | }
28 |
29 | public function execute(Observer $observer){
30 | $store = $this->storeManager->getStore();
31 | $storeCode = $store->getCode();
32 | $websiteCode = $store->getWebsite()->getCode();
33 | $this->config->addBodyClass($storeCode);
34 | $this->config->addBodyClass($websiteCode);
35 | }
36 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://packagist.org/packages/samgranger/module-store-code-body-class) [](https://packagist.org/packages/samgranger/module-store-code-body-class) [](https://packagist.org/packages/samgranger/module-store-code-body-class) [](https://packagist.org/packages/samgranger/module-store-code-body-class)
2 | # Magento 2 Store Code Body Class Plugin
3 |
4 | As the name suggests, this plugin simply adds the store & website code to the body class.
5 |
6 | ## Install
7 | ```
8 | composer require samgranger/module-store-code-body-class
9 | php bin/magento setup:upgrade
10 | ```
11 |
12 | You might have to clear Magento's cache after installation to see the changes depending on your situation.
13 |
14 | ## License
15 | This module has been released under the MIT license.
16 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "samgranger/module-store-code-body-class",
3 | "description": "The Store Code Body Class module for Magento2 adds the website & store code to the body class.",
4 | "type": "magento2-module",
5 | "version": "2.0.1",
6 | "license": "MIT",
7 | "authors": [
8 | {
9 | "name": "Sam Granger",
10 | "email": "sam.granger@gmail.com",
11 | "homepage": "http://www.github.com/samgranger"
12 | }
13 | ],
14 | "autoload": {
15 | "files": [
16 | "registration.php"
17 | ],
18 | "psr-4": {
19 | "SamGranger\\StoreCodeBodyClass\\": ""
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/etc/frontend/events.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/etc/module.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/registration.php:
--------------------------------------------------------------------------------
1 |
6 | */
7 |
8 | \Magento\Framework\Component\ComponentRegistrar::register(
9 | \Magento\Framework\Component\ComponentRegistrar::MODULE,
10 | 'SamGranger_StoreCodeBodyClass',
11 | __DIR__
12 | );
13 |
--------------------------------------------------------------------------------