def discount_price(self, context, product, price_info): """ Get the discounted price for context. Best discount is selected. Minimum price will be selected if the cheapest price is under that. """ create_price = context.shop.create_price shop_product = product.get_shop_instance(context.shop) best_discount = None for campaign in CatalogCampaign.get_matching(context, shop_product): price = price_info.price # get first matching effect for effect in campaign.effects.all(): price -= effect.apply_for_product(context=context, product=product, price_info=price_info) if best_discount is None: best_discount = price if price < best_discount: best_discount = price if best_discount: if shop_product.minimum_price and best_discount < shop_product.minimum_price: best_discount = shop_product.minimum_price if best_discount < create_price("0"): best_discount = create_price("0") price_info.price = best_discount return price_info
def discount_price(self, context, product, price_info): """ Get the discounted price for context. Best discount is selected. Minimum price will be selected if the cheapest price is under that. """ create_price = context.shop.create_price shop_product = product.get_shop_instance(context.shop) best_discount = None for campaign in CatalogCampaign.get_matching(context, shop_product): price = price_info.price # get first matching effect for effect in campaign.effects.all(): price -= effect.apply_for_product(context=context, product=product, price_info=price_info) if best_discount is None: best_discount = price if price < best_discount: best_discount = price if best_discount: if shop_product.minimum_price and best_discount < shop_product.minimum_price: best_discount = shop_product.minimum_price if best_discount < create_price("0"): best_discount = create_price("0") price_info.price = best_discount return price_info
def discount_price(self, context, product, price_info: PriceInfo): """ Get the discounted price for context. Best discount is selected. Minimum price will be selected if the cheapest price is under that. """ create_price = context.shop.create_price shop_product = ShopProduct.objects.filter(shop=context.shop, product=product).first() if not shop_product: return price_info best_discount = None for campaign in CatalogCampaign.get_matching(context, shop_product): price = price_info.price # get first matching effect for effect in campaign.effects.all(): price -= effect.apply_for_product(context=context, product=product, price_info=price_info) if best_discount is None: best_discount = price if price < best_discount: best_discount = price if not best_discount: return price_info if shop_product.minimum_price and best_discount < shop_product.minimum_price: best_discount = shop_product.minimum_price if best_discount < create_price("0"): best_discount = create_price("0") return PriceInfo( best_discount, base_price=price_info.base_price, quantity=price_info.quantity, expires_on=price_info.expires_on, )