siteation/magento2-storeinfo

Get your store information with ease

Installs: 2 819

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 1

Forks: 2

Open Issues: 1

Language:HTML

Type:magento2-module

2.1.0 2023-09-24 14:53 UTC

This package is auto-updated.

Last update: 2024-02-18 15:50:11 UTC


README

Packagist Version Supported Magento Versions Hyvä Themes Supported License

This Magento 2 module adds the option to get the store information with ease.

So you can get the store phone number from the Stores > Config. Instead using static block or hard code it in your template directly.

Installation

Install the package via;

composer require siteation/magento2-storeinfo
bin/magento module:enable Siteation_StoreInfo

Note

This Module requires Magento 2.4 or higher! For more requirements see the composer.json.

How to use

By default, this module does not load any content.

This approach was chosen intentionally to ensure that it doesn't impose any specific styling or templating on your theme.

Instead, we provide this module as a versatile toolkit that you can seamlessly integrate into your theme.

To get started, you can refer to the sample configurations and usage examples provided below.

This empowers you to tailor the module to your specific needs and maintain full control over the styling and templating to perfectly match your theme.

Important

We also offer a StoreInfo Extra module that add more fields, for example social media links, check it out here: StoreInfo Extra

Adding a address block

We have made an address block that uses the store information. And also comes with schema tags to enrich the Contact data.

To load the default store address block use 1 of the following xml samples in your template.

Hyva - XML Sample
<referenceBlock name="footer-content">
    <block
        name="footer.store.info"
        as="footer-store-info"
        template="Siteation_StoreInfo::hyva/store-address.phtml"
    />
</referenceBlock>
Luma - XML Sample
<referenceContainer name="footer">
    <block
        name="footer.store.info"
        as="footer-store-info"
        template="Siteation_StoreInfo::luma/store-address.phtml"
    >
        <arguments>
            <argument name="viewModelStoreInfo" 
                xsi:type="object">Siteation\StoreInfo\ViewModel\StoreInfo</argument>
        </arguments>
    </block>
</referenceContainer>

Get Store info in your own block.

First get the viewModal in your template.

Hyva - Sample Phtml file head
<?php declare(strict_types=1);

use Hyva\Theme\Model\ViewModelRegistry;
use Magento\Framework\View\Element\Template;
use Magento\Framework\Escaper;
use Siteation\StoreInfo\ViewModel\StoreInfo;

/** @var ViewModelRegistry $viewModels */
/** @var Template $block */
/** @var Escaper $escaper */

/** @var StoreInfo $storeInfo */
$storeInfo = $viewModels->require(StoreInfo::class);
Luma - Sample Phtml file head

For Luma templates, see the previous sample for the xml needed to load the viewModal.

<?php declare(strict_types=1);

use Magento\Framework\View\Element\Template;
use Magento\Framework\Escaper;

/** @var Template $block */
/** @var Escaper $escaper */

/** @var Siteation\StoreInfo\ViewModel\StoreInfo $storeInfo */
$storeInfo = $block->getData('viewModelStoreInfo');

After this you can load any Magento StoreInfo field as text in your phtml;

<?php
// Get specific predefined store info field
$storeInfo->getPostcode();
$storeInfo->getSalesEmail();

// Get the same as above, using the global functions
$storeInfo->getStoreInfo('postcode'); // 'general/store_information/%s'
$storeInfo->getStoreEmail('email', 'ident_sales'); // 'trans_email/%2$s/%1$s'