1

Based on some quote details (e.g. products in the quote) I need to show or hide a certain Checkout Agreement. The same as described here, but for Magento 2: https://stackoverflow.com/questions/12567937/magento-have-terms-and-conditions-if-customer-buys-certain-products

I have not yet been able to find a solution for Magento 2.

I know how to get the quote details and determine if the agreement needs to be shown, but I do not know where to hook into the agreement loading to stop a particular agreement from being shown if my conditions are met.

Any ideas?

1 Answer 1

1

You can write plugins for the corresponding module functions where you can add/delete agreements as you wish. Just do not forget to also modify the validation of the required agreements.

<?php

namespace XXX\XXX\Plugin\Model;

class CheckoutAgreementsListPlugin
{
    public function __construct()
    {
    }

    public function afterGetList(\Magento\CheckoutAgreements\Model\CheckoutAgreementsList $subject, $result)
    {
        // modify shown agreements
        return $result;
    }

    public function afterGetRequiredAgreementIds(\Magento\CheckoutAgreements\Model\AgreementsProvider $subject, $result)
    {
        // modify required agreements
        return $result;
    }
}

Note: The subject of the plugin functions tell you which classes to override in di.xml.

<type name="Magento\CheckoutAgreements\Model\AgreementsValidator">
     <plugin sortOrder="1" name="XXXAgreementsValidator" type="xxx\xxx\Plugin\Model\CheckoutAgreementsListPlugin"/>
</type>
<type name="Magento\CheckoutAgreements\Model\AgreementsProvider">
        <plugin sortOrder="1" name="XXXAgreementsProvider" type="xxx\xxx\Plugin\Model\CheckoutAgreementsListPlugin"/>
</type>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.