Unable to use app.featuresAvailable(Group.Cart)

Unable to use app.featuresAvailable(Group.Cart)

sunriseshoapeng
Shopify Partner
2 0 0

Hi,

Recently with the 7.0 update on the pos, our current app broke. After investigating and asking Shopify, I was directed to using the code snippet below. But after implementing this on the client side, index page. I am constantly receiving the error of 

UnhandledPromiseRejectionWarning: AppBridgeError: APP::APP_ERROR::WINDOW_UNDEFINED: Feature detection is only available on the client side.

Even though I am using this on client side. Any ideas how to get this functionality working? I need to be able to fetch cart on app load, so the idea would be to grab cart on index.

var cart = AppBridge.actions.Cart.create(App);
cart.subscribe(AppBridge.actions.Cart.Action.UPDATE, function (payload) {
    alert('Fetched');
});

var cartFeaturesAvailable = new Promise((resolve) => {
    function checkCartFeatures() {
        return App.featuresAvailable(AppBridge.actions.Group.Cart).then(function (state) {
            var _ref = state.Cart && state.Cart[AppBridge.actions.Cart.Action.FETCH]
                , Dispatch = _ref.Dispatch;
            if (Dispatch) {
                resolve();
            }
            return Dispatch;
        });
    }

    checkCartFeatures().then(function (isCartAvailable) {
        if (isCartAvailable) return;
        App.subscribe(AppBridge.actions.Features.Action.UPDATE, function () {
            checkCartFeatures().then(function (isCartAvailable) {
                if (isCartAvailable) return;
                window.alert('Not fetched');
            });
        });
    });
});

// This can be call multiple times whenever you need to fetch cart because the cartFeaturesAvailable promise is resolved
cartFeaturesAvailable.then(function () {
    cart.dispatch(AppBridge.actions.Cart.Action.FETCH);
});

 
Thanks

Sunrise Integration -
Replies 0 (0)