def test_product_basket_campaigns2(): shop = get_default_shop() product = create_product("test", shop, default_price=20) shop_product = product.get_shop_instance(shop) campaign = BasketCampaign.objects.create(active=True, shop=shop, name="test") condition = ProductsInBasketCondition.objects.create(quantity=1) campaign.conditions.add(condition) assert BasketCampaign.get_for_product(shop_product).count() == 0 condition.products.add(product) assert BasketCampaign.get_for_product(shop_product).count() == 1 shop1 = Shop.objects.create(name="testshop", identifier="testshop", status=ShopStatus.ENABLED, public_name="testshop") sp = ShopProduct.objects.create(product=product, shop=shop1, default_price=shop1.create_price(200)) campaign.shop = shop1 campaign.save() assert BasketCampaign.get_for_product(shop_product).count() == 0 assert BasketCampaign.get_for_product(sp).count() == 1
def test_product_basket_campaigns(): shop = get_default_shop() product = create_product("test", shop, default_price=20) shop_product = product.get_shop_instance(shop) cat = Category.objects.create(name="test") campaign = BasketCampaign.objects.create(active=True, shop=shop, name="test") # no rules assert BasketCampaign.get_for_product(shop_product).count() == 0 # category condition that doesn't match cat_condition = CategoryProductsBasketCondition.objects.create(category=cat) campaign.conditions.add(cat_condition) assert BasketCampaign.get_for_product(shop_product).count() == 0 # category condition that matches shop_product.categories.add(cat) assert BasketCampaign.get_for_product(shop_product).count() == 1 # category effect that doesn't match effect = DiscountFromCategoryProducts.objects.create(campaign=campaign, category=cat) shop_product.categories.remove(cat) campaign.line_effects.add(effect) assert BasketCampaign.get_for_product(shop_product).count() == 0 # category effect and condition that matches shop_product.primary_category = cat shop_product.save() assert BasketCampaign.get_for_product(shop_product).count() == 1
def test_product_basket_campaigns(): shop = get_default_shop() product = create_product("test", shop, default_price=20) shop_product = product.get_shop_instance(shop) cat = Category.objects.create(name="test") campaign = BasketCampaign.objects.create(active=True, shop=shop, name="test") # no rules assert BasketCampaign.get_for_product(shop_product).count() == 0 # category condition that doesn't match cat_condition = CategoryProductsBasketCondition.objects.create( category=cat) campaign.conditions.add(cat_condition) assert BasketCampaign.get_for_product(shop_product).count() == 0 # category condition that matches shop_product.categories.add(cat) assert BasketCampaign.get_for_product(shop_product).count() == 1 # category effect that doesn't match effect = DiscountFromCategoryProducts.objects.create(campaign=campaign, category=cat) shop_product.categories.remove(cat) campaign.line_effects.add(effect) assert BasketCampaign.get_for_product(shop_product).count() == 0 # category effect and condition that matches shop_product.primary_category = cat shop_product.save() assert BasketCampaign.get_for_product(shop_product).count() == 1
def get_new_lines(self, order_source, lines): matching_campaigns = BasketCampaign.get_matching(order_source, lines) for line in self._handle_total_discount_effects(matching_campaigns, order_source, lines): yield line for line in self._handle_line_effects(matching_campaigns, order_source, lines): yield line
def get_new_lines(self, order_source, lines): matching_campaigns = BasketCampaign.get_matching(order_source, lines) for line in self._handle_line_effects(matching_campaigns, order_source, lines): yield line # total discounts must be run after line effects since lines can be changed in place for line in self._handle_total_discount_effects(matching_campaigns, order_source, lines): yield line
def get_new_lines(self, order_source, lines): matching_campaigns = BasketCampaign.get_matching(order_source, lines) for line in self._handle_total_discount_effects( matching_campaigns, order_source, lines): yield line for line in self._handle_line_effects(matching_campaigns, order_source, lines): yield line