You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from oscar.apps.offer import models
  2. class AlphabetRange(object):
  3. name = "Products that start with D"
  4. def contains_product(self, product):
  5. return product.title.startswith('D')
  6. def num_products(self):
  7. return None
  8. class BasketOwnerCalledBarry(models.Condition):
  9. name = "User must be called barry"
  10. class Meta:
  11. proxy = True
  12. def is_satisfied(self, basket):
  13. if not basket.owner:
  14. return False
  15. return basket.owner.first_name.lower() == 'barry'
  16. def can_apply_condition(self, product):
  17. return False
  18. def consume_items(self, basket, affected_lines):
  19. return
  20. class ChangesOwnerName(models.Benefit):
  21. class Meta:
  22. proxy = True
  23. def apply(self, basket, condition, offer=None):
  24. condition.consume_items(basket, ())
  25. return models.PostOrderAction(
  26. "You will have your name changed to Barry!")
  27. def apply_deferred(self, basket, order, application):
  28. if basket.owner:
  29. basket.owner.first_name = "Barry"
  30. basket.owner.save()
  31. return "Name changed to Barry!"
  32. return "We tried to apply benefit but couldn't"
  33. @property
  34. def description(self):
  35. return "Changes owners name"