Question

I've made a custom module, with the ability to print the terms and conditions on a static page. I've achieved this by posting a question on Stack, which answer worked for me: Show terms and conditions on static page

(I've followed to above exactly)

Now, I've created the module with the intention to be reused in other instances of Magento 2(.2.3). So, I've installed the module on a clean installation of Magento 2:

  • Enabled developer mode
  • Created corresponding vendor folder
  • Uploaded the module to the vendor folder
  • ran php bin/magento setup:upgrade
  • ran php bin/magento setup:di:compile
  • created terms and conditions
  • enabled the function in the backend (I created a Helper for this)
  • ran php bin/magento cache:flush
  • Browsed to http://www.mywebshop.com/termsconditions

The /termsconditions url loads correctly, so this means the module is working. But somehow, the code which gets the agreement content, returns empty?

This all may sound like a stupid question, but as far as I know, there shouldn't be going something wrong.

var_dump of $block->getAgreements() returns

array (size=0)
  empty

Whilst I have created terms and conditions via the admin menu and which show up correctly.

Also the terms and conditions show up in the DB.

Someone who knows what I might have forgotten or what is going wrong?

The code in .phtml

<?php
/**
 * @var $block \Magento\CheckoutAgreements\Block\Agreements
 */
?>

<ol class="agreements items">
    <?php var_dump($block->getAgreements()) ?>
    <?php foreach ($block->getAgreements() as $agreement): ?>
        <li class="item">
            <?php if ($agreement->getIsHtml()):?>
                <?php /* @escapeNotVerified */ echo $agreement->getContent() ?>
            <?php else:?>
                <?php echo nl2br($block->escapeHtml($agreement->getContent())) ?>
            <?php endif; ?>
        </li>
    <?php endforeach ?>
</ol>

Layout file:

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <title>Terms and Conditions</title>
    </head>
    <body>
        <referenceBlock name="page.main.title" remove="true" />
        <referenceContainer name="content">
            <block class="Magento\CheckoutAgreements\Block\Agreements" name="terms_conditions"  template="Vendor_TCRender::terms.phtml"/>
        </referenceContainer>

    </body>
</page>
Was it helpful?

Solution

I think Enable Terms and Conditions option is "No" in your webshop. make sure that it is enabled from Store > Configuration > Checkout > Checkout Options > Enable Terms and Conditions

After saving configuration clear the cache php bin/magento c:f

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