3

I've got to make a shop based on sylius able to sell free products. In order to do so, I've followed the doc "Customizing Validation" and made thoses modifications :

#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

it result in nothing : in the symfony profiler, the sylius validation group is still appplied.

I can't figured out what I did bad.

please note that :

  • I tried to store the parameter into the service.yml file, it did change nothing.
  • I don't know how to find the name for the parameter, so I used a name similar to the ressource sylius.channel_pricing (see : bin/console sylius:debug:resource sylius.channel_pricing)
Bruno
  • 1,088
  • 1
  • 13
  • 31
  • I have no idea about Sylius but... What happens if you remove the `NotBlank` rule? – Álvaro González Mar 09 '17 at 09:42
  • Hello I just tried, it do change nothing : the validation group remain the one by default `sylius`. It's probably because I choose a bad parameter name, but I can't find out the good one... `sylius.form.type.channel_pricing.validation_groups` – Bruno Mar 10 '17 at 08:19

1 Answers1

2

I copy paste an answer from @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

Bruno
  • 1,088
  • 1
  • 13
  • 31
  • The default is that I have to activate this promotion in the admin panel in the installation procedure. – Bruno Mar 14 '17 at 12:56
  • I also had to overwrite many templates in order to replace the non promotional prices with a "free" mention. – Bruno Mar 16 '17 at 09:08