Magento. How get data of current order

Magento. How get data of current order

July 24, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento. How get data of current order

Retrieving Current Order Data in Magento Checkout

As a senior developer working on Magento projects, I often get asked how to access current order data during checkout. In this post, we’ll walk through the process of retrieving key information like addresses selected by the customer.

Understanding Magento’s Checkout Flow

Magento follows a multi-step checkout process:

  1. Shipping Address
  2. Shipping Method
  3. Payment Method
  4. Order Summary (Review)

The order summary step is where you want to access current order data, including shipping and billing addresses chosen by the customer.

Accessing Current Order Data in Block/Abstract

To retrieve current order data, you need to leverage Magento’s quote management system. Here’s a step-by-step guide:

  1. Include the necessary files: Ensure your block file includes the required namespace and files for the quote model:
namespace Vendor\Namespace\Block;
use Magento\Framework\App\Request\Http as Request;
use Magento\Quote\Model\QuoteIdMaskFactory;
  1. Inject the QuoteIdMask object: In your constructor, inject the quoteIdMask object which helps retrieve the current quote (order) being processed:
private $quoteIdMask;

public function __construct(
    ...
    QuoteIdMaskFactory $quoteIdMask,
    ...) {
   this->quoteIdMask = $quoteIdMask;
}
  1. Get the quote ID from session: Magento stores the current quote ID in the session during checkout:
$session = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Checkout\Model\Session');
$quote_id = $session->getQuote()->getId();
  1. Retrieve the order instance: Use the quoteIdMask to get the actual quote object:
$quote = $this->quoteIdMask->load($quote_id);
  1. Access address data: Now you can access shipping and billing addresses using the shippingAddress and billingAddress properties of the $quote object:
$billing_address = $quote->getBillingAddress();
$shipping_address = $quote->getShippingAddress();

echo 'Customer Name: ' . $billing_address->getName();
echo 'Street Address: ' . $shipping_address->getStreetLine(1);

Best Practices and Further Reading

  • Always use dependency injection for objects like quoteIdMask rather than directly instantiating them.
  • For complex queries, consider using Magento’s Magento\Quote\Model\ResourceModel\Quote resource model.
  • If you need to access order data outside of the block (like in a controller), follow similar steps but ensure proper request validity checks.

Check out LaravelCompany.com for more Magento development best practices and tips from our team of experts.

Conclusion

Retrieving current order data during checkout is a common task in Magento development. By understanding the quote management system and following the steps outlined above, you can easily access billing and shipping addresses selected by customers on the review (summary) step.

Remember to thoroughly test your code and ensure it handles edge cases like empty carts or guest checkouts appropriately. With proper implementation, you’ll be able to efficiently use order data in your custom Magento extensions.

Happy coding!

Checkout Orders Customers

Our network