class Applicator utils Applicator def apply self request basket Apply

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Applicator(utils.Applicator):
def apply(self, request, basket):
"""
Apply all relevant offers to the given basket.
The request is passed too as sometimes the available offers
are dependent on the user (eg session-based offers).
"""
checkout_session = CheckoutSessionData(request)
code = checkout_session.shipping_method_code(basket)
offers = self.get_offers(request, basket)
def compare(offer):
if offer.condition.name == u'User must choose takeaway shipping' \
and code != "takeaway":
return False
else:
return True
offers = filter(compare, offers)
self.apply_offers(basket, offers)