# Show shipping price in checkout for not selected methods

**URL:** https://forum.shopware.com/t/show-shipping-price-in-checkout-for-not-selected-methods/99024
**Category:** Shopware 6 (English)
**Tags:** programming
**Created:** [21. März 2023 um 09:19 UTC](https://forum.shopware.com/t/show-shipping-price-in-checkout-for-not-selected-methods/99024 "2023-03-21T09:19:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![patryk.jurkiewicz19](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@patryk.jurkiewicz19](https://forum.shopware.com/u/patryk.jurkiewicz19)
#### Post date: [21. März 2023 um 09:19 UTC](https://forum.shopware.com/t/show-shipping-price-in-checkout-for-not-selected-methods/99024/1 "2023-03-21T09:19:35Z")

</div>

Hello!

I need to show price for shipping methods that are not selected in the checkout. I’ve decorated

`Shopware\Core\Checkout\Shipping\SalesChannel\ShippingMethodRoute`

Service, and configured DI to place my new class in the checkout controller. Here is the load function code

```
  public function load(Request $request, SalesChannelContext $context, Criteria $criteria): ShippingMethodRouteResponse {

      $result = $this->shippingMethodRoute->load($request, $context, $criteria);

      $shippingMethods = $result->getShippingMethods()->filterByActiveRules($context);

      $cart = $this->cartService->getCart($context->getToken(), $context);
      /** @var ShippingMethodEntity $shippingMethod */
      foreach ($shippingMethods as $shippingMethod) {
          $cartClone = clone $cart;
          $cartData = $cartClone->getData();
          $deliveries = $cartClone->getDeliveries();
          /** @var Delivery $delivery */
          foreach ($deliveries as $delivery) {
              $delivery->setShippingMethod($shippingMethod);
          }
          $cartData->set("shipping-method-" . $shippingMethod->getId(), $shippingMethod);
          $this->deliveryCalculator->calculate($cartData, $cartClone, $deliveries, $context);
          $shippingCost = $cartClone->getDeliveries()->getShippingCosts()->sum()->getTotalPrice();
          var_dump($shippingCost);
          $shippingMethod->shippingPrice = $shippingCost;
      }

      return $result;
  }

```

But in some cases, it works correctly but sometimes when I change the shipping method it calculates one price for all of them, which is incorrect.

---

<div class="post-metadata">

### Author: ![patryk.jurkiewicz19](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@patryk.jurkiewicz19](https://forum.shopware.com/u/patryk.jurkiewicz19)
#### Post date: [27. März 2023 um 11:08 UTC](https://forum.shopware.com/t/show-shipping-price-in-checkout-for-not-selected-methods/99024/2 "2023-03-27T11:08:33Z")

</div>

I’ve solved the issue. You need to also set the delivery shipping price to zero, otherwise, it doesn’t calculate it

public function load(Request $request, SalesChannelContext $context, Criteria $criteria): ShippingMethodRouteResponse {

```
      $criteria->addAssociation('prices');
      $result = $this->shippingMethodRoute->load($request, $context, $criteria);
      $originalResult = clone $result;
      $cart = $this->cartService->getCart($context->getToken(), $context);
      $shippingMethods = $result->getShippingMethods()->filterByActiveRules($context);
      /** @var ShippingMethodEntity $shippingMethod */
      try {
          foreach ($shippingMethods as $shippingMethod) {
              $cartClone = clone $cart;
              $cartData = $cartClone->getData();
              $deliveries = $cartClone->getDeliveries();
              /** @var Delivery $delivery */
              foreach ($deliveries as $delivery) {
                  $delivery->setShippingCosts(new CalculatedPrice(0, 0, new CalculatedTaxCollection(), new TaxRuleCollection()));
                  $delivery->setShippingMethod($shippingMethod);
              }
              $cartData->set(DeliveryProcessor::buildKey($shippingMethod->getId()), $shippingMethod);
              $this->deliveryCalculator->calculate($cartData, $cartClone, $deliveries, $context);
              $shippingCost = $cartClone->getDeliveries()->getShippingCosts()->sum()->getTotalPrice();
              $shippingMethod->shippingPrice = $shippingCost;
          }
      } catch (\Error $exception) {
          return $originalResult;
      }

      return $result;
  }

```
