madcoders/setono-sylius-terms-plugin

Sylius服务条款插件

安装数: 2,555

依赖者: 0

建议者: 0

安全: 0

星级: 0

关注者: 0

分支: 11

类型:sylius-plugin


README

这是对Setono/SyliusTermsPlugin的分支

扩展功能

  • 可以启用/禁用每个条目
  • 可以决定在哪里显示条款:结账页面、客户注册表单、页脚(作为链接)
  • 位置字段以对条款进行排序(如果同一区域使用多个条款)
  • 升级开发环境到Sylius 1.10

与原始README相比,有2个额外的安装步骤

步骤7:覆盖客户注册表单

覆盖Sylius表单

  • 如果您还没有自己的templates/bundles/SyliusShopBundle/Register/_form.html.twig

    $ cp vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/views/Register/_form.html.twig \
    templates/bundles/SyliusShopBundle/Register/_form.html.twig
  • 如果您已经有了它

    添加条款字段(正好这种方式)

    {# templates/bundles/SyliusShopBundle/Register/_form.html.twig#}
    {% if form.terms is defined %}
        {% form_theme form.terms '@SetonoSyliusTermsPlugin/Shop/Form/termsTheme.html.twig' %}
        {{ form_row(form.terms) }}
    {% endif %}

    所以最终模板将看起来像这样

    {# templates/bundles/SyliusShopBundle/Register/_form.html.twig#}
    <h4 class="ui dividing header">{{ 'sylius.ui.personal_information'|trans }}</h4>
    <div class="two fields">
        {{ form_row(form.firstName, sylius_test_form_attribute('first-name')) }}
        {{ form_row(form.lastName, sylius_test_form_attribute('last-name')) }}
    </div>
    {{ form_row(form.email, sylius_test_form_attribute('email')) }}
    {{ form_row(form.phoneNumber, sylius_test_form_attribute('phone-number')) }}
    {{ form_row(form.subscribedToNewsletter, sylius_test_form_attribute('subscribed-to-newsletter')) }}
    <h4 class="ui dividing header">{{ 'sylius.ui.account_credentials'|trans }}</h4>
    {{ form_row(form.user.plainPassword.first, sylius_test_form_attribute('password-first')) }}
    {{ form_row(form.user.plainPassword.second, sylius_test_form_attribute('password-second')) }}
    {% if form.terms is defined %}
        {% form_theme form.terms '@SetonoSyliusTermsPlugin/Shop/Form/termsTheme.html.twig' %}
        {{ form_row(form.terms) }}
    {% endif %}

步骤8:覆盖页脚块

覆盖Sylius模板块

  • 如果您还没有自己的templates/bundles/SyliusShopBundle/Layout/Footer/Grid/_your_store.html.twig

    $ cp vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/views/Layout/Footer/Grid/_your_store.html.twig \
    templates/bundles/SyliusShopBundle/Layout/Footer/Grid/_your_store.html.twig
  • 如果您已经有了它

    添加条款字段(正好这种方式)

    {# templates/bundles/SyliusShopBundle/Layout/Footer/Grid/_your_store.html.twig #}
    {% set terms = footer_terms_view() %}
    {% if terms is defined and terms is not null %}
        {% for term in terms %}
            {{ footer_term_link(term, sylius.localeCode) }}
        {% endfor %} 
    {% endif %}

    所以最终模板将看起来像这样

    {# templates/bundles/SyliusShopBundle/Layout/Footer/Grid/_your_store.html.twig #}
    <div class="four wide column">
        <h4 class="ui inverted header">{{ 'sylius.ui.your_store'|trans }}</h4>
        <div class="ui inverted link list">
            <a href="#" class="item">{{ 'sylius.ui.about'|trans }}</a>
            {% set terms = footer_terms_view() %}
            {% if terms is defined and terms is not null %}
                {% for term in terms %}
                    {{ footer_term_link(term, sylius.localeCode) }}
                {% endfor %}
            {% endif %}
            <a href="{{ path('sylius_shop_contact_request') }}" class="item">{{ 'sylius.ui.contact_us'|trans }}</a>
        </div>
    </div>

有一个开放的pull request,它详细总结了更改:Setono#48

------- 原始插件的README从这里开始 --------

将在客户结账时添加检查条款和条件的必填要求

屏幕截图

商店

在客户可以下订单之前,他/她必须检查所需的条款

Screenshot showing shop checkout complete page

管理员

这里是一份条款列表。注意terms_and_conditions与多个渠道相关联。

Screenshot showing admin terms index page

Screenshot showing admin terms update page

说明字段是在完整订单页面上显示的文本。注意您可以使用占位符([链接:链接文本])来指示链接的位置。

Screenshot showing admin terms translation update page

安装

步骤1:下载插件

打开命令行,进入您的项目目录,并执行以下命令以下载此插件的最新稳定版本

$ composer require setono/sylius-terms-plugin

此命令要求您全局安装Composer,如Composer文档的安装章节中所述。

步骤2:启用插件

然后,通过将其添加到项目config/bundles.php文件中注册的插件/捆绑包列表来启用插件

<?php
# config/bundles.php
return [
    // ...
    
    Setono\SyliusTermsPlugin\SetonoSyliusTermsPlugin::class => ['all' => true],
    
    // It is important to add plugin before the grid bundle
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
    
    // ...
];

注意您必须在网格捆绑包之前实例化插件,否则您将看到如您请求的参数“setono_sylius_terms.model.terms.class”不存在。这样的异常。

步骤3:导入配置

# config/packages/_sylius.yaml
imports:
    # ...
    
    - { resource: "@SetonoSyliusTermsPlugin/Resources/config/app/config.yaml" }
    
    # ...

步骤4:导入路由

# config/routes/setono_sylius_terms.yaml

setono_sylius_terms_shop:
    resource: "@SetonoSyliusTermsPlugin/Resources/config/shop_routing.yaml"
    prefix: /{_locale}
    requirements:
        _locale: ^[a-z]{2}(?:_[A-Z]{2})?$

setono_sylius_terms_admin:
    resource: "@SetonoSyliusTermsPlugin/Resources/config/admin_routing.yaml"
    prefix: /admin

步骤5:更新您的数据库模式

$ php bin/console doctrine:migrations:diff
$ php bin/console doctrine:migrations:migrate

步骤6:覆盖结账完成表单

覆盖Sylius表单

  • 如果您还没有自己的templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig

    $ cp vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/views/Checkout/Complete/_form.html.twig \
    templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig
  • 如果您已经有了它

    添加条款字段(正好这种方式)

    {# templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig #}
    {% if form.terms is defined %}
        {% form_theme form.terms '@SetonoSyliusTermsPlugin/Shop/Form/termsTheme.html.twig' %}
        {{ form_row(form.terms) }}
    {% endif %}

    所以最终模板将看起来像这样

    {# templates/bundles/SyliusShopBundle/Checkout/Complete/_form.html.twig #}
    {{ form_row(form.notes, {'attr': {'rows': 3}}) }}
    {% if form.terms is defined %}
        {% form_theme form.terms '@SetonoSyliusTermsPlugin/Shop/Form/termsTheme.html.twig' %}
        {{ form_row(form.terms) }}
    {% endif %}

故障排除

  • 如果您看到在类“Symfony\Component\Form\FormView”中既不存在属性“terms”,也不存在方法“terms()”、“getterms()”/“isterms()”或“hasterms()”或“__call()”,并且具有公共访问权限。

    请参阅Setono#13并再次检查您是否像在覆盖结账完成表单部分中描述的那样在模板中添加了条款字段。

  • 如果您看到网格“setono_sylius_terms_terms”不存在

    那么您忘记在步骤3:导入配置部分中导入配置。

  • 如果在您的js控制台中看到 Uncaught ReferenceError: $ is not defined

    这意味着 jQuery 被加载在了插件javascript代码之后。插件的javascript代码是通过 sylius.shop.layout.javascripts Sonata块注入到主模板中的。因此,请检查您的自定义 templates/bundles/SyliusShopBundle/layout.html.twig 中的 javascript 块,它应该像这样

    {# layout.html.twig #}
    
    {% block javascripts %}
        // We expect jquery to be loaded here
        {% include '@SyliusUi/_javascripts.html.twig' with {'path': 'assets/shop/js/app.js'} %}
    
        // But if you have it as separate script - just make sure
        // it placed before `sylius.shop.layout.javascripts` sonata block
    
        {{ sonata_block_render_event('sylius.shop.layout.javascripts') }}
    {% endblock %}