Skip to content

Commit 4fc5ea6

Browse files
committed
Pending changes
1 parent 6a972b9 commit 4fc5ea6

9 files changed

Lines changed: 37 additions & 63 deletions

File tree

view/frontend/layout/loki_theme_add_alpine.xml

Lines changed: 0 additions & 26 deletions
This file was deleted.

view/frontend/layout/loki_theme_catalog_category_view.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:View/Layout:etc/page_configuration.xsd">
33
<body>
44
<referenceContainer name="before.body.end">
5-
<block name="loki.script.components.category.addtocart" template="Loki_Theme::script/components/category/addtocart.phtml"/>
5+
<block name="loki.script.components.category.addtocart" template="Loki_Theme::script/components/category/add-to-cart.phtml"/>
6+
<block name="loki.script.components.category.layered-navigation" template="Loki_Theme::script/components/category/layered-navigation.phtml"/>
7+
<block name="loki.script.components.category.add-to-wishlist" template="Loki_Theme::script/components/category/add-to-wishlist.phtml"/>
8+
<block name="loki.script.components.category.add-to-compare" template="Loki_Theme::script/components/category/add-to-compare.phtml"/>
69
</referenceContainer>
710
</body>
811
</page>

view/frontend/layout/loki_theme_default.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<block name="loki.script.components.messages" template="Loki_Theme::script/components/messages.phtml"/>
2424
<block name="loki.script.components.minicart" template="Loki_Theme::script/components/minicart.phtml"/>
2525
<block name="loki.script.components.top-links" template="Loki_Theme::script/components/top-links.phtml"/>
26-
<block name="loki.script.components.cookie-notice" template="Loki_Theme::script/components/cookie-notice.phtml"/>
26+
<block ifconfig="web/cookie/cookie_restriction" name="loki.script.components.cookie-notice" template="Loki_Theme::script/components/cookie-notice.phtml"/>
2727
</referenceContainer>
2828

2929
<referenceContainer name="minicart.addons">

view/frontend/templates/minicart.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,6 @@ use Magento\Framework\View\Element\Template;
158158

159159
<template x-if="hasNoCartItems">
160160
<div>
161-
<?= $escaper->escapeHtml(__('Your cart is empty')) ?>
161+
<?= $escaper->escapeHtml(__('You have no items in your shopping cart.')) ?>
162162
</div>
163163
</template>

view/frontend/templates/script/components/category/addtocart.phtml renamed to view/frontend/templates/script/components/category/add-to-cart.phtml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,16 @@ use Magento\Framework\View\Element\Template;
2626
const data = new FormData();
2727
data.append('product', form.querySelector('input[name="product"]').value);
2828
data.append('form_key', form.querySelector('input[name="form_key"]').value);
29+
data.append('uenc', form.querySelector('input[name="uenc"]').value);
2930

3031
fetch(form.action, {
3132
method: 'POST',
3233
headers: {
3334
'X-Requested-With': 'XMLHttpRequest',
34-
'Content-Type': 'multipart/form-data; charset=UTF-8',
3535
},
3636
body: data
3737
}).finally(function () {
38-
Alpine.store('LumaLocalStorage').refresh('cart');
39-
Alpine.store('LumaLocalStorage').refresh('messages');
38+
Alpine.store('LumaLocalStorage').refresh('cart,messages');
4039
button.disabled = false;
4140
});
4241
});

view/frontend/templates/script/components/messages.phtml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,6 @@ if (false === is_numeric($timeout)) {
2121

2222
const store = Alpine.store('LumaLocalStorage');
2323

24-
function getMessagesFromCookie() {
25-
const value = `; ${document.cookie}`;
26-
const parts = value.split(`; mage-messages=`);
27-
if (parts.length !== 2) {
28-
return [];
29-
}
30-
31-
document.cookie = "mage-messages=";
32-
const part = parts.pop().split(";").shift();
33-
if (!part) {
34-
return [];
35-
}
36-
37-
const decoded = decodeURIComponent(part);
38-
if (!decoded) {
39-
return [];
40-
}
41-
42-
return JSON.parse(decoded);
43-
}
44-
4524
function displayMessages(messages) {
4625
if (!messages.length > 0) {
4726
return;
@@ -81,6 +60,6 @@ if (false === is_numeric($timeout)) {
8160
store.remove('messages');
8261
})
8362

84-
displayMessages(getMessagesFromCookie());
63+
displayMessages(LokiCookies.get('mage-messages'));
8564
});
8665
</script>

view/frontend/templates/script/components/top-links.phtml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $customerAccountLoginUrl = $block->getUrl('customer/account/login');
1717
Alpine.effect(() => {
1818
const customerSection = Alpine.store('LumaLocalStorage').get('customer');
1919

20-
if (customerSection.id) {
20+
if (customerSection.fullname) {
2121
this.showCustomerUrls();
2222
this.hideGuestUrls();
2323
this.showGreeting();
@@ -49,12 +49,20 @@ $customerAccountLoginUrl = $block->getUrl('customer/account/login');
4949
});
5050
},
5151
showGreeting() {
52+
const element = this.$el.querySelector('.logged-in');
53+
if (!element) {
54+
return;
55+
}
56+
5257
const customerSection = Alpine.store('LumaLocalStorage').get('customer');
53-
this.$el.querySelector('.logged-in').innerHTML = '<?= /* @noEscape */ __('Welcome, %1') ?>'
58+
element.innerHTML = '<?= /* @noEscape */ __('Welcome, %1') ?>'
5459
.replace('%1', customerSection.fullname);
5560
},
5661
hideGreeting() {
57-
this.$el.querySelector('.greet.welcome').style.display = 'none';
62+
const element = this.$el.querySelector('.greet.welcome');
63+
if (element) {
64+
element.style.display = 'none';
65+
}
5866
},
5967
getGuestElements() {
6068
return [

view/frontend/templates/script/cookies.phtml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
22
declare(strict_types=1);
33

4-
/** @version 0.0.6 */
5-
64
use Loki\Theme\ViewModel\CookieConfig;
75
use Magento\Framework\View\Element\Template;
86

7+
/** @version 0.0.6 */
98
/** @var Template $block */
109
/** @var CookieConfig $cookieConfig */
1110

@@ -25,10 +24,10 @@ $cookieConfig = $block->getCookieConfig();
2524
const name = parts[0].trim();
2625
let value = parts[1].trim();
2726

27+
value = decodeURI(value);
28+
value = decodeURIComponent(value);
2829
if (value.startsWith('{') && value.endsWith('}')) {
2930
value = JSON.parse(value);
30-
} else {
31-
value = decodeURI(value);
3231
}
3332

3433
cookies[name] = value;
@@ -43,7 +42,10 @@ $cookieConfig = $block->getCookieConfig();
4342
let cookieParts = [];
4443
cookieParts.push(name + '=' + value);
4544
cookieParts.push('max-age=' + this.lifetime + 20000);
46-
cookieParts.push('path=' + this.path);
45+
46+
if (this.path) {
47+
cookieParts.push('path=' + this.path);
48+
}
4749

4850
if (this.domain) {
4951
cookieParts.push('domain=' + this.domain);
@@ -54,7 +56,12 @@ $cookieConfig = $block->getCookieConfig();
5456
}
5557

5658
cookieParts.push('SameSite=' + this.sameSite);
59+
console.log('set cookie', cookieParts);
60+
5761
document.cookie = cookieParts.join('; ');
62+
},
63+
isAllowedSaving() {
64+
return this.get('user_allowed_save_cookie');
5865
}
5966
}
6067
</script>

view/frontend/templates/script/store/local-storage.phtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ use Magento\Framework\View\Element\Template;
3131
url += '?sections=' + sections;
3232
}
3333

34-
fetch(url)
34+
fetch(url, {
35+
headers: {
36+
'X-Requested-With': 'XMLHttpRequest',
37+
},
38+
})
3539
.then((response) => {
3640
return response.json();
3741
})

0 commit comments

Comments
 (0)