January 2, 2021
Magento2 Config Scopehint extension #
One of the most important things to understand in Magento is concept of scope! Website - Store - Storeview. For many developers it becomes pretty natural after a while - inheritance of values, global scope, website scope - difference between website and store and so on. While for us it’s easy (after a while) to understand, it might become confusing for merchants or less experienced store managers.
When it comes to configuration settings, there have been many times when I received “I’ve changed settings but it does not work” - after checking it in admin panel, I could see that setting was indeed changed, for global value - but it also had value set on storeview level, which obviosuly had higher priority than global one. As a result - there was no change visible, even after refreshing cache 10 times. Quite often - concept of scopes is not understood, many times I could see values set for storeview, even tough they were same as global ones.
There were also times, when I forgot about checking it - and when bug was reported, I forgot to check settings in admin panel and started xdebug sessions just to find that it’s matter of wrong configuration.
To help with all these rather minor issues, I decided to create small helper-module, which would give me an overview of configurations for each storeview already on general page.
How it works #
General idea is quite easy - to add element to display below config label. In order to keep page layout clean -tooltip with additional information should be shown only when hovered.
Unfortunaly, it’s not that easy to add such element, due to how it’s implemented in Magento - the only solution is to add
after plugin on
Magento\Config\Block\System\Config\Form\Field and add desired HTML (seems hacky, I know!).
Then, we add some HTML content which is injected into hidden div (which is made visible when hovering). Content for this HTML is based on code, which checks values of each config for each store, and summary is created based on admin configuration.
Values, which are different than default/global value are highlighted, so it’s easy to check, without need of changing scope to each storeview.