From f109ad158c564caad508f36892aa3e1bb12ac9b0 Mon Sep 17 00:00:00 2001 From: Touza El Hassan <131183815+elhassantouza@users.noreply.github.com> Date: Thu, 9 May 2024 14:40:21 +0100 Subject: [PATCH 1/3] Display error message when total cart amount is greater than max checkout amount --- assets/main.js | 19 +++++++++++++++++++ layouts/theme.liquid | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/assets/main.js b/assets/main.js index c69134bb..7bcd0f71 100644 --- a/assets/main.js +++ b/assets/main.js @@ -309,3 +309,22 @@ function processVideoSections() { } processVideoSections(); + +function decodeHtmlEntities(text) { + let textarea = document.createElement('textarea'); + textarea.innerHTML = text; + + return textarea.value; +} + +function renderTextContent(htmlContent) { + let tempElement = document.createElement('div'); + tempElement.innerHTML = htmlContent; + + return tempElement.innerText || tempElement.textContent; +} + +if (FORM.errors) { + let decodedText = decodeHtmlEntities(FORM.errors); + notify(renderTextContent(decodedText), 'error', 20000); +} diff --git a/layouts/theme.liquid b/layouts/theme.liquid index 6b349c80..1588ad2b 100644 --- a/layouts/theme.liquid +++ b/layouts/theme.liquid @@ -25,6 +25,12 @@ {% section 'main-footer' %} {%- render 'cart-drawer' -%} + {% javascript %} + const FORM = { + errors: '{{ form.errors | first }}', + } + {% endjavascript %} + {{ 'main.js' | asset_url | script_tag }} From 0bd52d1a7c20ab11f919b2d6c3cf6905d8b5d5c1 Mon Sep 17 00:00:00 2001 From: Touza El Hassan <131183815+elhassantouza@users.noreply.github.com> Date: Thu, 9 May 2024 14:49:56 +0100 Subject: [PATCH 2/3] Test --- assets/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/main.js b/assets/main.js index 7bcd0f71..2308ac48 100644 --- a/assets/main.js +++ b/assets/main.js @@ -328,3 +328,4 @@ if (FORM.errors) { let decodedText = decodeHtmlEntities(FORM.errors); notify(renderTextContent(decodedText), 'error', 20000); } + From 70dd52832640d6d158382d2ea3bdca42a8a5f120 Mon Sep 17 00:00:00 2001 From: Touza El Hassan <131183815+elhassantouza@users.noreply.github.com> Date: Thu, 9 May 2024 15:29:22 +0100 Subject: [PATCH 3/3] Update --- assets/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/main.js b/assets/main.js index 2308ac48..7bcd0f71 100644 --- a/assets/main.js +++ b/assets/main.js @@ -328,4 +328,3 @@ if (FORM.errors) { let decodedText = decodeHtmlEntities(FORM.errors); notify(renderTextContent(decodedText), 'error', 20000); } -