コード例 #1
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()
コード例 #2
0
    def test_02_awesome_option_increases_price_by_its_value(self):
        self.create_fixtures()

        c_item_option = CartItemOption()
        c_item_option.option = self.option
        c_item_option.cartitem = self.cartitem
        c_item_option.save()

        MODIFIERS = ["shop.cart.modifiers.product_options.ProductOptionsModifier"]
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            self.cart.update()
            self.cart.save()
            sub_should_be = (1 * self.PRODUCT_PRICE) + (1 * self.AWESOME_OPTION_PRICE)
            total_should_be = sub_should_be

            self.assertEqual(self.cart.subtotal_price, sub_should_be)
            self.assertEqual(self.cart.total_price, total_should_be)
コード例 #3
0
    def test_02_awesome_option_increases_price_by_its_value(self):
        self.create_fixtures()

        c_item_option = CartItemOption()
        c_item_option.option = self.option
        c_item_option.cartitem = self.cartitem
        c_item_option.save()

        MODIFIERS = ['shop_simplevariations.cart_modifier.ProductOptionsModifier']
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            self.cart.update()
            self.cart.save()
            sub_should_be = (1*self.PRODUCT_PRICE) + (1*self.AWESOME_OPTION_PRICE)
            total_should_be = sub_should_be

            self.assertEqual(self.cart.subtotal_price, sub_should_be)
            self.assertEqual(self.cart.total_price, total_should_be)
コード例 #4
0
    def test03_quantity_should_be_used_by_modifier(self):
        quantity = 2
        self.create_fixtures(quantity=quantity)

        c_item_option = CartItemOption()
        c_item_option.option = self.option
        c_item_option.cartitem = self.cartitem
        c_item_option.save()

        MODIFIERS = ["shop_simplevariations.cart_modifier.ProductOptionsModifier"]
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            self.cart.update()
            self.cart.save()
            sub_should_be = (quantity * self.PRODUCT_PRICE) + (quantity * self.AWESOME_OPTION_PRICE)
            total_should_be = sub_should_be

            self.assertEqual(self.cart.subtotal_price, sub_should_be)
            self.assertEqual(self.cart.total_price, total_should_be)
コード例 #5
0
    def test03_quantity_should_be_used_by_modifier(self):
        quantity = 2
        self.create_fixtures(quantity=quantity)

        c_item_option = CartItemOption()
        c_item_option.option = self.option
        c_item_option.cartitem = self.cartitem
        c_item_option.save()

        MODIFIERS = ['shop_simplevariations.cart_modifier.ProductOptionsModifier']
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):
            self.cart.update()
            self.cart.save()
            sub_should_be = (quantity*self.PRODUCT_PRICE) \
                          + (quantity*self.AWESOME_OPTION_PRICE)
            total_should_be = sub_should_be

            self.assertEqual(self.cart.subtotal_price, sub_should_be)
            self.assertEqual(self.cart.total_price, total_should_be)