微信小程序商品加入购物车逻辑

微信小程序商品加入购物车js里逻辑是什么样的
新人刚入小程序

    请路过的大佬 解释下!!!  
    需要调用小程序端的API吗?getStorageSync
    不是很明白。

    找的源码:
        cart:function(e){//加入购物车
        var that=this;
        var id = e.currentTarget.dataset.id;
        var userId = wx.getStorageSync('userId');
        if (userId != null && userId > 0 && userId != '') {
            that.addCart(id, userId, that.data.quantity, 1, e.currentTarget.dataset.unit);
        }else{
            wx.showModal({
                title: '温馨提示',
                content: '先登录',
                success: function (res) {
                    if (res.confirm) {
                        wx.navigateTo({
                            url: '/pages/mine/mine',
                        })
                    } else if (res.cancel) {
                    }
                }
            })
        }
    }

图片说明

getStorageSync 是获取小程序之前存储的 userId 通过 wx.getStorageSync('userId') 赋给变量 var userId
至于

if (userId != null && userId > 0 && userId != '') {
            that.addCart(id, userId, that.data.quantity, 1, e.currentTarget.dataset.unit); //这里是添加购物车的 另一个addCart方法函数
 }