Created
April 27, 2020 12:55
-
-
Save ndzoesch/4edf70c290f0e22c4f546673934b0fed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
namespace Shopware\Core\Checkout\Customer\SalesChannel; | |
// SHORTENED FOR READABILITY; | |
// SEE THE LINK ABOVE FOR FULL SOURCE | |
/** | |
* @RouteScope(scopes={"store-api"}) | |
*/ | |
class LogoutRoute extends AbstractLogoutRoute | |
{ | |
/** | |
* @OA\Post( | |
* path="/account/logout", | |
* description="Logouts current loggedin customer", | |
* operationId="logoutCustomer", | |
* tags={"Store API", "Account"}, | |
* @OA\Response( | |
* response="200", | |
* description="" | |
* ) | |
* ) | |
* @Route(path="/store-api/v{version}/account/logout", name="store-api.account.logout", methods={"POST"}) | |
*/ | |
public function logout(SalesChannelContext $context): NoContentResponse | |
{ | |
if (!$context->getCustomer()) { | |
throw new CustomerNotLoggedInException(); | |
} | |
$this->contextPersister->save( | |
$context->getToken(), | |
[ | |
'customerId' => null, | |
'billingAddressId' => null, | |
'shippingAddressId' => null, | |
] | |
); | |
$event = new CustomerLogoutEvent($context, $context->getCustomer()); | |
$this->eventDispatcher->dispatch($event); | |
return new NoContentResponse(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment