我必须在 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/