Skip to content

Commit 8b5a167

Browse files
committed
Replace redirect script on customer/account/logoutSuccess page
1 parent 082b7e7 commit 8b5a167

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
3+
<body>
4+
<referenceBlock name="customer_logout" template="LokiTheme_LumaComponents::script/component/customer/logout.phtml"/>
5+
</body>
6+
</page>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Magento\Framework\Escaper;
5+
use Magento\Framework\View\Element\Template;
6+
7+
/** @var Template $block */
8+
/** @var Escaper $escaper */
9+
10+
$redirectUrl = $block->getUrl();
11+
$timeout = (int)$block->getTimeout();
12+
if ($timeout < 1) {
13+
$timeout = 2000;
14+
}
15+
?>
16+
<div x-data="LumaCustomerLogout">
17+
<p x-html="getMessage"></p>
18+
</div>
19+
20+
<script>
21+
document.addEventListener('alpine:init', () => {
22+
Alpine.data('LumaCustomerLogout', () => ({
23+
message: '<?= $escaper->escapeHtml(
24+
__(
25+
'You have signed out and will go to our homepage in %1 seconds.'
26+
)
27+
) ?>',
28+
redirectUrl: '<?= $block->getUrl() ?>',
29+
timeout: <?= (int)$timeout ?>,
30+
init() {
31+
this.prefetch();
32+
33+
const interval = setInterval(() => {
34+
this.timeout = this.timeout - 1000;
35+
}, 1000);
36+
37+
setTimeout(() => {
38+
clearInterval(interval);
39+
window.location.assign(this.redirectUrl);
40+
}, this.timeout);
41+
},
42+
getMessage() {
43+
const seconds = this.timeout / 1000;
44+
return this.message.replace('%1', seconds);
45+
},
46+
prefetch() {
47+
const preloadLink = document.createElement('link');
48+
preloadLink.rel = 'prefetch';
49+
preloadLink.as = 'document';
50+
preloadLink.href = '/';
51+
document.head.appendChild(preloadLink);
52+
}
53+
}));
54+
});
55+
</script>
56+
57+
<script type="speculationrules">
58+
{
59+
"prerender": [{ "source": "list", "urls": ["<?= $block->getUrl() ?>"] }]
60+
}
61+
</script>

0 commit comments

Comments
 (0)