Skip to content

Instantly share code, notes, and snippets.

@ndzoesch
Created April 27, 2020 12:55
Show Gist options
  • Save ndzoesch/4edf70c290f0e22c4f546673934b0fed to your computer and use it in GitHub Desktop.
Save ndzoesch/4edf70c290f0e22c4f546673934b0fed to your computer and use it in GitHub Desktop.
<?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