php - 如何自定义 Sylius 以销售免费产品(默认最低价格为 0.01)

标签 php validation doctrine-orm symfony sylius

我必须在 sylius 的基础上开一家能够销售免费产品的商店。 为此,我按照文档“Customizing Validation”进行了修改:

#AppBundle/Resources/config/validation.yml
Sylius\Component\Core\Model\ChannelPricing:
    # see http://docs.sylius.org/en/latest/customization/validation.html
    #the original constraint said that the minimum price is 0.01 in vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/Resources/config/validation/ChannelPricing.xml
    properties:
        price:
            - NotBlank:
                message: sylius.channel_pricing.price.not_blank
                groups: [app_product]
            - Range:
                min: 0
                minMessage: app.channel_pricing.price.min
                groups: [app_product]

#app/config/parameters.yml
parameters:
    sylius.form.type.channel_pricing.validation_groups: [app_product] # see http://docs.sylius.org/en/latest/customization/validation.html

它没有结果:在 symfony 分析器中,sylius 验证组仍然被应用。

我想不通我做错了什么。

请注意:

  • 我尝试将参数存储到 service.yml 文件中,但它没有任何改变。
  • 我不知道如何找到参数的名称,所以我使用了类似于资源 sylius.channel_pricing 的名称(参见:bin/console sylius:debug:resource sylius.channel_pricing)

最佳答案

我复制粘贴@pjedrzejewski 的回答:

Perhaps you should use a promotion to apply proper discount and get the order total to 0? Then Sylius should handle it just fine. I am not sure we should allow setting price 0, it can lead to terrible mistakes

关于php - 如何自定义 Sylius 以销售免费产品(默认最低价格为 0.01),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42690246/

相关文章:

javascript - 根据 Laravel 中未定义的父 ID 获取 ajax 下拉列表

php - 使用bean抓取sugarcrm中的完整表记录

java - 采用 JSR 303 Bean 验证

symfony - 学说 : Pagination with left Joins

php - 在 symfony 实体中获取和设置下划线

php - 教义查询生成器 : having/where error using alias

php - MySQL 不会更新表中最后一行的最后一个单元格

php - 更新数据库数据失败

c# - 验证器和 ClientIDMode 问题 (ASP.NET)

c# - 范围验证属性未验证