示例#1
0
    def get_new_lines(self, order_source, lines):
        price_so_far = sum((x.price for x in lines), order_source.zero_price)

        def get_discount_line(campaign, amount, price_so_far):
            new_amount = min(amount, price_so_far)
            price_so_far -= new_amount
            return self._get_campaign_line(campaign, new_amount, order_source)

        best_discount = None
        best_discount_campaign = None
        for campaign in BasketCampaign.get_matching(order_source, lines):
            if campaign.discount_amount:
                discount_amount = campaign.discount_amount
            else:
                discount_amount = order_source.total_price_of_products * campaign.discount_percentage

            # if campaign has coupon, match it to order_source.codes
            if campaign.coupon:
                # campaign was found because discount code matched. This line is always added
                yield get_discount_line(campaign, discount_amount, price_so_far)
            elif best_discount is None or discount_amount > best_discount:
                best_discount = discount_amount
                best_discount_campaign = campaign

        if best_discount is not None:
            yield get_discount_line(best_discount_campaign, best_discount, price_so_far)
示例#2
0
文件: modules.py 项目: teserak/shoop
    def get_new_lines(self, order_source, lines):
        price_so_far = sum((x.price for x in lines), order_source.zero_price)

        def get_discount_line(campaign, amount, price_so_far):
            new_amount = min(amount, price_so_far)
            price_so_far -= new_amount
            return self._get_campaign_line(campaign, new_amount, order_source)

        best_discount = None
        best_discount_campaign = None
        for campaign in BasketCampaign.get_matching(order_source, lines):
            if campaign.discount_amount:
                discount_amount = campaign.discount_amount
            else:
                discount_amount = order_source.total_price_of_products * campaign.discount_percentage

            # if campaign has coupon, match it to order_source.codes
            if campaign.coupon:
                # campaign was found because discount code matched. This line is always added
                yield get_discount_line(campaign, discount_amount,
                                        price_so_far)
            elif best_discount is None or discount_amount > best_discount:
                best_discount = discount_amount
                best_discount_campaign = campaign

        if best_discount is not None:
            yield get_discount_line(best_discount_campaign, best_discount,
                                    price_so_far)
示例#3
0
文件: modules.py 项目: JSin/shuup
    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
示例#4
0
    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