购物车不能正常工作

时间:2016-12-21 18:34:33

标签: javascript jquery

购物车代码:

class TeamSettingsForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super(TeamSettingsForm, self).__init__(*args, **kwargs)

        slack = Slacker(kwargs['instance'].access_token)

        priv_ch = [(g['id'], g['name']) for g in slack.groups.list().body['groups'] if not g['is_archived']]
        pub_ch = [(c['id'], c['name']) for c in slack.channels.list().body['channels'] if not c['is_archived']]
        users = [(u['id'], u['profile']['real_name']) for u in slack.users.list().body['members'] if not u['deleted']]

        self.fields['post_channel'].widget.choices=tuple(pub_ch)
        self.fields['approval_channel'].widget.choices=tuple(pub_ch + priv_ch + users)

    class Meta:
        model = Team
        fields = ['post_channel', 'approval_channel', 'admin_only_approval',
                  'admin_only_edit']
        widgets = {
            'post_channel':  forms.ChoiceField,
            'approval_channel': forms.ChoiceField
        }

我有这个持久性错误,在重新加载时,它不会保存我所做的更改。所以,例如,我已经订购了2个价值一些的飞盘(现在没关系),但是当刷新它,点击订购某个产品时,购物车不会保存更改,即使它是假设的至。我不确定问题出在哪里,所以我把这一切粘在了这里。

1 个答案:

答案 0 :(得分:0)

当您增加购物车中已有商品的数量时,您永远不会将商品保存到localstorage。

    function addItemToCart(name, price, count) {
        for (var i in cart) {
            if (cart[i].name === name) {
                cart[i].count += count;
                //need to do this here too.
                saveCart();
                //
                return;
            }
        }
        var item = new Item(name, price, count);
        cart.push(item);
        saveCart();
    }

否则它只会在添加新项目时将购物车保存到localstorage,因此在此之前,递增的项目不会保存到存储中。