Ad

How To Use Timber.RightDrawer.open(); In Custom Add To Cart Success To Open Drawer?

- 1 answer

I am using add to cart with custom ajax code and its working fine, problem is I need to open cart drawer on success function by using timber.RightDrawer.open(); For now I am using "js-drawer-open-right" class in form but its open drawer same time when click on add to cart button. I need to open drawer on success of add to cart.

My Ajax code is:

                function addItem(button) {
                var postData = $(button).closest('.add-to-cart').serialize();
                  $.ajax({
                    type: 'POST',
                    url: '/cart/add.js',
                    dataType: 'json',
                    data: postData,
                    success: addToCartOk,
                    error: addToCartFail
                  });
                }
                function addToCartOk(product) {
                //Want to open drawer here on success
                  timber.RightDrawer.open();
                }
                function addToCartFail(obj, status) {
                }

My form is:

Here you can check Add to Cart https://soft-theme.myshopify.com/collections/all

Ad

Answer

I have find out different and very easy solution for this as compare to timber.RightDrawer.open();

I have clicked "js-drawer-open-right" with jQuery in success function and removed that class from form which I have placed before.

The success function now is:

         function addToCartOk(product) {
            //drawer open here by click on that class on success
              jQuery('.js-drawer-open-right').click();
            }

Its worked perfectly fine.

Ad
source: stackoverflow.com
Ad