0

I need to change the Terms and Conditions HTML. The client wants to add HTML in the middle of the text. For that I need to change the getAgreementsConfig function (Magento\CheckoutAgreements\Model\AgreementsConfigProvider).

I build a plugin to change the result of this function. I worked on this for the last 2 days, and no result until now. I don't know what else to do. My code is: My di.xml file is:

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Magento\CheckoutAgreements\Model\AgreementsConfigProvider">
      <plugin name="agreementsHtmlText" type="VendorName\CheckoutAgreements\Model\Plugin\AgreementPlugin" sortOrder="10" disabled="false"/>
    </type>
</config>

And my Plugin is (VendorName\CheckoutAgreements\Model\Plugin\AgreementPlugin):

<?php

namespace VenderName\CheckoutAgreements\Model\Plugin;

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Store\Model\ScopeInterface;
use Magento\CheckoutAgreements\Model\Api\SearchCriteria\ActiveStoreAgreementsFilter;

class AgreementPlugin
{

    public function afterGetAgreementsConfig(\Magento\CheckoutAgreements\Model\AgreementsConfigProvider $subject, $result){

        foreach ($result['agreements'] as $key => $value) {
            $result[$key]['checkboxText'] ='ahahahhah'; // test if result changes
        }


        return 'qiweoqiwueioqwiueioquw'; //just to test if it changes the resukt
    }
}

I tried and change almost everything, and until now, no luck. Can anyone help me?

Thank you

1
  • It will not work because the method getAgreementsConfig is a protected method. Plugins only work on public methods. Commented Mar 4, 2020 at 3:57

1 Answer 1

1

You can try to plug in to the public function of this class:

public function getConfig()
{
    $agreements = [];
    $agreements['checkoutAgreements'] = $this->getAgreementsConfig();

    return $agreements;
}

Therefore, "afterGetConfig" should be working.

Edit:

What you probably want to do is allow links again in the "checkboxText". This will not work with a simple plugin, since you need to access some protected variable of the class to get the data before rendering the agreements array. Instead override the class with a preference:

class CustomAgreementsConfigProvider extends AgreementsConfigProvider 
   implements ConfigProviderInterface
{
  protected function getAgreementsConfig()
  {
    $agreementConfiguration = [];
    $isAgreementsEnabled = $this->scopeConfiguration->isSetFlag(
        AgreementsProvider::PATH_ENABLED,
        ScopeInterface::SCOPE_STORE
    );

    $agreementsList = $this->checkoutAgreementsRepository->getList();
    $agreementConfiguration['isEnabled'] = (bool) ($isAgreementsEnabled && count($agreementsList) > 0);

    foreach ($agreementsList as $agreement) {
        $agreementConfiguration['agreements'][] = [
            'content' => $agreement->getIsHtml()
                ? $agreement->getContent()
                : nl2br($this->escaper->escapeHtml($agreement->getContent())),
            'checkboxText' => $agreement->getCheckboxText(), // TODO: this is usually escaped
            'mode' => $agreement->getMode(),
            'agreementId' => $agreement->getAgreementId()
        ];
    }

    return $agreementConfiguration;
}

}

Your Answer

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

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