Shopify/Timber

Load ajax cart on page load not on click of open cart drawer

Opened this issue · 4 comments

Hi,

I am trying to look at the best solution to loading the cart template into a container when the page loads as opposed to when click on open cart drawer.

Are there any options or solutions for this?

Cam commented

I am not sure it would be a good idea to do that. But you certainly could. You would need to modify the following files to suit: ajax-cart.js.liquid, ajax-cart-template.liquid and modify the script at the bottom of the theme.liquid layout file so that "timber.RightDrawer.open();" updates your inline cart instead.

@Cam, thank you for chiming in! I looked all over the internet for this. Essentially, loading ajax cart on page load (rather than on open cart drawer) allows a user to view the items in the cart without having to click on anything. I am working on a very common implementation that will show the ajaxified cart in a drop down menu that just fades in when hovering the Cart link, rather than clicking on a link to display the cart. The problem I am having is the same as that the DOM is not populated with the ajaxified cart until the cart button is clicked on. How does one instantiates the ajax cart without the toggle cart button?

(The suggested workaround shown on this thread: #265 seems very simple but I could not make it work - and the link from Carson no longer works.)

@mdunbavan, where you able to find a way to create the ajaxified cart on load?

I'm looking to do the same, load cart on page load, any ideas? @sydneykaiserman did you manage to do this and how?

@MatthewKennedy I was able to do it by calling this in the page load:

ajaxCart.load();
timber.RightDrawer.open()

Hope it helps.