custom/static-plugins/SamsonCustomer/src/Controller/AddressController.php line 79

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Samson\Controller;
  3. /***
  4.  *
  5.  * This file is part of the "SAMSON Shop" project.
  6.  *
  7.  * For the full copyright and license information, please read the
  8.  * LICENSE.txt file that was distributed with this source code.
  9.  *
  10.  *  (c) 2020
  11.  *
  12.  ***/
  13. use Samson\Exception\CustomerNeedsPasswordChangeException;
  14. use Shopware\Core\Checkout\Cart\Exception\CustomerNotLoggedInException;
  15. use Shopware\Core\Checkout\Customer\CustomerEntity;
  16. use Shopware\Core\Checkout\Customer\SalesChannel\AbstractChangeCustomerProfileRoute;
  17. use Shopware\Core\Checkout\Customer\SalesChannel\AbstractDeleteAddressRoute;
  18. use Shopware\Core\Checkout\Customer\SalesChannel\AbstractListAddressRoute;
  19. use Shopware\Core\Checkout\Customer\SalesChannel\AbstractUpsertAddressRoute;
  20. use Shopware\Core\Checkout\Customer\SalesChannel\AccountService;
  21. use Shopware\Core\Framework\Uuid\Exception\InvalidUuidException;
  22. use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
  23. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  24. use Shopware\Core\System\SystemConfig\SystemConfigService;
  25. use Shopware\Storefront\Controller\AddressController as ShopwareAddressController;
  26. use Shopware\Storefront\Page\Address\Detail\AddressDetailPageLoader;
  27. use Shopware\Storefront\Page\Address\Listing\AddressListingPageLoader;
  28. use Symfony\Component\HttpFoundation\RedirectResponse;
  29. use Symfony\Component\HttpFoundation\Request;
  30. use Symfony\Component\HttpFoundation\Response;
  31. use Shopware\Core\Framework\Routing\Annotation\LoginRequired;
  32. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  33. use Shopware\Core\Framework\Routing\Annotation\Since;
  34. use Symfony\Component\Routing\Annotation\Route;
  35. use Shopware\Storefront\Framework\Routing\Annotation\NoStore;
  36. use Samson\Annotation\CustomerNeedsPasswordChange;
  37. /**
  38.  * @RouteScope(scopes={"storefront"})
  39.  */
  40. class AddressController extends ShopwareAddressController
  41. {
  42.     private SystemConfigService $systemConfigService;
  43.     public function __construct(
  44.         AddressListingPageLoader           $addressListingPageLoader,
  45.         AddressDetailPageLoader            $addressDetailPageLoader,
  46.         AccountService                     $accountService,
  47.         AbstractListAddressRoute           $listAddressRoute,
  48.         AbstractUpsertAddressRoute         $updateAddressRoute,
  49.         AbstractDeleteAddressRoute         $deleteAddressRoute,
  50.         AbstractChangeCustomerProfileRoute $updateCustomerProfileRoute,
  51.         SystemConfigService                $systemConfigService)
  52.     {
  53.         parent::__construct($addressListingPageLoader,
  54.             $addressDetailPageLoader,
  55.             $accountService,
  56.             $listAddressRoute,
  57.             $updateAddressRoute,
  58.             $deleteAddressRoute,
  59.             $updateCustomerProfileRoute);
  60.         $this->systemConfigService $systemConfigService;
  61.     }
  62.     /**
  63.      * @Since("6.0.0.0")
  64.      * @LoginRequired()
  65.      * @CustomerNeedsPasswordChange()
  66.      *
  67.      * @Route("/account/address", name="frontend.account.address.page", options={"seo"="false"}, methods={"GET"})
  68.      * @NoStore
  69.      *
  70.      * @throws CustomerNotLoggedInException
  71.      * @throws CustomerNeedsPasswordChangeException
  72.      */
  73.     public function accountAddressOverview(Request $requestSalesChannelContext $contextCustomerEntity $customer): Response
  74.     {
  75.         if (empty($context->getCustomer())) {
  76.             return $this->redirectToRoute('frontend.account.login.page', [
  77.                 'redirectTo' => 'frontend.account.address.page'
  78.             ]);
  79.         }
  80.         return parent::accountAddressOverview($request$context$customer);
  81.     }
  82.     /**
  83.      * @Since("6.0.0.0")
  84.      * @LoginRequired()
  85.      * @CustomerNeedsPasswordChange()
  86.      * @Route("/account/address/create", name="frontend.account.address.create.page", options={"seo"="false"}, methods={"GET"})
  87.      * @NoStore
  88.      *
  89.      * @throws CustomerNotLoggedInException
  90.      * @throws CustomerNeedsPasswordChangeException
  91.      */
  92.     public function accountCreateAddress(Request $requestRequestDataBag $dataSalesChannelContext $contextCustomerEntity $customer): Response
  93.     {
  94.         if ($this->systemConfigService->get('SamsonConfiguration.settings.allowChangeAddress')) {
  95.             return parent::accountCreateAddress($request$data$context$customer);
  96.         }
  97.         return new RedirectResponse($this->generateUrl('frontend.account.home.page'));
  98.     }
  99.     /**
  100.      * @Since("6.0.0.0")
  101.      * @LoginRequired()
  102.      * @CustomerNeedsPasswordChange()
  103.      * @Route("/account/address/{addressId}", name="frontend.account.address.edit.page", options={"seo"="false"}, methods={"GET"})
  104.      * @NoStore
  105.      *
  106.      * @throws CustomerNotLoggedInException
  107.      * @throws CustomerNeedsPasswordChangeException
  108.      */
  109.     public function accountEditAddress(Request $requestSalesChannelContext $contextCustomerEntity $customer): Response
  110.     {
  111.         if ($this->systemConfigService->get('SamsonConfiguration.settings.allowChangeAddress')) {
  112.             return parent::accountEditAddress($request$context$customer);
  113.         }
  114.         return new RedirectResponse($this->generateUrl('frontend.account.home.page'));
  115.     }
  116.     /**
  117.      * @Since("6.0.0.0")
  118.      * @LoginRequired()
  119.      * @CustomerNeedsPasswordChange()
  120.      * @Route("/account/address/default-{type}/{addressId}", name="frontend.account.address.set-default-address", methods={"POST"})
  121.      *
  122.      * @throws CustomerNotLoggedInException
  123.      * @throws CustomerNeedsPasswordChangeException
  124.      * @throws InvalidUuidException
  125.      */
  126.     public function switchDefaultAddress(string $typestring $addressIdSalesChannelContext $contextCustomerEntity $customer): RedirectResponse
  127.     {
  128.         return parent::switchDefaultAddress($type$addressId$context$customer); // TODO: Change the autogenerated stub
  129.     }
  130.     /**
  131.      * @Since("6.0.0.0")
  132.      * @LoginRequired()
  133.      * @CustomerNeedsPasswordChange()
  134.      * @Route("/account/address/delete/{addressId}", name="frontend.account.address.delete", options={"seo"="false"}, methods={"POST"})
  135.      *
  136.      * @throws CustomerNotLoggedInException
  137.      * @throws CustomerNeedsPasswordChangeException
  138.      */
  139.     public function deleteAddress(string $addressIdSalesChannelContext $contextCustomerEntity $customer): Response
  140.     {
  141.         if ($this->systemConfigService->get('SamsonConfiguration.settings.allowChangeAddress')) {
  142.             return parent::deleteAddress($addressId$context$customer);
  143.         }
  144.         return new RedirectResponse($this->generateUrl('frontend.account.home.page'));
  145.     }
  146.     /**
  147.      * @Since("6.0.0.0")
  148.      * @LoginRequired()
  149.      * @CustomerNeedsPasswordChange()
  150.      * @Route("/account/address/create", name="frontend.account.address.create", options={"seo"="false"}, methods={"POST"})
  151.      * @Route("/account/address/{addressId}", name="frontend.account.address.edit.save", options={"seo"="false"}, methods={"POST"})
  152.      *
  153.      * @throws CustomerNotLoggedInException
  154.      * @throws CustomerNeedsPasswordChangeException
  155.      */
  156.     public function saveAddress(RequestDataBag $dataSalesChannelContext $contextCustomerEntity $customer): Response
  157.     {
  158.         return parent::saveAddress($data$context$customer);
  159.     }
  160.     /**
  161.      * @Since("6.0.0.0")
  162.      * @LoginRequired(allowGuest=true)
  163.      * @CustomerNeedsPasswordChange()
  164.      * @Route("/widgets/account/address-book", name="frontend.account.addressbook", options={"seo"=true}, methods={"POST"}, defaults={"XmlHttpRequest"=true})
  165.      *
  166.      * @throws CustomerNeedsPasswordChangeException
  167.      */
  168.     public function addressBook(Request $requestRequestDataBag $dataBagSalesChannelContext $contextCustomerEntity $customer): Response
  169.     {
  170.         return parent::addressBook($request$dataBag$context$customer);
  171.     }
  172. }