How can i get the order total value on success page easily? Magento 2.2
-
27-02-2021 - |
سؤال
I am trying to get the order value from success.phtml page so that I can report it back in the facebook pixel.
I am just looking for the simplest way to get the order value. Yes, a shortcut pretty much.
I tried this:
$orderTotal = round($block->getGrandTotal(), 2);
and also
$lastOrderId = $block->getOrderId();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->load($lastOrderId);
echo "order id: ". $lastOrderId;
echo $order->getGrandTotal();
and several other methods but the total order value seems to be hard to find.
المحلول
After doing even more tests I finally gave up and went oldschool and just simply created a new connection to the database and queried the sales_order
table.
This is not the correct way to solve it. But I think there is a plugin or the template that is messing up my environment so in case exactly evertything else fails then I guess you can use this for a breif time.
$lastOrderId = $block->getOrderId();
$SQL = mysqli_connect('localhost', 'username', 'password', 'databasename', '8889');
$q = "select * from `sales_order` WHERE increment_id={$lastOrderId}";
$rs = $SQL->query($q);
$order_tmp = $rs->fetch_object();
$grand_total = $order_tmp->grand_total;
لا تنتمي إلى magento.stackexchange