I’ve created a custom module to get order data to be used into tracking code in success page.
I got all data phone, total country .. etc except the street and city !
I don’t know what’s the problem, below my model code :
<?php declare(strict_types=1);
namespace NectarGoogleBlock;
use MagentoCheckoutModelSession;
use MagentoFrameworkViewElementTemplate;
class Success extends Template
{
/** @var Session */
private $checkoutSession;
/**
* @param TemplateContext $context
* @param Session $checkoutSession
* @param array $data
*/
public function __construct(
TemplateContext $context,
Session $checkoutSession,
array $data = []
) {
$this->checkoutSession = $checkoutSession;
parent::__construct($context, $data);
}
public function getGrandTotal()
{
$order = $this->checkoutSession->getLastRealOrder();
return $order->getGrandTotal();
}
public function getEmail()
{
$order = $this->checkoutSession->getLastRealOrder();
return $order->getCustomerEmail();
}
public function getFirst()
{
$order = $this->checkoutSession->getLastRealOrder();
return $order->getCustomerFirstname();
}
public function getLast()
{
$order = $this->checkoutSession->getLastRealOrder();
return $order->getCustomerLastname();
}
public function getMobile()
{
$order = $this->checkoutSession->getLastRealOrder();
$telephone = $order->getShippingAddress();
return $telephone->getTelephone();
}
public function getStreet()
{
$order = $this->checkoutSession->getLastRealOrder();
$street = $order->getShippingAddress();
return $street->getStreet();
}
public function getCity()
{
$order = $this->checkoutSession->getLastRealOrder();
$city = $order->getShippingAddress();
return $city->getCity();
}
public function getCountry()
{
$order = $this->checkoutSession->getLastRealOrder();
$country = $order->getShippingAddress();
return $country->getCountryId();
}
}
Could you please advise.