<?php
declare(strict_types=1);
namespace Rhiem\RhiemRentalProducts\Subscriber;
use Rhiem\RhiemRentalProducts\Components\RentalProduct\LineItem\RentalProductLineItemFactory;
use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CheckoutConfirmShippingAddressSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
CheckoutConfirmPageLoadedEvent::class => 'onCheckoutConfirmPageLoaded',
];
}
/**
* Shopware core sets hideShippingAddress based on the presence of IS_PHYSICAL line items.
* Rental products are represented as a dedicated line item type and may not carry IS_PHYSICAL,
* which hides the shipping address card on checkout confirm. This subscriber re-enables the
* shipping address card when rental line items are present in the cart.
*/
public function onCheckoutConfirmPageLoaded(CheckoutConfirmPageLoadedEvent $event): void
{
$page = $event->getPage();
$cart = $page->getCart();
$rentalLineItems = $cart->getLineItems()->filterFlatByType(RentalProductLineItemFactory::TYPE);
if (\count($rentalLineItems) === 0) {
return;
}
$page->setHideShippingAddress(false);
}
}