diff --git a/Build/Sources/JavaScript/add_to_cart.js b/Build/Sources/JavaScript/add_to_cart.js index a9a4d0c0..c5ff3147 100644 --- a/Build/Sources/JavaScript/add_to_cart.js +++ b/Build/Sources/JavaScript/add_to_cart.js @@ -89,29 +89,30 @@ document.addEventListener('DOMContentLoaded', () => { const { net } = response; const { gross } = response; - const miniCart = document.querySelector('#cart-preview'); - const countElement = miniCart.querySelector('.cart-preview-count'); - const netElement = miniCart.querySelector('.net'); - const grossElement = miniCart.querySelector('.gross'); - const linkElement = miniCart.querySelector('.checkout-link'); - - if (countElement) { - countElement.innerHTML = count; - } - if (netElement) { - netElement.innerHTML = net; - } - if (grossElement) { - grossElement.innerHTML = gross; - } - - if (linkElement) { - if (count > 0) { - linkElement.style.display = 'block'; - } else { - linkElement.style.display = 'none'; + const miniCarts = document.querySelectorAll('.cart-preview'); + miniCarts.forEach((miniCart) => { + const countElement = miniCart.querySelector('.cart-preview-count'); + const netElement = miniCart.querySelector('.net'); + const grossElement = miniCart.querySelector('.gross'); + const linkElement = miniCart.querySelector('.checkout-link'); + + if (countElement) { + countElement.innerHTML = count; } - } + if (netElement) { + netElement.innerHTML = net; + } + if (grossElement) { + grossElement.innerHTML = gross; + } + if (linkElement) { + if (count > 0) { + linkElement.style.display = 'block'; + } else { + linkElement.style.display = 'none'; + } + } + }); dispatchCustomEvent( 'extcode:minicart-was-updated', diff --git a/Documentation/Changelog/10.0/Breaking-614-AllowMoreThanOneCartPreviewInPage b/Documentation/Changelog/10.0/Breaking-614-AllowMoreThanOneCartPreviewInPage new file mode 100644 index 00000000..ddee569b --- /dev/null +++ b/Documentation/Changelog/10.0/Breaking-614-AllowMoreThanOneCartPreviewInPage @@ -0,0 +1,27 @@ +.. include:: ../../Includes.rst.txt + +======================================================================= +Breaking: #614 - Allow more than one CartPreview (aka minicart) in page +======================================================================= + +See `Issue 614 `__ + +Description +=========== + +The `id` "cart-preview" was removed from the default template file. +The provided JavaScript now uses the `class` "cart-preview" instead of the `id` "cart-preview". + + +Affected Installations +====================== + +All installations using the CartPreview with an own template without the +`class` "cart-preview". + +Migration +========= + +Replace `id` "cart-preview" with `class` "cart-preview" in the CartPreview template. + +.. index:: Frontend diff --git a/Documentation/Changelog/10.0/Feature-614-AllowMoreThanOneCartPreviewInPage b/Documentation/Changelog/10.0/Feature-614-AllowMoreThanOneCartPreviewInPage new file mode 100644 index 00000000..19bfb57a --- /dev/null +++ b/Documentation/Changelog/10.0/Feature-614-AllowMoreThanOneCartPreviewInPage @@ -0,0 +1,21 @@ +.. include:: ../../Includes.rst.txt + +====================================================================== +Feature: #614 - Allow more than one CartPreview (aka minicart) in page +====================================================================== + +See `Issue 614 `__ + +Description +=========== + +You can now integrate several CartPreview plugins (aka minicarts) on one page. +The provided JavaScript now uses the `class` "cart-preview" instead of the `id` "cart-preview". +The `id` "cart-preview" was removed from the default template file. + +Impact +====== + +No direct impact. + +.. index:: Backend, API diff --git a/Documentation/Changelog/10.0/Index.rst b/Documentation/Changelog/10.0/Index.rst index f1afa74d..70df9765 100644 --- a/Documentation/Changelog/10.0/Index.rst +++ b/Documentation/Changelog/10.0/Index.rst @@ -18,3 +18,13 @@ Breaking :glob: Breaking-* + +Features +-------- + +.. toctree:: + :maxdepth: 1 + :titlesonly: + :glob: + + Feature-* diff --git a/Resources/Private/Templates/Cart/CartPreview/Show.html b/Resources/Private/Templates/Cart/CartPreview/Show.html index 1ca91619..0f6145ff 100644 --- a/Resources/Private/Templates/Cart/CartPreview/Show.html +++ b/Resources/Private/Templates/Cart/CartPreview/Show.html @@ -4,7 +4,7 @@ -
+
{cart.count}
@@ -15,4 +15,4 @@
- \ No newline at end of file + diff --git a/Resources/Public/JavaScript/add_to_cart.js b/Resources/Public/JavaScript/add_to_cart.js index 1909e43d..4679d9dc 100644 --- a/Resources/Public/JavaScript/add_to_cart.js +++ b/Resources/Public/JavaScript/add_to_cart.js @@ -83,27 +83,29 @@ const { count } = response; const { net } = response; const { gross } = response; - const miniCart = document.querySelector("#cart-preview"); - const countElement = miniCart.querySelector(".cart-preview-count"); - const netElement = miniCart.querySelector(".net"); - const grossElement = miniCart.querySelector(".gross"); - const linkElement = miniCart.querySelector(".checkout-link"); - if (countElement) { - countElement.innerHTML = count; - } - if (netElement) { - netElement.innerHTML = net; - } - if (grossElement) { - grossElement.innerHTML = gross; - } - if (linkElement) { - if (count > 0) { - linkElement.style.display = "block"; - } else { - linkElement.style.display = "none"; + const miniCarts = document.querySelectorAll(".cart-preview"); + miniCarts.forEach((miniCart) => { + const countElement = miniCart.querySelector(".cart-preview-count"); + const netElement = miniCart.querySelector(".net"); + const grossElement = miniCart.querySelector(".gross"); + const linkElement = miniCart.querySelector(".checkout-link"); + if (countElement) { + countElement.innerHTML = count; } - } + if (netElement) { + netElement.innerHTML = net; + } + if (grossElement) { + grossElement.innerHTML = gross; + } + if (linkElement) { + if (count > 0) { + linkElement.style.display = "block"; + } else { + linkElement.style.display = "none"; + } + } + }); dispatchCustomEvent( "extcode:minicart-was-updated", {