Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BillingAddressValidationRule.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Magento\Framework\Validation\ValidationResultFactory;
12 
17 {
21  private $generalMessage;
22 
26  private $validationResultFactory;
27 
32  public function __construct(
33  ValidationResultFactory $validationResultFactory,
34  string $generalMessage = ''
35  ) {
36  $this->validationResultFactory = $validationResultFactory;
37  $this->generalMessage = $generalMessage;
38  }
39 
43  public function validate(Quote $quote): array
44  {
45  $validationErrors = [];
46  $billingAddress = $quote->getBillingAddress();
47  $billingAddress->setStoreId($quote->getStoreId());
48  $validationResult = $billingAddress->validate();
49  if ($validationResult !== true) {
50  $validationErrors = [__($this->generalMessage)];
51  }
52  if (is_array($validationResult)) {
53  $validationErrors = array_merge($validationErrors, $validationResult);
54  }
55 
56  return [$this->validationResultFactory->create(['errors' => $validationErrors])];
57  }
58 }
$billingAddress
Definition: order.php:25
$quote
__()
Definition: __.php:13
__construct(ValidationResultFactory $validationResultFactory, string $generalMessage='')