1

I am trying to recover the termes and conditions in my class but without success.

Here is my class :

class Bvr extends \Magento\Framework\Model\AbstractModel{

    public function __construct(
    \Magento\Framework\Filesystem $filesystem,
    \Magento\CheckoutAgreements\Model\Agreement $agreement,
    array $data = []

     ) {

    $this->_rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
    $this->agreement = $agreement;
    // parent::__construct($data);
    }

protected function printSlip($invoice, $order) {

    $referenceNumber = $invoice->getOrder()->getIsrReferenceNumber();
    $aCmsPage = $this->agreement->getContent();


 }

}

I get this error :

Fatal error: Call to a member function getContent() on null in /var/www/magento21-test2/app/code/acme/BVR/Model/PDF/Bvr.php

Is that you know the solution to recover the terms and conditions? Thank you

2 Answers 2

1

We need to declare the agreement variable. In the constructor, we inject the parent constructor classes.

class Bvr extends \Magento\Framework\Model\AbstractModel {

    /**
     * @var \Magento\Framework\Filesystem\Directory\ReadInterface
     */
    protected $_rootDirectory;
    /**
     * @var \Magento\CheckoutAgreements\Model\Agreement
     */
    protected $agreement;

    public function __construct(
       \Magento\Framework\Model\Context $context,
       \Magento\Framework\Registry $registry,
       \Magento\Framework\Filesystem $filesystem,
       \Magento\CheckoutAgreements\Model\Agreement $agreement,
       \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
       \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
       array $data = []
   )
   {
       $this->_rootDirectory = $filesystem->getDirectoryRead(DirectoryList::ROOT);
       $this->agreement = $agreement;
       parent::__construct($context, $registry, $resource, $resourceCollection, $data);
   }

    protected function printSlip($invoice, $order) {

        $referenceNumber = $invoice->getOrder()->getIsrReferenceNumber();
        $aCmsPage = $this->agreement->getContent();

    }

}
0

Yes, the synthax is correct but it don't works.

I tried that :

$aCmsPage = $this->agreement->getContent();
echo var_dump($aCmsPage);

But this returns me NULL I find nothing in the doc magento2. Thanks

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.