1

Is it possible to get the basket table with Product name, quantity and price to show on the Order success page?

Also to show the shipping and billing address underneath this.

Please Advise.

2 Answers 2

1

Yes, you can get the order by using the order increment id (which is already on success page) on the success page. And after that you can get the order items from order. After that get the product from order item.

Use following code

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$incrId = 100005363;
$collection = $objectManager->create('Magento\Sales\Model\Order'); 
$order = $collection->loadByIncrementId($incrId);

        $orderItems = $order->getAllItems();

        foreach($orderItems as $item)
        {
            $product = $item->getProduct();
        }

Get shiiping and billing address

$billingAddress = $order->getBillingAddress();
$shippingAddress = $order->getShippingAddress();
4
  • Let me know if you have any question for above code.
    – DJ Dev
    Commented Nov 20, 2019 at 12:59
  • Thank you for the response. Would this code go on the success.phtml page? If not which template would this need to be added to?
    – Developer
    Commented Nov 20, 2019 at 14:44
  • Direct use of ObjectManager is not good practice for magento development. Commented Nov 20, 2019 at 15:27
  • Yes you can use this code into directly in success.phtml. And if you don't want to use objectMnager then first you'll need to override success block.
    – DJ Dev
    Commented Nov 21, 2019 at 7:18
0

Yes, It is possible to show recent order data on order success page. As you already have recent order increment Id.

protected $orderFactory;

public function __construct(
    \Magento\Sales\Api\Data\OrderInterfaceFactory $orderFactory,
    ......
) {
    $this->orderFactory = $orderFactory;

}

Load order object by increment id:

/** @var \Magento\Sales\Api\Data\OrderInterface $order **/
$order = $this->orderFactory->create()->loadByIncrementId('00001952-42');
$orderItems = $order->getAllItems();
foreach($orderItems as $item) {
      $product = $item->getProduct();
      echo "product name ". $product->getName();
      echo "product sku ". $product->getSku();
}

Template to ovveride in your theme vendor/magento/module-checkout/view/frontend/templates/success.phtml

5
  • Thank you for your reply. Where would this code go? I am new to Magento.
    – Developer
    Commented Nov 20, 2019 at 14:02
  • you can place this code into helper class or override block of order success page and place custom function in it. Commented Nov 20, 2019 at 15:27
  • Which template does this need to be added to?
    – Developer
    Commented Nov 20, 2019 at 15:40
  • answer updated! Commented Nov 21, 2019 at 8:58
  • I added this to the success.phtml template and still not showing the product table. Please can you further advise on this?
    – Developer
    Commented Nov 21, 2019 at 13:51

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.