コード例 #1
0
    def post_success(self, product, cart_item):
        super(SimplevariationCartDetails, self).post_success(product, cart_item)
        # if no cart_item was added, just skip
        if cart_item is None:
            return self.success()
        #if this cart item already has an option set we don't need to do
        #anything because an existing option set will never change. if we got a
        #set of different options, that would become a new CartItem.
        if cart_item.cartitemoption_set.exists():
            return self.success()

        post = self.request.POST
        for key in self.request.POST.keys():
            if key.startswith('add_item_option_group_'):
                option = Option.objects.get(pk=int(post[key]))
                cartitem_option = CartItemOption()
                cartitem_option.cartitem = cart_item
                cartitem_option.option = option
                cartitem_option.save()
            elif key.startswith('add_item_text_option_'):
                id = key.split('add_item_text_option_')[1]
                txt = self.request.POST[key]
                if txt != '':
                    txt_opt = TextOption.objects.get(pk=id)
                    cito = CartItemTextOption()
                    cito.text_option = txt_opt
                    cito.text = txt
                    cito.cartitem = cart_item
                    cito.save()
                
        return self.success()
コード例 #2
0
    def post_success(self, product, cart_item):
        super(SimplevariationCartDetails, self).post_success(product, cart_item)
        #if this cart item already has an option set we don't need to do
        #anything because an existing option set will never change. if we got a
        #set of different options, that would become a new CartItem.
        if cart_item.cartitemoption_set.exists():
            return self.success()

        post = self.request.POST
        for key in self.request.POST.keys():
            if key.startswith('add_item_option_group_'):
                option = Option.objects.get(pk=int(post[key]))
                cartitem_option = CartItemOption()
                cartitem_option.cartitem = cart_item
                cartitem_option.option = option
                cartitem_option.save()
            elif key.startswith('add_item_text_option_'):
                id = key.split('add_item_text_option_')[1]
                txt = self.request.POST[key]
                if txt != '':
                    txt_opt = TextOption.objects.get(pk=id)
                    cito = CartItemTextOption()
                    cito.text_option = txt_opt
                    cito.text = txt
                    cito.cartitem = cart_item
                    cito.save()
                
        return self.success()
コード例 #3
0
    def post_success(self, product, cart_item, post=None):
        super(SimplevariationCartDetails, self).post_success(product, cart_item)
        #if this cart item already has an option set we don't need to do
        #anything because an existing option set will never change. if we got a
        #set of different options, that would become a new CartItem.
        if cart_item.cartitemoption_set.exists():
            return self.success()

        post = self.request.POST
        for key in post.keys():
            if key.startswith(option_group_name_prefix):
                pk = post[key]
                if not pk:
                    # blank option group was already validated
                    # and allowed by the time this point
                    # is reached, so just skip it
                    continue
                data = parse_option_group_name(key)
                group = OptionGroup.objects.get(pk=data["pk"])
                option = Option.objects.get(pk=pk)
                cartitem_option = CartItemOption()
                cartitem_option.cartitem = cart_item
                cartitem_option.option = option
                cartitem_option.group = group
                cartitem_option.choice = data["choice"]
                cartitem_option.save()
            elif key.startswith('add_item_text_option_'):
                txt = post[key]
                if not txt:
                    # blank text option was already validated
                    # and allowed by the time this point
                    # is reached, so just skip it
                    continue
                pk = key.split('add_item_text_option_')[1]
                txt_opt = TextOption.objects.get(pk=pk)
                cito = CartItemTextOption()
                cito.text_option = txt_opt
                cito.text = txt
                cito.cartitem = cart_item
                cito.save()
                
        return self.success()