Home > Software design >  Print invoice in Sales>Orders Magento 2
Print invoice in Sales>Orders Magento 2

Time:01-03

Error: Call to a member function getStoreId() on null in /Users/mac14/Sites/cleanlinesurf-upgrade/app/code/Fooman/PdfCustomiser/Block/AbstractSalesDocument.php:180

I'm getting this error on print Invoice from Action dropdown in Sales>Orders on admin side. Here is the code:

$storeId = $this->getSalesObject()->getStoreId();
if ($storeId === null) {
   $store = $this->_storeManager->getDefaultStoreView();
   $storeId = $store->getId();
}
return $storeId;

CodePudding user response:

Try injecting

Fooman_PdfCustomiser_Helper_Pdf $helper

Then use

$helper->getStoreId()

CodePudding user response:

Try this code:

protected $_storeManager;    

    public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManager
    )
    {        
        $this->_storeManager = $storeManager;
    }
    public function getStoreId()
    {
        return $this->_storeManager->getStore()->getId();
    }
  • Related