Type
magento2-module
Enables developers to include Magento blocks in their themes that have access to Store Configuration like address, phone number, etc.
magento2-module
MIT
None
None
None
None
None
SemExpert_StoreInfoBlocks enables developers to include Magento blocks in their themes that have access to Store Configuration like address, phone number, etc.
To get started you only need to add the module to an existing Magento2 installation.
You need a running copy of Magento2
Also, in order for composer to locate the module repository, you need to have set up SemExpert repository:
composer config repositories.semexpert composer https://packages.semexpert.com.ar/
To get StoreInfoBlocks up and running, you need to add it as a dependency to your Magento composer.json file
composer require semexpert/module-store-info-blocks
Or add it manually to your composer.json
{
"require": {
"semexpert/module-store-info-blocks": "*"
}
}
After installing, you need to enable via the Magento CLI
php bin/magento module:enable SemExpert_StoreInfoBlocks
This module provides only unit tests that can be hooked into Magento testsuite in the standard way
php bin/magento dev:tests:run unit
In order to run this module's tests exclusively you can use the provided dev/phpunit.xml
configuration file.
vendor/bin/phpunit -c vendor/semexpert/moodule-store-info-blocks/dev/phpunit.xml
I found no need for integration or functional tests as of yet. And also I am unsure about how to write those.
The module follows Magento 2.2 PHP and Less coding standards. You should test your code using the provided black/white lists and phpunit.xml configuration.
cp ./dev/tests/static/phpunit.xml dev/tests/static/phpunit.xml
cp ./dev/tests/static/less/whitelist/common.txt dev/tests/static/testsuite/Magento/Test/Less/_files/whitelist/common.txt
cp ./dev/tests/static/php/whitelist/common.txt dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/common.txt
The module provides 2 types of blocks
SemExpert\StoreInfoBlocks\Block\Template
Provides a stadard Template block with access to store configuration
informationSemExpert\StoreInfoBlocks\Block\Value
Allow to output a single configuration value without formatting. Requires some
setup via layout xmlThese blocks are available for use in your custom themes but are not automatically included anywhere on the site.
By simply calling the Template block in a layout, the provided storeinfo.phtml template will be used which is provided only as an example
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="header.panel">
<block class="SemExpert\StoreInfoBlocks\Block\Template" name="header.storeinfo" />
</referenceContainer>
</body>
</page>
or you can provide your own template. Within the template, you can access a DataObject containing the store information
by calling $block->getStoreInformation()
default.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="header.panel">
<block class="SemExpert\StoreInfoBlocks\Block\Template" name="header.storeinfo"
template="storeinfo-modal-window.phtml" />
</referenceContainer>
</body>
</page>
storeinfo-modal-window.phtml
<?php $storeInfo = $block->getStoreInformation(); ?>
<div class="call-us">
<strong>Call Us at:</strong> <?= $storeInfo->getData('phone') ?> <?= $storeInfo->getData('hours') ?>
</div>
Available data keys are:
You can set up a value block via layout XML to retrieve a single unformatted value
contact_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="contactForm">
<block class="SemExpert\StoreInfoBlocks\Block\Value" name="storephone">
<arguments>
<argument name="key" type="xsi:string">phone</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
app/design/SemExpert/CustomTheme/Magento_Contact/templates/form.phtml
<form>
<!-- ... -->
</form>
<p>
Or call us at <a href=tel:<?= $block->getChildHtml('storephone') ?>"><?= $block->getChildHtml('storephone') ?></a>
</p>
Check the description for Template block for a list of accepted values for the key
argument.
We use SemVer for versioning. To see available versions, check the tags for this repository.
Also check the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details