semexpert/module-store-info-blocks

允许开发者在他们的主题中包含具有访问商店配置(如地址、电话号码等)功能的 Magento 块。

安装次数: 3,165

依赖关系: 0

建议者: 0

安全: 0

星标: 0

关注者: 14

分支: 0

公开问题: 0

类型:magento2-module

1.0.4 2021-07-16 03:12 UTC

This package is auto-updated.

Last update: 2024-09-16 10:12:28 UTC


README

SemExpert_StoreInfoBlocks 允许开发者在他们的主题中包含具有访问商店配置(如地址、电话号码等)功能的 Magento 块。

Build Status

入门指南

要开始使用,您只需将模块添加到现有的 Magento2 安装中。

先决条件

您需要一个运行的 Magento2 版本

此外,为了使 composer 能够找到模块仓库,您需要设置 SemExpert 仓库

composer config repositories.semexpert composer https://packages.semexpert.com.ar/

安装

要使 StoreInfoBlocks 正常运行,您需要将其添加到您的 Magento composer.json 文件中的依赖项

composer require semexpert/module-store-info-blocks

或者手动将其添加到您的 composer.json 文件中

{
  "require": {
    "semexpert/module-store-info-blocks": "*"
  }
}

安装后,您需要通过 Magento CLI 启用它

php bin/magento module:enable SemExpert_StoreInfoBlocks

运行测试

此模块仅提供单元测试,可以通过标准方式将其挂钩到 Magento 测试套件中

php bin/magento dev:tests:run unit

要单独运行此模块的测试,您可以使用提供的 dev/phpunit.xml 配置文件。

vendor/bin/phpunit -c vendor/semexpert/moodule-store-info-blocks/dev/phpunit.xml

到目前为止,我没有发现需要集成或功能测试。而且我也不确定如何编写这些测试。

编码风格

该模块遵循 Magento 2.2 PHP 和 Less 编码标准。您应该使用提供的黑白名单和 phpunit.xml 配置来测试您的代码。

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

Magento 2

组件

该模块提供了两种类型的块

  • SemExpert\StoreInfoBlocks\Block\Template 提供了一个带有访问商店配置信息的标准模板块
  • SemExpert\StoreInfoBlocks\Block\Value 允许输出一个未经格式化的单个配置值。需要通过布局 xml 进行一些设置

这些块可用于您的自定义主题,但不会自动包含在任何网站上。

用法

模板

通过在布局中调用模板块,将使用提供的 storeinfo.phtml 模板,该模板仅作为示例提供

<?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>

或者您也可以提供自己的模板。在模板中,您可以通过调用 $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>

可用的数据键包括

  • name
  • phone
  • hours
  • street_line1
  • street_line2
  • city
  • postcode
  • region_id
  • region
  • country_id
  • country
  • vat_number

您可以通过布局 XML 设置值块以检索单个未经格式化的值

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>  

请参阅模板块的描述以获取 key 参数的可接受值列表。

版本控制

我们使用 SemVer 进行版本控制。要查看可用的版本,请查看此存储库的 标签

作者

  • Matías Montes - 初始工作 - barbazul

还可以查看参与此项目的 贡献者列表

许可证

本项目采用MIT许可协议 - 请参阅LICENSE.md文件获取详细信息

致谢