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

Commit 21930cc

Browse files
author
Patrick McLain
committed
Reset occ cookie on customer login
1 parent 9135d2d commit 21930cc

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

Observer/CustomerAuthenticated.php

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

etc/frontend/events.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:Event/etc/events.xsd">
3+
<event name="customer_customer_authenticated">
4+
<observer name="pmclain_occ" instance="Pmclain\OneClickCheckout\Observer\CustomerAuthenticated" />
5+
</event>
6+
</config>

0 commit comments

Comments
 (0)