Skip to content

Get grand total by id using DI

After a long suffering, I found that I’ve to use DI instead of object manager.
However I’m trying to create block in custom module and call the method in success.phtml.
But I got the following error :
An error has happened during application run. See exception log for details.

My block file :

<?php
namespace NectarGoogleBlock;

private $_objectManager;

 public function __construct(MagentoFrameworkObjectManagerInterface $objectmanager)
   {
           $this->_objectManager = $objectmanager;
   }
   public function GrandTotal()
   {               
       $oid = $this->_objectManager->create('MagentoSalesModelOrder')->loadByIncrementId($block->getOrderId());
       return $order->getGrandTotal($oid);
   }

In success.phtml :

$block = $this->block(NectarGoogleBlockorder);
$total = $block->GrandTotal();

I feel that I mad a mistake but I don’t know where.. could you please help me.