Question

I am currently trying to add Terms & Conditions to the customer registration. I thought the best would be just to update the layout.

So I simply extended customer_account_create.xml this in my theme:

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="form.additional.info">
            <block class="Magento\CheckoutAgreements\Block\Agreements" name="register_agreements"
                   template="Magento_CheckoutAgreements::additional_agreements.phtml" before="-"/>
        </referenceContainer>
    </body>
</page>

However it does not show up any check box.

Any idea why?

Thanks in Advance!

Was it helpful?

Solution

Change in following files:

/vendor/magento/module-customer/view/frontend/templates/form/register.phtml (Append below code)

<?php   
     if (!$block->getAgreements()) {
            return;
        }

        /** @var \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection $argeementsCollection */
        $argeementsCollection = $block->getAgreements();
        $agreementMappedArray = [];
        /** @var \Magento\CheckoutAgreements\Model\Agreement $agreement */
        foreach ($argeementsCollection as $agreement) {
            if ($agreement->getIsActive()) {
                $agreementMappedArray[] = [
                    'mode' => $agreement->getMode(),
                    'agreementId' => $agreement->getAgreementId(),
                    'checkboxText' => $agreement->getCheckboxText(),
                    'content' => $agreement->getContent()
                ];
            }
        }
        $agreementJson = json_encode($agreementMappedArray);
        ?>
        <div data-bind="scope: 'checkout-agreements-component-scope'" class="checkout-agreements-block">
        <!-- ko template: getTemplate() --><!-- /ko -->
        </div>

Add below script :

<script type="text/x-magento-init">
 {
"*": {
    "Magento_Ui/js/core/app": {
        "components": {
            "checkout-agreements-component-scope": {
                "component": 
 "Magento_CheckoutAgreements/js/view/checkout- 
  agreements",
                "agreements": <?php /* @noEscape */ echo 
   $agreementJson; ?>,
                "isVisible": true
            }
        }
    }
   }
 }
 </script>

Note : Override form/phtml file into your module, Don't change in core module directly.

And two links helpful for me :-

magento 2 - Terms and conditions checkbox on register page

https://ipfs-sec.stackexchange.cloudflare-ipfs.com/magento/A/question/151956.html

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top