<?php declare(strict_types=1);
namespace Dvdw\PlatformChoice\Storefront\Controller;
use Dvdw\PlatformChoice\System\SalesChannel\Struct\DashboardDomainExtension;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Content\ProductExport\Exception\SalesChannelDomainNotFoundException;
use Shopware\Core\Framework\Routing\Annotation\Since;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\AccountProfileController;
use Shopware\Storefront\Controller\StorefrontController;
use Shopware\Storefront\Framework\Routing\Annotation\NoStore;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/
class ProfileController extends StorefrontController
{
private AccountProfileController $decorated;
public function __construct(
AccountProfileController $decorated
)
{
$this->decorated = $decorated;
}
public function getDecorated(): AccountProfileController
{
return $this->decorated;
}
/**
* @Since("6.0.0.0")
* @Route("/account", name="frontend.account.home.page", methods={"GET"}, defaults={"_loginRequired"=true})
* @NoStore
*/
public function index(Request $request, SalesChannelContext $context, CustomerEntity $customer): Response
{
return $this->profileOverview($request, $context);
}
/**
* @Since("6.0.0.0")
* @Route("/account/profile", name="frontend.account.profile.page", methods={"GET"}, defaults={"_loginRequired"=true})
* @NoStore
*/
public function profileOverview(Request $request, SalesChannelContext $context): Response
{
$url = $this->getDashboardDomain($context);
return new RedirectResponse(rtrim($url, '/') . '/account/profile');
}
private function getDashboardDomain(SalesChannelContext $context): string
{
/** @var DashboardDomainExtension|null $dashboardDomain */
$dashboardDomain = $context->getExtension(DashboardDomainExtension::KEY);
if ($dashboardDomain === null) {
throw new SalesChannelDomainNotFoundException('Dashboard');
}
return $dashboardDomain->getDomain();
}
}