I’m using the new Horizon 2025 theme and I’m building a custom “Frequently Bought Together” section. It allows customers to select multiple products and add them all to the cart via JavaScript using the /cart/add.js endpoint.
The products are being added successfully to the cart, but I’m having trouble making the Cart Drawer open AND refresh its contents after multiple products are added.
From the theme’s code, I can see there’s a <cart-drawer-component> and it listens to a custom CartAddEvent, but I’m unsure how to properly trigger that event or update the drawer state programmatically.
How can I programmatically open and refresh the Cart Drawer in the Horizon 2025 theme after adding multiple products with JavaScript?**
Ideally, I’d like to use the theme’s native method or dispatch event to keep everything consistent.
Any help or insight would be greatly appreciated. Thanks in advance!
This solution works, however, it doesn’t wait for the cart-drawer contents to update before opening the drawer. Any idea how this can be modified? This seems true for both CartUpdateEvent and CartAddEvent.
@_vi@Luis_Rojas
use horizon theme built-in event handling for forms.
For simplicity, just wrap your form inside the theme’s web component and add the default submit handler. That’s all you need, it’ll automatically handle ajax submission and open the cart drawer for you.
<product-form-component on:submit="/handleSubmit">
{% form 'product', product %}
// Your inputs
{% endform %}
</product-form-component>
Is there any documentation available that explains the JavaScript logic for the Horizon theme, or is the GitHub repo the only source to analyze? I want to implement Horizon, but I need to check what exactly I can do there using the built-in event handling.