25 private $scopeConfiguration;
30 private $agreementsValidator;
35 private $checkoutAgreementsList;
40 private $activeStoreAgreementsFilter;
49 \
Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator,
51 \
Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface $checkoutAgreementsList,
54 $this->agreementsValidator = $agreementsValidator;
55 $this->scopeConfiguration = $scopeConfiguration;
56 $this->checkoutAgreementsList = $checkoutAgreementsList;
57 $this->activeStoreAgreementsFilter = $activeStoreAgreementsFilter;
71 \
Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject,
74 \
Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
77 if ($this->isAgreementEnabled()) {
78 $this->validateAgreements($paymentMethod);
93 \
Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject,
96 \
Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
99 if ($this->isAgreementEnabled()) {
100 $this->validateAgreements($paymentMethod);
109 private function validateAgreements(\
Magento\Quote\Api\Data\PaymentInterface $paymentMethod)
111 $agreements = $paymentMethod->getExtensionAttributes() ===
null 113 : $paymentMethod->getExtensionAttributes()->getAgreementIds();
115 if (!$this->agreementsValidator->isValid($agreements)) {
116 throw new \Magento\Framework\Exception\CouldNotSaveException(
118 "The order wasn't placed. " 119 .
"First, agree to the terms and conditions, then try placing your order again." 129 private function isAgreementEnabled()
131 $isAgreementsEnabled = $this->scopeConfiguration->isSetFlag(
135 $agreementsList = $isAgreementsEnabled
136 ? $this->checkoutAgreementsList->getList($this->activeStoreAgreementsFilter->buildSearchCriteria())
138 return (
bool)($isAgreementsEnabled && count($agreementsList) > 0);
__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\GuestPaymentInformationManagementInterface $subject, $cartId, $email, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress=null)
beforeSavePaymentInformation(\Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject, $cartId, $email, \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, \Magento\Quote\Api\Data\AddressInterface $billingAddress=null)