1

After using magento 2.4 updated from 2.3.5 about 2 weeks I noticed in some customer, which are subscribed in newsletters and have been sent from us 1 or more newsletter, when trying to edit in admin we get messed up page and error in logs:

[2020-09-20 19:55:13] report.CRITICAL: Error: Call to a member function getId() on null in /public_html/vendor/magento/module-customer/Block/Adminhtml/Edit/Tab/Newsletter/Grid/Renderer/Action.php:63
Stack trace:
#0 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Renderer\Action->render(Object(Magento\Newsletter\Model\Queue\Interceptor))
#1 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Renderer\Action\Interceptor->___callParent('render', Array)
#2 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Renderer\Action\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Newsletter\Model\Queue\Interceptor))
#3 /public_html/generated/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Newsletter/Grid/Renderer/Action/Interceptor.php(23): Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Renderer\Action\Interceptor->___callPlugins('render', Array, Array)
#4 /public_html/vendor/magento/module-backend/Block/Widget/Grid/Column.php(279): Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Renderer\Action\Interceptor->render(Object(Magento\Newsletter\Model\Queue\Interceptor))
#5 /public_html/var/view_preprocessed/pub/static/vendor/magento/module-backend/view/adminhtml/templates/widget/grid/extended.phtml(1): Magento\Backend\Block\Widget\Grid\Column->getRowField(Object(Magento\Newsletter\Model\Queue\Interceptor))
#6 /public_html/vendor/magento/framework/View/TemplateEngine/Php.php(71): include('/pu...')
#7 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Interceptor), '/pu...', Array)
#8 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callParent('render', Array)
#9 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\TemplateEngine\Php\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Interceptor), '/pu...', Array)
#10 /public_html/generated/code/Magento/Framework/View/TemplateEngine/Php/Interceptor.php(23): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callPlugins('render', Array, Array)
#11 /public_html/vendor/magento/framework/View/Element/Template.php(273): Magento\Framework\View\TemplateEngine\Php\Interceptor->render(Object(Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Interceptor), '/pu...', Array)
#12 /public_html/vendor/magento/framework/View/Element/Template.php(303): Magento\Framework\View\Element\Template->fetchView('/pu...')
#13 /public_html/vendor/magento/module-backend/Block/Template.php(141): Magento\Framework\View\Element\Template->_toHtml()
#14 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(1111): Magento\Backend\Block\Template->_toHtml()
#15 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(1115): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}()
#16 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(675): Magento\Framework\View\Element\AbstractBlock->_loadCache()
#17 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Element\AbstractBlock->toHtml()
#18 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Interceptor->___callParent('toHtml', Array)
#19 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Interceptor->Magento\Framework\Interception\{closure}()
#20 /public_html/generated/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Newsletter/Grid/Interceptor.php(32): Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Interceptor->___callPlugins('toHtml', Array, Array)
#21 /public_html/vendor/magento/framework/View/Layout.php(566): Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Interceptor->toHtml()
#22 /public_html/vendor/magento/framework/View/Layout.php(542): Magento\Framework\View\Layout->_renderBlock('newsletter.grid')
#23 /public_html/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement('newsletter.grid')
#24 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(522): Magento\Framework\View\Layout->renderElement('newsletter.grid', true)
#25 /public_html/var/view_preprocessed/pub/static/vendor/magento/module-customer/view/adminhtml/templates/tab/newsletter.phtml(1): Magento\Framework\View\Element\AbstractBlock->getChildHtml('grid')
#26 /public_html/vendor/magento/framework/View/TemplateEngine/Php.php(71): include('/pu...')
#27 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter), '/pu...', Array)
#28 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callParent('render', Array)
#29 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\View\TemplateEngine\Php\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter), '/pu...', Array)
#30 /public_html/generated/code/Magento/Framework/View/TemplateEngine/Php/Interceptor.php(23): Magento\Framework\View\TemplateEngine\Php\Interceptor->___callPlugins('render', Array, Array)
#31 /public_html/vendor/magento/framework/View/Element/Template.php(273): Magento\Framework\View\TemplateEngine\Php\Interceptor->render(Object(Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter), '/pu...', Array)
#32 /public_html/vendor/magento/framework/View/Element/Template.php(303): Magento\Framework\View\Element\Template->fetchView('/pu...')
#33 /public_html/vendor/magento/module-backend/Block/Template.php(141): Magento\Framework\View\Element\Template->_toHtml()
#34 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(1111): Magento\Backend\Block\Template->_toHtml()
#35 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(1115): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}()
#36 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(675): Magento\Framework\View\Element\AbstractBlock->_loadCache()
#37 /public_html/vendor/magento/module-ui/Component/Layout/Tabs.php(212): Magento\Framework\View\Element\AbstractBlock->toHtml()
#38 /public_html/vendor/magento/module-ui/Component/Layout/Tabs.php(88): Magento\Ui\Component\Layout\Tabs->addWrappedBlock(Object(Magento\Ui\Component\HtmlContent), Array)
#39 /public_html/vendor/magento/framework/View/Layout/Generic.php(74): Magento\Ui\Component\Layout\Tabs->addChildren(Array, Object(Magento\Ui\Component\Form), 'customer_form')
#40 /public_html/vendor/magento/module-ui/Component/Layout/Tabs.php(65): Magento\Framework\View\Layout\Generic->build(Object(Magento\Ui\Component\Form))
#41 /public_html/vendor/magento/framework/View/Layout/Generator/Structure.php(46): Magento\Ui\Component\Layout\Tabs->build(Object(Magento\Ui\Component\Form))
#42 /public_html/vendor/magento/module-ui/TemplateEngine/Xhtml/Result.php(102): Magento\Framework\View\Layout\Generator\Structure->generate(Object(Magento\Ui\Component\Form))
#43 /public_html/vendor/magento/module-ui/TemplateEngine/Xhtml/Result.php(124): Magento\Ui\TemplateEngine\Xhtml\Result->appendLayoutConfiguration()
#44 /public_html/vendor/magento/module-ui/Component/Wrapper/UiComponent.php(73): Magento\Ui\TemplateEngine\Xhtml\Result->__toString()
#45 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(1111): Magento\Ui\Component\Wrapper\UiComponent->_toHtml()
#46 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(1115): Magento\Framework\View\Element\AbstractBlock->Magento\Framework\View\Element\{closure}()
#47 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(675): Magento\Framework\View\Element\AbstractBlock->_loadCache()
#48 /public_html/vendor/magento/framework/View/Layout.php(579): Magento\Framework\View\Element\AbstractBlock->toHtml()
#49 /public_html/vendor/magento/framework/View/Layout.php(540): Magento\Framework\View\Layout->_renderUiComponent('customer_form')
#50 /public_html/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement('customer_form')
#51 /public_html/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement('customer_form', false)
#52 /public_html/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('content', false)
#53 /public_html/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement('content')
#54 /public_html/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement('content', false)
#55 /public_html/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('admin.scope.col...', false)
#56 /public_html/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement('admin.scope.col...')
#57 /public_html/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement('admin.scope.col...', false)
#58 /public_html/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('main.col', false)
#59 /public_html/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement('main.col')
#60 /public_html/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement('main.col', false)
#61 /public_html/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('page.main.conta...', false)
#62 /public_html/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement('page.main.conta...')
#63 /public_html/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement('page.main.conta...', false)
#64 /public_html/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('page.content', false)
#65 /public_html/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement('page.content')
#66 /public_html/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement('page.content', false)
#67 /public_html/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('page.wrapper', false)
#68 /public_html/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper')
#69 /public_html/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement('page.wrapper', false)
#70 /public_html/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('backend.page', false)
#71 /public_html/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement('backend.page')
#72 /public_html/vendor/magento/framework/View/Layout.php(594): Magento\Framework\View\Layout->renderElement('backend.page', false)
#73 /public_html/vendor/magento/framework/View/Layout.php(544): Magento\Framework\View\Layout->_renderContainer('root', false)
#74 /public_html/vendor/magento/framework/View/Layout.php(497): Magento\Framework\View\Layout->renderNonCachedElement('root')
#75 /public_html/vendor/magento/framework/View/Layout.php(963): Magento\Framework\View\Layout->renderElement('root')
#76 /public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(41): Magento\Framework\View\Layout->getOutput()
#77 /public_html/vendor/magento/framework/View/Result/Page.php(258): Magento\Framework\View\Layout\Interceptor->getOutput()
#78 /public_html/vendor/magento/framework/View/Result/Layout.php(171): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#79 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#80 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Backend\Model\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#81 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Backend\Model\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#82 /public_html/generated/code/Magento/Backend/Model/View/Result/Page/Interceptor.php(23): Magento\Backend\Model\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#83 /public_html/vendor/magento/framework/App/Http.php(120): Magento\Backend\Model\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#84 /public_html/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http->launch()
#85 /public_html/vendor/magento/framework/App/Bootstrap.php(263): Magento\Framework\App\Http\Interceptor->launch()
#86 /public_html/pub/index.php(40): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#87 {main} [] []

That file:

Action.php:63

has this code:

'subscriber' => $this->_coreRegistry->registry('subscriber')->getId()

And whole function is :

public function render(\Magento\Framework\DataObject $row)
{
    $actions = [];
    $actions[] = [
        '@' => [
            'href' => $this->getUrl(
                'newsletter/template/preview',
                [
                    'id' => $row->getTemplateId(),
                    'subscriber' => $this->_coreRegistry->registry('subscriber')->getId()
                ]
            ),
            'target' => '_blank',
        ],
        '#' => __('View'),
    ];
    return $this->_actionsToHtml($actions);
}

From what I understand it gets null instead of customer id in that query. But I checked in database and newsletter table have the right customer and subscriber id

For now I solved it by changing line 63 in Action.php

'subscriber' => 1

But I don't know if I created some other issue.

Any help please?

11
  • Any news on this? We're experiencing exactly the same issue. Oct 1, 2020 at 12:38
  • 1
    Use the fix I have in my question for now...It works
    – G. G.
    Oct 1, 2020 at 16:21
  • I have the same issue. Just to make sure it is not only an issue with my magento, i have installed a fresh copy of magento 2.4.1. I created a customer that is subscribed to newsletter, create a newsletter template and queued it. Then when i try to edit the customer, i get this. prnt.sc/v642qm As long as a customer is involved in any kind of newsletter, we are unable to edit this customer.
    – James Tsai
    Oct 26, 2020 at 0:52
  • 1
    I reported on GitHub and it should be fixed in the next release. github.com/magento/magento2/issues/30645#issuecomment-716339052
    – James Tsai
    Oct 26, 2020 at 12:14
  • Great. @JamesTsai do you know which files are changed so I can insert them to my instance?
    – G. G.
    Oct 26, 2020 at 12:21

1 Answer 1

1

Dears, I solved this Magento bug changing:

'subscriber' => $this->_coreRegistry->registry('subscriber')->getId()

to:

'subscriber' => $this->_coreRegistry->registry('current_customer_id')

I used the following plugin:

<?php
declare(strict_types=1);

namespace MyExtensions\MD2\Plugin\Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Renderer;

class Action
{

    
    public function __construct(
        
        \Magento\Framework\Registry $registry
        
    ) {
        $this->_coreRegistry = $registry;
        
        
    } 

    public function aroundRender(
        \Magento\Customer\Block\Adminhtml\Edit\Tab\Newsletter\Grid\Renderer\Action $subject,
        \Closure $proceed,
        $row
    ) {
        //Your plugin code
        $actions = [];

        $actions[] = [
            '@' => [
                'href' => $subject->getUrl(
                    'newsletter/template/preview',
                    [
                        'id' => $row->getTemplateId(),
                     //   'subscriber' => $this->_coreRegistry->registry('subscriber')->getId()
                        'subscriber' => $this->_coreRegistry->registry('current_customer_id')
                    ]
                ),
                'target' => '_blank',
            ],
            '#' => __('View'),
        ];

        return $this->_actionsToHtml($actions);


        $result = $proceed($row);
        return $result;
    }


    protected function _actionsToHtml(array $actions)
    {
        $html = [];
        $attributesObject = new \Magento\Framework\DataObject();
        foreach ($actions as $action) {
            $attributesObject->setData($action['@']);
            $html[] = '<a ' . $attributesObject->serialize() . '>' . $action['#'] . '</a>';
        }
        return implode('<span class="separator">&nbsp;|&nbsp;</span>', $html);
    }
}

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.