Source of file CheckoutComponentValidator.php
Size: 1,691 Bytes - Last Modified: 2021-12-23T10:24:58+00:00
/var/www/docs.ssmods.com/process/src/src/Forms/CheckoutComponentValidator.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 | <?php namespace SilverShop\Forms; use SilverShop\Checkout\CheckoutComponentConfig; use SilverStripe\Forms\RequiredFields; use SilverStripe\ORM\ValidationException; /** * Order validator makes sure everything is set correctly * and in place before an order can be placed. */ class CheckoutComponentValidator extends RequiredFields { protected $config; public function __construct(CheckoutComponentConfig $config) { $this->config = $config; parent::__construct($this->config->getRequiredFields()); } public function php($data) { $valid = parent::php($data); //do component validation try { $this->config->validateData($data); } catch (ValidationException $e) { $result = $e->getResult(); foreach ($result->getMessages() as $message) { if (!$this->fieldHasError($message['fieldName'])) { $this->validationError($message['fieldName'], $message['message'], 'bad'); } } $valid = false; } if (!$valid) { $this->form->sessionMessage( _t( __CLASS__ . ".InvalidDataMessage", "There are problems with the data you entered. See below:" ), "bad" ); } return $valid; } public function fieldHasError($field) { if ($this->getErrors()) { foreach ($this->getErrors() as $error) { if ($error['fieldName'] === $field) { return true; } } } return false; } } |