Get quote by reserved order id

Get quote by reserved order id

July 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Get quote by reserved order id

Retrieving Quotes by Reserved Order ID in Laravel Commerce

When integrating a third-party payment gateway into your e-commerce site built with Laravel Commerce, you may find yourself needing to retrieve a quote using the reserved order ID returned from the gateway upon successful payment. This can be achieved without having to convert the quote into an order beforehand.

Understanding Reserved Orders and Quotes

In Laravel Commerce, a quote represents a shopping cart or basket of products. When a customer proceeds to checkout, they are presented with a quote summary before the payment process begins. A reserved order, on the other hand, is a temporary holding area for orders that are in progress but have not yet been finalized.

Retrieving Quotes by Reserved Order ID

To fetch a quote using the reserved order ID returned from your external payment gateway, you’ll first need to retrieve the corresponding reservation. This can be done using the Reservations model provided by Laravel Commerce:

use App\Models\Reservation;
use App\Models\Quote;

$reservation = Reservation::where('reserved_order_id', $externalGatewayId)
                           ->firstOrFail();

In this example, we’re using a Laravel query to find the reservation with the matching reserved_order_id provided by the external payment gateway. The firstOrFail() method will throw an exception if no matching record is found.

Accessing the Associated Quote

Once you have retrieved the reservation, you can access the associated quote using the quote relationship defined in your Reservation model:

$quote = $reservation->quote;

The $quote variable now contains the Quote model instance for the shopping cart that was used to create the original order.

Retrieving Quote Items and Totals

With a reference to the quote, you can easily access all the items in the cart:

foreach ($quote->items as $item) {
    // Process each item
}

You can also retrieve the total price of the quote using the total attribute:

$totalPrice = $quote->total;

Conclusion: A Seamless Integration

In conclusion, retrieving a quote using a reserved order ID in Laravel Commerce is a straightforward process that doesn’t require converting the quote into an order prematurely. This approach allows for a clean separation of concerns between your e-commerce application and the external payment gateway.

Remember to adapt this example according to your specific needs and ensure you have proper error handling in place, especially when dealing with third-party integrations.

For more detailed information on working with reservations and quotes in Laravel Commerce, I recommend checking out our official documentation for a comprehensive guide.

Checkout Catalog Database Orders

Our network