Javascript Events - Sidecart Show

Hi,

We've followed the guidance here: https://wiki.foxycart.com/v/2.0/javascript

We simply we want to execute some custom JQuery when the side cart is shown... we've added the following to an external JS file (not within document ready).

var FC = FC || {};
FC.onLoad = function () {
FC.client.on("sidecart-show", function (params, next) {
alert("Show side cart");
});
};

The alert is fired but then the side cart doesn't load... what are we doing wrong?

We did also try:

FC.client.on("render.done", function (params) {
alert("render done");
});

But this is fired three to four times...

Any ideas?

Thanks
Comments
  • fc_adamfc_adam FoxyCart Team
    edited October 23
    @BLJ,

    You're really close there. Your first approach is how you'd want to do it, except without the "next" parameter. When that's included, it makes your callback function async, and so you have to call next(); for the event to continue.

    If you don't need it async, your code would just want to be this:
    var FC = FC || {};
    FC.onLoad = function () {
    FC.client.on("sidecart-show", function (params) {
    alert("Show side cart");
    });
    };
    If you wanted to only run after the sidecart has shown, you can do that by making the event sidecart-show.done too.
  • BLJBLJ Member
    Thanks Adam, brilliant!

    All sorted... we're running some logic to show / hide the paypal checkout icons based on whether the shipping options have been confirmed.

    FC.client.on("cart-shipping-options-update.done", function (params) {
    $shippingVal = $(".fc-transaction__shipping").find(".fc-subtotal__value").text().trim();
    if ($shippingVal != "TBD") { $(".fc-action--payment--or").show("slow");
    $(".fc-action--payment--paypal-ec").show("slow");
    });
Sign In or Register to comment.