am extending the onepage/success block and able to get the order id from it but what I want is last ordered information like Product URL, product ID, Product image and so, I did a search about this but I couldn't find any apt ans for this, any reference even would be helpful. I need all these info at success page.

namespace Mobiweb\Ordershare\Block;

class Ordershare extends \Magento\Checkout\Block\Onepage\Success { public function getOrder() { return $this->_checkoutSession->getLastRealOrder(); } }

in phtml am getting last order id. I want that last ordered product details by that id.

  • For all items of last order ? Commented Mar 10, 2018 at 17:59
  • I have updated the questions. @KishanPatadia Commented Mar 11, 2018 at 11:10

1 Answer 1

    use Magento\Framework\App\Bootstrap;
    $bootstrap = Bootstrap::create(BP, $_SERVER);

    $objectManager = $bootstrap->getObjectManager();

    $state = $objectManager->get('Magento\Framework\App\State');
    $orderId = 3; // Put your last orderId
    $orderData = $objectManager->create('Magento\Sales\Model\Order')->load($orderId);

    if(is_object($orderData) && $orderData->getId()!=''){
          $payment_info = (array)$orderData->getPaymentsCollection()->getData();
          $orderHistory = (array)$orderData->getStatusHistoryCollection()->getData();
          $items = $orderData->getAllItems();               
          $order_detail= (array)$orderData->getData();
          $billingData = (array)$orderData->getBillingAddress()->getData();
          $shippingData = (array)$orderData->getShippingAddress()->getData();

          // get each item detail
          foreach($items as $item){
              $item_detail = (array) $item->getData();
          }//end each

      }//end if


Run this file, Print array as per your need

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.