How to get which terms and conditions has been accepted by a customer?

Hi,

How to get from Customer or Order object which terms and conditions has been accepted by user?

I mean those:

when you click on submit order it will pass into extension_attribute parameter:

{“cartId”:“186”,“paymentMethod”:{“method”:“checkmo”,“extension_attributes”:{“agreement_ids”:[""]}},“billingAddress”:{“customerAddressId”:10,“email”:null,“countryId”:“US”,“regionId”:62,“regionCode”:“WA”,“region”:“Washington”,“customerId”:18,“street”:[“900 Winslow Way E”,“900 Winslow Way E”],“company”:“test”,“telephone”:“999999999999”,“postcode”:“98110-2450”,“city”:“Bainbridge Island”,“firstname”:“testf”,“lastname”:“testl”,“saveInAddressBook”:false}}

By using below code you will get:
$paymentMethod->getExtensionAttributes()->getAgreementIds()

1 Like

Thanks,

Are you sure that this is getting Terms and Conditions displayed in checkout according to screen I’ve pasted?

Yes

Please check below class for same:
Magento\CheckoutAgreements\Model\Checkout\Plugin\Validation

you can do like you can create plugin using di.xml

>   <type name="Magento\Checkout\Api\PaymentInformationManagementInterface">
>         <plugin name="agreementsids" type="Test\Test\Model\Checkout\Plugin\Test"/>
>     </type>

public function beforeSavePaymentInformationAndPlaceOrder(
\Magento\Checkout\Api\PaymentInformationManagementInterface $subject,
$cartId,
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
\Magento\Quote\Api\Data\AddressInterface $billingAddress
) {
$ids=$paymentMethod->getExtensionAttributes()->getAgreementIds();
// write your stuff here to save info
}

Ok, will try.

The next thing – where is placed information about that these fields are all required? I mean backend validation.

We have to make part of terms required and part – non-required.

Thanks in advance,

Magento\CheckoutAgreements\Model\Checkout\Plugin\Validation.php

I have also problem with creating account after order.
I added some terms & conditions and when i try to create account after order i get error validation message that these fields are required.
How can i workaround it or make this data always filled on create account after order?

Hello,

Have you did any customization for terms & conditions? because by default Magento 2 provide only for checkout page.

sorry I mean I added some required EAV attributes on customer register form, and i get validation error on create account after order.

Awesome “extension_attributes”:{“agreement_ids”:[“1”]} solved issue of “Please agree to all the terms and conditions before placing the order.”