0

I want to make a craft commerce custom order field required (server side). I already use this for require the default address fields. But how to add custom fields? Because this is done on the Address class.

        /**
         * Server require custom order fields
         */
        Event::on(
          Address::class,
          Model::EVENT_DEFINE_RULES,
          function(DefineRulesEvent $event) {
              $rules = $event->rules;
              $rules[] = [['firstName', 'lastName'], 'required'];
              $rules[] = ['field:fieldHandle', 'required']; // <- this is not working
              $event->rules = $rules;
          }
        );
3
  • I'm surprised that the update cart method in Commerce doesn't seem to respect the required lightswitch of an order field. This seems like a bug to me - I don't think you should have to use a custom module to do it. Jan 25 at 12:09
  • But is it possible with some kind of event? I tried making the field required but that's not working. I also think this should work but because it doesn't I'm looking for an alternative also because I work with a onepagecheckout with ajax calls Jan 26 at 14:09
  • I'm not sure, but I'd probably raise this as a bug report with Craft Commerce, as it doesn't seem right that you are able to mark an order field as "required" but that choice is not respected. Jan 26 at 14:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.