<?php declare(strict_types=1);
namespace Samson\Controller;
/***
*
* This file is part of the "SAMSON Shop" project.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2020
*
***/
use Samson\Exception\CustomerNeedsPasswordChangeException;
use Shopware\Core\Checkout\Cart\Exception\CustomerNotLoggedInException;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Shopware\Core\Checkout\Customer\SalesChannel\AbstractChangeCustomerProfileRoute;
use Shopware\Core\Checkout\Customer\SalesChannel\AbstractDeleteAddressRoute;
use Shopware\Core\Checkout\Customer\SalesChannel\AbstractListAddressRoute;
use Shopware\Core\Checkout\Customer\SalesChannel\AbstractUpsertAddressRoute;
use Shopware\Core\Checkout\Customer\SalesChannel\AccountService;
use Shopware\Core\Framework\Uuid\Exception\InvalidUuidException;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Controller\AddressController as ShopwareAddressController;
use Shopware\Storefront\Page\Address\Detail\AddressDetailPageLoader;
use Shopware\Storefront\Page\Address\Listing\AddressListingPageLoader;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Shopware\Core\Framework\Routing\Annotation\LoginRequired;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\Framework\Routing\Annotation\Since;
use Symfony\Component\Routing\Annotation\Route;
use Shopware\Storefront\Framework\Routing\Annotation\NoStore;
use Samson\Annotation\CustomerNeedsPasswordChange;
/**
* @RouteScope(scopes={"storefront"})
*/
class AddressController extends ShopwareAddressController
{
private SystemConfigService $systemConfigService;
public function __construct(
AddressListingPageLoader $addressListingPageLoader,
AddressDetailPageLoader $addressDetailPageLoader,
AccountService $accountService,
AbstractListAddressRoute $listAddressRoute,
AbstractUpsertAddressRoute $updateAddressRoute,
AbstractDeleteAddressRoute $deleteAddressRoute,
AbstractChangeCustomerProfileRoute $updateCustomerProfileRoute,
SystemConfigService $systemConfigService)
{
parent::__construct($addressListingPageLoader,
$addressDetailPageLoader,
$accountService,
$listAddressRoute,
$updateAddressRoute,
$deleteAddressRoute,
$updateCustomerProfileRoute);
$this->systemConfigService = $systemConfigService;
}
/**
* @Since("6.0.0.0")
* @LoginRequired()
* @CustomerNeedsPasswordChange()
*
* @Route("/account/address", name="frontend.account.address.page", options={"seo"="false"}, methods={"GET"})
* @NoStore
*
* @throws CustomerNotLoggedInException
* @throws CustomerNeedsPasswordChangeException
*/
public function accountAddressOverview(Request $request, SalesChannelContext $context, CustomerEntity $customer): Response
{
if (empty($context->getCustomer())) {
return $this->redirectToRoute('frontend.account.login.page', [
'redirectTo' => 'frontend.account.address.page'
]);
}
return parent::accountAddressOverview($request, $context, $customer);
}
/**
* @Since("6.0.0.0")
* @LoginRequired()
* @CustomerNeedsPasswordChange()
* @Route("/account/address/create", name="frontend.account.address.create.page", options={"seo"="false"}, methods={"GET"})
* @NoStore
*
* @throws CustomerNotLoggedInException
* @throws CustomerNeedsPasswordChangeException
*/
public function accountCreateAddress(Request $request, RequestDataBag $data, SalesChannelContext $context, CustomerEntity $customer): Response
{
if ($this->systemConfigService->get('SamsonConfiguration.settings.allowChangeAddress')) {
return parent::accountCreateAddress($request, $data, $context, $customer);
}
return new RedirectResponse($this->generateUrl('frontend.account.home.page'));
}
/**
* @Since("6.0.0.0")
* @LoginRequired()
* @CustomerNeedsPasswordChange()
* @Route("/account/address/{addressId}", name="frontend.account.address.edit.page", options={"seo"="false"}, methods={"GET"})
* @NoStore
*
* @throws CustomerNotLoggedInException
* @throws CustomerNeedsPasswordChangeException
*/
public function accountEditAddress(Request $request, SalesChannelContext $context, CustomerEntity $customer): Response
{
if ($this->systemConfigService->get('SamsonConfiguration.settings.allowChangeAddress')) {
return parent::accountEditAddress($request, $context, $customer);
}
return new RedirectResponse($this->generateUrl('frontend.account.home.page'));
}
/**
* @Since("6.0.0.0")
* @LoginRequired()
* @CustomerNeedsPasswordChange()
* @Route("/account/address/default-{type}/{addressId}", name="frontend.account.address.set-default-address", methods={"POST"})
*
* @throws CustomerNotLoggedInException
* @throws CustomerNeedsPasswordChangeException
* @throws InvalidUuidException
*/
public function switchDefaultAddress(string $type, string $addressId, SalesChannelContext $context, CustomerEntity $customer): RedirectResponse
{
return parent::switchDefaultAddress($type, $addressId, $context, $customer); // TODO: Change the autogenerated stub
}
/**
* @Since("6.0.0.0")
* @LoginRequired()
* @CustomerNeedsPasswordChange()
* @Route("/account/address/delete/{addressId}", name="frontend.account.address.delete", options={"seo"="false"}, methods={"POST"})
*
* @throws CustomerNotLoggedInException
* @throws CustomerNeedsPasswordChangeException
*/
public function deleteAddress(string $addressId, SalesChannelContext $context, CustomerEntity $customer): Response
{
if ($this->systemConfigService->get('SamsonConfiguration.settings.allowChangeAddress')) {
return parent::deleteAddress($addressId, $context, $customer);
}
return new RedirectResponse($this->generateUrl('frontend.account.home.page'));
}
/**
* @Since("6.0.0.0")
* @LoginRequired()
* @CustomerNeedsPasswordChange()
* @Route("/account/address/create", name="frontend.account.address.create", options={"seo"="false"}, methods={"POST"})
* @Route("/account/address/{addressId}", name="frontend.account.address.edit.save", options={"seo"="false"}, methods={"POST"})
*
* @throws CustomerNotLoggedInException
* @throws CustomerNeedsPasswordChangeException
*/
public function saveAddress(RequestDataBag $data, SalesChannelContext $context, CustomerEntity $customer): Response
{
return parent::saveAddress($data, $context, $customer);
}
/**
* @Since("6.0.0.0")
* @LoginRequired(allowGuest=true)
* @CustomerNeedsPasswordChange()
* @Route("/widgets/account/address-book", name="frontend.account.addressbook", options={"seo"=true}, methods={"POST"}, defaults={"XmlHttpRequest"=true})
*
* @throws CustomerNeedsPasswordChangeException
*/
public function addressBook(Request $request, RequestDataBag $dataBag, SalesChannelContext $context, CustomerEntity $customer): Response
{
return parent::addressBook($request, $dataBag, $context, $customer);
}
}