Skip to content
This repository was archived by the owner on Jun 2, 2022. It is now read-only.

Commit 980e413

Browse files
author
Patrick McLain
committed
Delete status cookie on logout
1 parent 7bf443e commit 980e413

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Plugin/Logout.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Pmclain\OneClickCheckout\Plugin;
4+
5+
use Magento\Framework\Stdlib\CookieManagerInterface;
6+
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
7+
use Magento\Framework\Session\SessionManagerInterface;
8+
9+
class Logout
10+
{
11+
/**
12+
* @var CookieManagerInterface
13+
*/
14+
private $cookieManager;
15+
16+
/**
17+
* @var CookieMetadataFactory
18+
*/
19+
private $cookieMetaDataFactory;
20+
21+
/**
22+
* @var SessionManagerInterface
23+
*/
24+
private $sessionManager;
25+
26+
public function __construct(
27+
CookieManagerInterface $cookieManager,
28+
CookieMetadataFactory $cookieMetadataFactory,
29+
SessionManagerInterface $sessionManager
30+
) {
31+
$this->cookieManager = $cookieManager;
32+
$this->cookieMetaDataFactory = $cookieMetadataFactory;
33+
$this->sessionManager = $sessionManager;
34+
}
35+
36+
/**
37+
* @param \Magento\Customer\Controller\Account\Logout $subject
38+
* @param \Magento\Framework\Controller\Result\Redirect $result
39+
* @return \Magento\Framework\Controller\Result\Redirect
40+
*/
41+
public function afterExecute(
42+
\Magento\Customer\Controller\Account\Logout $subject,
43+
$result
44+
) {
45+
$this->cookieManager->deleteCookie(
46+
'occ_status',
47+
$this->cookieMetaDataFactory->createCookieMetadata()
48+
->setPath($this->sessionManager->getCookiePath())
49+
->setDomain($this->sessionManager->getCookieDomain())
50+
);
51+
52+
return $result;
53+
}
54+
}

etc/frontend/di.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3+
<type name="Magento\Customer\Controller\Account\Logout">
4+
<plugin name="pmclain_occ_logout" type="Pmclain\OneClickCheckout\Plugin\Logout" sortOrder="10" />
5+
</type>
6+
</config>

0 commit comments

Comments
 (0)