-
I have a sticky add-to-cart button based on
https://www.youtube.com/watch?v=loRbZ2hOzhY
. -
I changed the code of the Dawn 11.0 theme based on the above video and the sticky
add-to-cart
bar is working.
The problem is, when I click the "Add to Cart"
button of the sticky add to cart bar, the slide-out drawer cart does not appear. But when I click the regular "Add to cart"
button on the product page, the slide-out drawer cart appears with animation as it should.
I have done the following but it is not working. If someone can help, it would be great…
-
I have added an asset and called it CartDrawerPull.js
-
For the above script, I added the script reference in the theme. liquid
-
Wrote the following code for capturing
/cart/add
an action for all forms and added an event listener and allowed it to handle default and added animate and active class.
document.querySelectorAll('form[action="/cart/add"]').forEach((form) => {
form.addEventListener("submit", (e) => {
// e.preventDefault();
document.querySelector('.cart-drawer').classList.add ('animate','active');
});
}) ```
2
Answers
Cheers! I could make it work with lot of trial on debugging but not without code from @bryan89tran to whom I a owe big thank. I modified @bryan89tran code after debugging and code I am using is as below now :
Instruct for anyone who wants to replicate
CartDrawerPull.js
CartDrawerPull.js
theme.liquid
has following line<script src="{{ 'CartDrawerPull.js' | asset_url }}" defer="defer"></script>
CartDrawerPull.js
andtheme.liquid
Add to Cart
button is clicked onsticky add to cart bar
, slide out drawer will appear.I am happy for me as I am learning Shopify customisation and this is my third hit.
Below is code for
CartDrawerPull.js
:I just installed a fresh install of dawn 11.0.0.
I am assuming that you still have the asset
cart-notification.js
still configured in the Dawn theme.But the following code works for me.
The
cart.renderContents(response);
is the method that renders the cart drawer. But you need thegetSectionsToRender
to render correctly.Hope this helps!