elbidouiller/sylius-terms-plugin

Sylius 条款和条件插件

安装: 162

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 11

类型:sylius-plugin

v1.1 2024-09-04 10:16 UTC

This package is auto-updated.

Last update: 2024-09-04 10:17:50 UTC


README

Latest Version Latest Unstable Version Software License Build Status Code Coverage

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

屏幕截图

商店

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

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 控制台中看到 未捕获的引用错误: $ 未定义

    这意味着 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 %}