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 effect = campaign.effects.first() 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 if campaign.discount_amount_value: price -= create_price(campaign.discount_amount_value) else: price -= (price * campaign.discount_percentage) 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 if campaign.discount_amount_value: price -= create_price(campaign.discount_amount_value) else: price -= price * campaign.discount_percentage 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