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 Answers 2
Deploy static content and check your .htaccess files from root directory and pub/static..
- 
 what do you mean "check your .htaccess files from root directory and pub/static"?Payman Khayree– Payman Khayree2021年09月30日 12:54:34 +00:00Commented Sep 30, 2021 at 12:54
- 
 Of course I am deploying the static content each timePayman Khayree– Payman Khayree2021年09月30日 12:56:47 +00:00Commented Sep 30, 2021 at 12:56
Must be Error in code
Please do view source of page via ctrl+u and check Error will there in Red Color
/var/logfiles. All I see is theBroken referencething that I mentioned above.