0

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.

1
<?php
    use Magento\Framework\App\Bootstrap;
    include('app/bootstrap.php');
    $bootstrap = Bootstrap::create(BP, $_SERVER);

    $objectManager = $bootstrap->getObjectManager();

    $state = $objectManager->get('Magento\Framework\App\State');
    $state->setAreaCode('frontend');
    $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, privacy policy and cookie policy

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