Magento 2 how to get all shipping rates from CartTotalRepository

Magento 2 how to get all shipping rates from CartTotalRepository

October 15, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 how to get all shipping rates from CartTotalRepository

Magento 2: Retrieving All Shipping Rates from CartTotalRepository

As a senior developer specializing in e-commerce platforms like Magento, I often encounter complex shipping configuration requirements from our clients at Laravel Company. In this post, we’ll tackle the challenge of retrieving all shipping rates from the CartTotalRepository to facilitate custom shipping calculations.

Understanding the Issue

We have a scenario where table rate shipping is already configured:

  • Within the US: $13
  • Alaska and outside the US: $38

Additionally, we want to offer rush shipping for an extra $25. While we’ve successfully added custom shipping following the Magento 2 documentation (Checkout - Add Custom Carrier), there’s a persistent issue on the final checkout step.

Currently, the rush shipping cost is displayed as $25 instead of the expected total of $38 ($13 + $25). Our goal is to fetch this combined shipping rate consistently across the cart and both checkout steps.

Debugging CartTotalRepository

Let’s start by examining the provided code:

$rates = $address->collectShippingRates()->getGroupedAllShippingRates();

The aim here is to collect all available shipping rates, including the table rate and custom rush rate. However, at this stage, only the custom shipping method ($25) is being yielded.

The Approach: Fetching Table Rate and Custom Shipping

To resolve this issue, we need to modify our approach:

  1. Fetch the table rate using the rateId: Magento uses a unique rate_id for each shipping method. In your case, you should be able to find the rate_id for the table rate shipping within the admin panel or database.

  2. Fetch the custom rush shipping amount: You’ve already added this as a separate carrier module.

  3. Calculate the combined total ($13 + $25 = $38) and apply it consistently across all checkout steps.

Here’s an outline of how you can achieve this:

// Fetch table rate using rateId (replace 'your_table_rate_id' with actual ID)
$tableRate = $this->tableRateRepository->get('your_table_rate_id');

// Fetch custom rush shipping amount
$rushShipping = 25;

// Calculate total shipping cost
$totalShippingCost = $tableRate->getPrice() + $rushShipping;

Conclusion

Retrieving all shipping rates from the CartTotalRepository in Magento 2 requires a strategic approach. By fetching both the table rate and custom rush shipping method separately, you can then calculate the total cost and apply it consistently throughout the checkout process.

Remember to replace placeholders like 'your_table_rate_id' with actual values specific to your store configuration.

For more advanced techniques in Magento development or if you need a professional team to handle your e-commerce needs, I highly recommend reaching out to Laravel Company. Our team of experts specializes in providing top-notch solutions tailored to your business requirements.

Stay tuned for more insights on Magento 2 and other e-commerce best practices!

Magento 2 Checkout Database Configuration

Our network