mirror of
https://github.com/bdnugget/magento2.git
synced 2026-11-07 09:17:35 +00:00
75 lines
1.8 KiB
PHP
75 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* Copyright © Magento, Inc. All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Magento\Quote\Model;
|
|
|
|
use Magento\Framework\Exception\LocalizedException;
|
|
use Magento\Framework\Validator\Exception as ValidatorException;
|
|
use Magento\Sales\Model\Order;
|
|
use Magento\Sales\Model\Order\Address\Validator as OrderAddressValidator;
|
|
|
|
/**
|
|
* Validates quote and order before quote submit.
|
|
*/
|
|
class SubmitQuoteValidator
|
|
{
|
|
/**
|
|
* @var QuoteValidator
|
|
*/
|
|
private $quoteValidator;
|
|
|
|
/**
|
|
* @var OrderAddressValidator
|
|
*/
|
|
private $orderAddressValidator;
|
|
|
|
/**
|
|
* @param QuoteValidator $quoteValidator
|
|
* @param OrderAddressValidator $orderAddressValidator
|
|
*/
|
|
public function __construct(
|
|
QuoteValidator $quoteValidator,
|
|
OrderAddressValidator $orderAddressValidator
|
|
) {
|
|
$this->quoteValidator = $quoteValidator;
|
|
$this->orderAddressValidator = $orderAddressValidator;
|
|
}
|
|
|
|
/**
|
|
* Validates quote.
|
|
*
|
|
* @param Quote $quote
|
|
* @return void
|
|
* @throws ValidatorException
|
|
* @throws LocalizedException
|
|
*/
|
|
public function validateQuote(Quote $quote): void
|
|
{
|
|
$this->quoteValidator->validateBeforeSubmit($quote);
|
|
}
|
|
|
|
/**
|
|
* Validates order.
|
|
*
|
|
* @param Order $order
|
|
* @return void
|
|
* @throws ValidatorException
|
|
* @throws LocalizedException
|
|
*/
|
|
public function validateOrder(Order $order): void
|
|
{
|
|
foreach ($order->getAddresses() as $address) {
|
|
$errors = $this->orderAddressValidator->validate($address);
|
|
if (!empty($errors)) {
|
|
throw new ValidatorException(
|
|
__("Failed address validation:\n%1", implode("\n", $errors))
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|