Closed
Description
Hello, I'm trying to print data to the success page about the most recent order placed. In app/code/Magento/Checkout/Controller/Onepage/Success.php
I've added the following php:
<?php
$orderID = $session->getLastOrderId();
$orderData = $this->_objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderID);
$orderItems = $orderData->getAllItems();
$orderString = "";
foreach ($orderItems as $item) {
$orderString = $orderString.$item->getSku();
}
$orderAddress = $orderData->getShippingAddress();
?>
<div id="order-data">
<pre id="order-number"><?= $orderID ?></pre>
<pre id="order-items"><?= print_r($orderItems) ?></pre>
<pre id="order-items-string"><?= print_r($orderString) ?></pre>
<pre id="order-address"><?= print_r($orderAddress) ?></pre>
<pre id="order-name"><?= print_r($orderData->getFirstName()) ?></pre>
</div>
I know it's working to some degree. The page is loading without errors and in the admin panel, I confirmed that the order is being placed with the printed $orderID with valid data. However, only the $orderID seems to be printing correctly. The output div comes out as follows:
<div id="order-data">
<!-- correct ID -->
<pre id="order-number">63</pre>
<!-- looks like an empty array followed by a 1? -->
<pre id="order-items">
Array
(
)
1
</pre>
<pre id="order-items-string">1</pre> <!-- all the other get methods return "1" -->
<pre id="order-address">1</pre>
<pre id="order-name">1</pre>
</div>
Sorry if this is a rudimentary question, but I've been struggling with this for a while. I can't find any pages in the php developer guide docs about interacting with the model. What am I doing wrong?