Does anyone know the code snippet that can be adde...
# replo-help
l
Does anyone know the code snippet that can be added to Replo to activate the slide out cart drawer on the new Horizon themes?
t
This post is now synced! Check it out here: Activate Slide Out Cart Drawer with Replo Code Snippet ā¤µļø Any future comments will be automatically posted to the thread
Community Guidelines ā–¶ļøŽ Related Discussions 1. Shopify Dawn Theme: Fixing Cart Page Redirect After ATC <!date^1747756265^({ago})> 2. Discussion 2 <!date^1738161763^({ago})> 3. Discussion 3 <!date^1737843946^({ago})> 4. Design and Build a Cart in Replo: Is it Possible? <!date^1723537312^({ago})>
c
Copy code
<script>
  document.addEventListener('DOMContentLoaded', function() {
    var cartButton = document.querySelector('.cart-button');
    var cartDrawer = document.querySelector('.cart-drawer');

    if (cartButton && cartDrawer) {
      cartButton.addEventListener('click', function() {
        cartDrawer.classList.toggle('open');
      });
    }
  });
</script>
Try this one out and let me know if it works! There hasn't been any official documentation around slide out carts for Horizon yet, so will have to test around until something hits šŸ™‚
l
Thanks @Carissa Cui, that isn't working for the version I'm using (Savor, but I presume it is the same across all horizon themes). Please let me know if you find a working version to activate the slide out cart. Thanks!
c
Ok we tested this one, it should work:
Copy code
fetch('/cart.js')
  .then(response => response.json())
  .then(cart => {
    fetch('/?snippets_id=cart-drawer')
      .then(response => response.text())
      .then(text => {
        const sectionInnerHTML = new DOMParser().parseFromString(text, 'text/html');
        const cartFormInnerHTML = sectionInnerHTML.querySelector('cart-items-component').innerHTML;
        document.querySelector('cart-items-component').innerHTML = cartFormInnerHTML;
        document.querySelector('cart-drawer-component > button').click();
        document.querySelector('.cart-bubble__text-count').innerHTML = cart.item_count;
        document.querySelector('cart-icon').classList.add('header-actions__cart-icon--has-cart');
        document.querySelector('.cart-bubble').classList.remove('visually-hidden');
      });
  });
šŸ™Œ 1
l
Works perfectly thank you @Carissa Cui!!
šŸ™Œ 1