Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Validation Class Reference

Public Member Functions

 __construct (\Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration, \Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface $checkoutAgreementsList, \Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter $activeStoreAgreementsFilter)
 
 beforeSavePaymentInformationAndPlaceOrder (\Magento\Checkout\Api\PaymentInformationManagementInterface $subject, $cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress=null)
 
 beforeSavePaymentInformation (\Magento\Checkout\Api\PaymentInformationManagementInterface $subject, $cartId, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress=null)
 

Protected Member Functions

 validateAgreements (\Magento\Quote\Api\Data\PaymentInterface $paymentMethod)
 
 isAgreementEnabled ()
 

Protected Attributes

 $scopeConfiguration
 
 $agreementsValidator
 

Detailed Description

Class Validation

Definition at line 16 of file Validation.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Checkout\Api\AgreementsValidatorInterface$agreementsValidator
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfiguration
\Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface$checkoutAgreementsList
ActiveStoreAgreementsFilter$activeStoreAgreementsFilter

Definition at line 44 of file Validation.php.

49  {
50  $this->agreementsValidator = $agreementsValidator;
51  $this->scopeConfiguration = $scopeConfiguration;
52  $this->checkoutAgreementsList = $checkoutAgreementsList;
53  $this->activeStoreAgreementsFilter = $activeStoreAgreementsFilter;
54  }

Member Function Documentation

◆ beforeSavePaymentInformation()

beforeSavePaymentInformation ( \Magento\Checkout\Api\PaymentInformationManagementInterface  $subject,
  $cartId,
\Magento\Quote\Api\Data\PaymentInterface  $paymentMethod,
\Magento\Quote\Api\Data\AddressInterface  $billingAddress = null 
)
Parameters
\Magento\Checkout\Api\PaymentInformationManagementInterface$subject
int$cartId
\Magento\Quote\Api\Data\PaymentInterface$paymentMethod
\Magento\Quote\Api\Data\AddressInterface | null$billingAddress
Exceptions

Definition at line 85 of file Validation.php.

90  {
91  if ($this->isAgreementEnabled()) {
92  $this->validateAgreements($paymentMethod);
93  }
94  }
validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod)
Definition: Validation.php:101

◆ beforeSavePaymentInformationAndPlaceOrder()

beforeSavePaymentInformationAndPlaceOrder ( \Magento\Checkout\Api\PaymentInformationManagementInterface  $subject,
  $cartId,
\Magento\Quote\Api\Data\PaymentInterface  $paymentMethod,
\Magento\Quote\Api\Data\AddressInterface  $billingAddress = null 
)
Parameters
\Magento\Checkout\Api\PaymentInformationManagementInterface$subject
int$cartId
\Magento\Quote\Api\Data\PaymentInterface$paymentMethod
\Magento\Quote\Api\Data\AddressInterface | null$billingAddress
Exceptions

Definition at line 65 of file Validation.php.

70  {
71  if ($this->isAgreementEnabled()) {
72  $this->validateAgreements($paymentMethod);
73  }
74  }
validateAgreements(\Magento\Quote\Api\Data\PaymentInterface $paymentMethod)
Definition: Validation.php:101

◆ isAgreementEnabled()

isAgreementEnabled ( )
protected

Verify if agreement validation needed

Returns
bool

Definition at line 121 of file Validation.php.

122  {
123  $isAgreementsEnabled = $this->scopeConfiguration->isSetFlag(
126  );
127  $agreementsList = $isAgreementsEnabled
128  ? $this->checkoutAgreementsList->getList($this->activeStoreAgreementsFilter->buildSearchCriteria())
129  : [];
130  return (bool)($isAgreementsEnabled && count($agreementsList) > 0);
131  }

◆ validateAgreements()

validateAgreements ( \Magento\Quote\Api\Data\PaymentInterface  $paymentMethod)
protected
Parameters
\Magento\Quote\Api\Data\PaymentInterface$paymentMethod
Exceptions

Definition at line 101 of file Validation.php.

102  {
103  $agreements = $paymentMethod->getExtensionAttributes() === null
104  ? []
105  : $paymentMethod->getExtensionAttributes()->getAgreementIds();
106 
107  if (!$this->agreementsValidator->isValid($agreements)) {
108  throw new \Magento\Framework\Exception\CouldNotSaveException(
109  __(
110  "The order wasn't placed. "
111  . "First, agree to the terms and conditions, then try placing your order again."
112  )
113  );
114  }
115  }
__()
Definition: __.php:13

Field Documentation

◆ $agreementsValidator

$agreementsValidator
protected

Definition at line 26 of file Validation.php.

◆ $scopeConfiguration

$scopeConfiguration
protected

Definition at line 21 of file Validation.php.


The documentation for this class was generated from the following file: