Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Insert Variable' functionality in templares does not work (Exception, call on null) #105

Open
Emanuel-23 opened this issue Aug 12, 2020 · 4 comments

Comments

@Emanuel-23
Copy link

In Magento 2.3.5 and Magento 2.4 as well, i can not make the variables to work.

When you try to create or edit a PDF template and press the 'insert variable' button an error occures:

Error: Call to a member function getId() on null in /app/web/vendor/magento/module-email/Block/Adminhtml/Template/Edit.php:295
...

I managed to find the potential cause for this, in Line 134-136 of /Controller/Adminhtml/Variable/Template.php
bute evene if i changed it to something like this (as copied from module-email), its not fixed (but then you even will get json response...)

$templateBlock = $this->_view->getLayout()->createBlock(
                \Magento\Email\Block\Adminhtml\Template\Edit::class,
                'template_id',
                [
                    'data' => [
                        'email_template' => $template
                    ]
                ]
            );

I assume that there have to be made several changes in order to make it compatible to the code of module-email.
Actually there are many parts of the code which seem to be deprecated, so this might not be the only problem. Hard to say at this point... But might be a starting point for someone that had the same issue.

@Emanuel-23 Emanuel-23 changed the title Variables dont work 'Insert Variable' functionality in templares does not work (Exception, call on null) Aug 12, 2020
@udovicic
Copy link

I can confirm that this is an issue on 2.3.5 and later

@chequille
Copy link

chequille commented Dec 8, 2020

Hi, everybody,
facing similar problem within 2.4.1
I am using layout definitions in the template like
{{layout area="frontend" handle="jscdesign_shipment_date" shipment=$shipment order=$order}}
But it generates as well the errors Call to member function on null

DId some body find a solution already?
Regards,
Chequille

Additional info:
The above layout handle is calling a template but shipment and order data is not available there and therefore causes the error.
In the template $shipment could be called with $shipment = $block->getShipment()
Unfortunately not working anymore. It worked in 2.3.5 very good and stable.

@amelojunior
Copy link

amelojunior commented Feb 2, 2021

the problem is here:

Pdfgenerator/Model/Template/Processor.php::processTemplate()

Setting setStrictMode to 0 fix this bug.

$processor->setStrictMode(0);

@rudracomputech
Copy link

rudracomputech commented Jun 29, 2021

I am using Magento version 2.3.5-p1 and also having same error.
Fatal error: Uncaught Error: Call to a member function getId() on null
And cant get variables value on pdf, Please help to solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants