【问题标题】:Print invoice in Sales>Orders Magento 2在销售>订单 Magento 2 中打印发票
【发布时间】:2021-12-28 11:17:31
【问题描述】:
Error: Call to a member function getStoreId() on null in /Users/mac14/Sites/cleanlinesurf-upgrade/app/code/Fooman/PdfCustomiser/Block/AbstractSalesDocument.php:180

我在管理端的销售>订单中的操作下拉列表中打印发票时收到此错误。代码如下:

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

【问题讨论】:

    标签: magento magento2


    【解决方案1】:

    尝试注入

    Fooman_PdfCustomiser_Helper_Pdf $helper
    

    然后使用

    $helper->getStoreId()
    

    【讨论】:

      【解决方案2】:

      试试这个代码:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多