elbidouiller / sylius-terms-plugin
Sylius 条款和条件插件
Requires
- php: >=8.1
- behat/transliterator: ^1.3
- doctrine/collections: ^1.6
- doctrine/orm: ^2.7
- knplabs/knp-menu: ^3.1
- monsieurbiz/sylius-rich-editor-plugin: ^2.7
- sylius/resource-bundle: ^1.6
- symfony/config: ^4.4 || ^5.4 || ^6.0
- symfony/dependency-injection: ^4.4 || ^5.4 || ^6.0
- symfony/form: ^4.4 || ^5.4 || ^6.0
- symfony/http-foundation: ^4.4 || ^5.4 || ^6.0
- symfony/http-kernel: ^4.4 || ^5.4 || ^6.0
- symfony/options-resolver: ^4.4 || ^5.4 || ^6.0
- symfony/routing: ^4.4 || ^5.4 || ^6.0
- symfony/translation-contracts: ^1.1 || ^2.4
- thecodingmachine/safe: ^1.1
- twig/twig: ^2.14 || ^3.3
- webmozart/assert: ^1.9
Requires (Dev)
- phpspec/phpspec: ^7.1
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.16.1
- psalm/plugin-symfony: ^2.4
- setono/code-quality-pack: ^2.1.1
- sylius/sylius: ~1.10.14
- symfony/debug-bundle: ^5.1
- symfony/dotenv: ^5.1
- symfony/intl: ^4.4 || ^5.0
- symfony/proxy-manager-bridge: ^4.4.25
- symfony/web-profiler-bundle: ^5.0
This package is auto-updated.
Last update: 2024-09-04 10:17:50 UTC
README
在客户结账时添加检查条款和条件的必要要求
屏幕截图
商店
在客户可以下订单之前,他/她必须检查所需条款
管理员
这里是一份条款列表。请注意与多个渠道关联的 terms_and_conditions
。
说明
字段是在完整订单页面上显示的文本。请注意,您可以使用占位符([链接:链接文本]
)来指定链接的位置。
安装
步骤 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:覆盖结账完成表单
-
如果您还没有自己的
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 %}