from oscar apps shipping import repository methods from oscar apps off

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from oscar.apps.shipping import repository, methods
from oscar.apps.offer import models
from oscar.apps.offer.custom import create_condition
class TakeAway(models.Condition):
name = "User must be called barry"
class Meta:
proxy = True
def is_satisfied(self, offer, basket):
print offer
return True
create_condition(TakeAway)
# We create subclasses so we can give them different codes and names
class Standard(methods.Free):
code = 'delivery'
name = "Delivery shipping"
class Express(methods.Free):
code = 'takeaway'
name = "Takeaway shipping"
class Repository(repository.Repository):
methods = [Standard(), Express()]
def get_shipping_methods(self, user, basket, shipping_addr=None, **kwargs):
return self.prime_methods(basket, self.methods)
def find_by_code(self, code, basket):
for method in self.methods:
if code == method.code:
return self.prime_method(basket, method)