0

I am trying to inject \Magento\Customer\Model\Session into the QuickOrder module. I want the page to show a different message when the user is not logged in.

In the directory app/code/Magento/QuickOrder/Block i made the class CheckLoggedIn.php:

<?php
namespace Magento\QuickOrder\Block;

use Magento\Widget\Block\BlockInterface;

class CheckLoggedIn implements BlockInterface
{
    protected $customerSession;

    public function __construct( \Magento\Customer\Model\Session $session)
    {
        $this->customerSession = $session;
    }

    public function isLoggedIn()
    {
        return $this->customerSession->isLoggedIn();
    }
}

and in vendor\magento\module-quick-order\view\frontend\templates\widget\sku.phtml , I added two lines of code:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php
/**
 * Order by SKU widget template
 *
 * @var $block \Magento\QuickOrder\Block\Sku
 */
?>

// I added these two lines:
<?php $block2= $block->getLayout()->createBlock('Magento\QuickOrder\Block\CheckLoggedIn'); ?>
<h1>test: <?php $block2->isLoggedIn();?></h1>

but now when I refresh the page, I get a blank page with an 500 (Internal Server Error). This is what I get in the debug.log:

report.INFO: Broken reference: the 'multiple-wishlist_sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []

What am I doing wrong? Am I trying to inject the module in a wong way?

thanks

UPDATE: The problem is the first line of the code. If I comment it, then I get the error undefined variable $block2. So the internal server error emerges from the frist line. And btw, the other pages work, only the corresponding url /quick-order is blank.

2
  • I bet you will find a php Fatal error in your web server logs. Look for it & paste it Sep 30 at 13:24
  • I do not see anything in /var/log files. All I see is the Broken reference thing that I mentioned above. Sep 30 at 13:31
0

Deploy static content and check your .htaccess files from root directory and pub/static..

2
  • what do you mean "check your .htaccess files from root directory and pub/static"? Sep 30 at 12:54
  • Of course I am deploying the static content each time Sep 30 at 12:56
0

Must be Error in code

Please do view source of page via ctrl+u and check Error will there in Red Color

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.