def apply_for_basket(self, order_source): from shuup.campaigns.models import CatalogCampaign discounted_base_amount = order_source.total_price_of_products context = PricingContext(order_source.shop, order_source.customer) for line in order_source.get_product_lines(): product = line.product if CatalogCampaign.get_matching( context, product.get_shop_instance(order_source.shop)): discounted_base_amount -= line.price return (discounted_base_amount * self.value)
def matches(self, basket, lines): from shuup.campaigns.models import CatalogCampaign total_undiscounted_price_value = basket.total_price_of_products.value shop = basket.shop context = PricingContext(shop, basket.customer) for line in basket.get_product_lines(): if CatalogCampaign.get_matching( context, line.product.get_shop_instance(shop)): total_undiscounted_price_value -= line.price.value return (total_undiscounted_price_value >= self.amount_value)
def get_context_data(product): ctx = {} for shop in Shop.objects.all(): try: shop_product = product.get_shop_instance(shop) except ShopProduct.DoesNotExist: continue ctx[shop] = { "basket_campaigns": BasketCampaign.get_for_product(shop_product), "catalog_campaigns": CatalogCampaign.get_for_product(shop_product) } return ctx
def get_context_data(cls, product, request=None): ctx = {} shop = request.shop try: shop_product = product.get_shop_instance(shop) except ShopProduct.DoesNotExist: return ctx ctx[shop] = { "basket_campaigns": BasketCampaign.get_for_product(shop_product), "catalog_campaigns": CatalogCampaign.get_for_product(shop_product) } return ctx
def apply_for_basket(self, order_source): from shuup.campaigns.models import CatalogCampaign campaign = self.campaign supplier = campaign.supplier if hasattr(campaign, "supplier") and campaign.supplier else None discounted_base_amount = get_total_price_of_products(order_source, campaign) context = PricingContext(order_source.shop, order_source.customer) for line in order_source.get_product_lines(): if supplier and line.supplier != supplier: continue product = line.product if CatalogCampaign.get_matching(context, product.get_shop_instance(order_source.shop)): discounted_base_amount -= line.price return (discounted_base_amount * self.value)
def apply_for_basket(self, order_source): from shuup.campaigns.models import CatalogCampaign campaign = self.campaign supplier = campaign.supplier if hasattr(campaign, "supplier") and campaign.supplier else None discounted_base_amount = get_total_price_of_products(order_source, campaign) context = PricingContext(order_source.shop, order_source.customer) for line in order_source.get_product_lines(): if supplier and line.supplier != supplier: continue product = line.product if CatalogCampaign.get_matching(context, product.get_shop_instance(order_source.shop)): discounted_base_amount -= line.price return discounted_base_amount * self.value
def matches(self, basket, lines): from shuup.campaigns.models import CatalogCampaign campaign = self.campaign.first() total_of_products = get_total_price_of_products(basket, campaign) product_lines = basket.get_product_lines() if hasattr(campaign, "supplier") and campaign.supplier: product_lines = [line for line in product_lines if line.supplier == campaign.supplier] total_undiscounted_price_value = total_of_products.value shop = basket.shop context = PricingContext(shop, basket.customer) for line in product_lines: if CatalogCampaign.get_matching(context, line.product.get_shop_instance(shop)): total_undiscounted_price_value -= line.price.value return (total_undiscounted_price_value >= self.amount_value)
def matches(self, basket, lines): from shuup.campaigns.models import CatalogCampaign campaign = self.campaign.first() total_of_products = get_total_price_of_products(basket, campaign) product_lines = basket.get_product_lines() if hasattr(campaign, "supplier") and campaign.supplier: product_lines = [ line for line in product_lines if line.supplier == campaign.supplier ] total_undiscounted_price_value = total_of_products.value shop = basket.shop context = PricingContext(shop, basket.customer) for line in product_lines: if CatalogCampaign.get_matching( context, line.product.get_shop_instance(shop)): total_undiscounted_price_value -= line.price.value return (total_undiscounted_price_value >= self.amount_value)