custom/plugins/RhiemRentalProducts/src/Subscriber/CheckoutConfirmShippingAddressSubscriber.php line 26

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Rhiem\RhiemRentalProducts\Subscriber;
  4. use Rhiem\RhiemRentalProducts\Components\RentalProduct\LineItem\RentalProductLineItemFactory;
  5. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class CheckoutConfirmShippingAddressSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             CheckoutConfirmPageLoadedEvent::class => 'onCheckoutConfirmPageLoaded',
  13.         ];
  14.     }
  15.     /**
  16.      * Shopware core sets hideShippingAddress based on the presence of IS_PHYSICAL line items.
  17.      * Rental products are represented as a dedicated line item type and may not carry IS_PHYSICAL,
  18.      * which hides the shipping address card on checkout confirm. This subscriber re-enables the
  19.      * shipping address card when rental line items are present in the cart.
  20.      */
  21.     public function onCheckoutConfirmPageLoaded(CheckoutConfirmPageLoadedEvent $event): void
  22.     {
  23.         $page $event->getPage();
  24.         $cart $page->getCart();
  25.         $rentalLineItems $cart->getLineItems()->filterFlatByType(RentalProductLineItemFactory::TYPE);
  26.         if (\count($rentalLineItems) === 0) {
  27.             return;
  28.         }
  29.         $page->setHideShippingAddress(false);
  30.     }
  31. }