7

I have a custom module in which I am using the grid to add items in the admin end. The items are getting added properly and everything is working fine.

However, I face an issue often where after sometimes the product grid gives me error as

Fatal error: Uncaught Error: Call to a member function setItem() on boolean in /var/www/html/xxxxx/magento2/vendor/magento/module-sales/Block/Adminhtml/Order/Create/Items/Grid.php:591 Stack trace: #0 /var/www/html/quote2sales/magento2/app/code/Vendor/Module/view/adminhtml/templates/quote/create/items/grid.phtml(82): Magento\Sales\Block\Adminhtml\Order\Create\Items\Grid->getItemUnitPriceHtml(Object(Magento\Quote\Model\Quote\Item)) #1 /var/www/html/xxxxx/magento2/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/var/www/html/q...') #2 /var/www/html/xxxxx/magento2/vendor/magento/framework/View/Element/Template.php(255): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Sales\Block\Adminhtml\Order\Create\Items\Grid), '/var/www/html/q...', Array) #3 /var/www/html/xxxxx/magento2/vendor/magento/framework/View/Element/Template.php(279): Magento\Framework\View\Element\Template->fetchView('/var/www/html/q...') #4 /var/www/html/xxxxx/magento2/vendor/magento/module in /var/www/html/xxxxx/magento2/vendor/magento/module-sales/Block/Adminhtml/Order/Create/Items/Grid.php on line 591

Here I have created my own template and used the Magento sales module block

/var/www/html/xxxxx/magento2/vendor/magento/module-sales/Block/Adminhtml/Order/Create/Items/Grid.php

In my template for the product grid I have called below function,

<?php echo $block->getItemUnitPriceHtml($_item); ?>

The block function is as below,

/**
 * Get the item unit price html
 *
 * @param Item $item
 * @return string
 */
public function getItemUnitPriceHtml(Item $item)
{
    $block = $this->getLayout()->getBlock('item_unit_price');
    $block->setItem($item);
    return $block->toHtml();
}

Why would this happen?
The error goes when I am logging out and logging in again or clearing the session.

Please, can anyone help?

  • Is this anything related to session? – sreelakshmi Nov 14 '17 at 7:14
  • @sree Yes, It can be related to session as the error goes after clearing the session. – coderunner Nov 14 '17 at 8:18

Your Answer

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

Browse other questions tagged or ask your own question.