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.

how_to_configure_stock_messaging.rst 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ================================
  2. How to configure stock messaging
  3. ================================
  4. Stock messaging is controlled on a per-partner basis. A product's stockrecord
  5. has the following methods for messaging:
  6. .. autoclass:: oscar.apps.partner.abstract_models.AbstractStockRecord
  7. :members: availability, availability_code
  8. :noindex:
  9. Both these methods delegate to a "partner wrapper" instance. These are defined
  10. in the ``OSCAR_PARTNER_WRAPPERS`` setting which is a dict mapping from partner
  11. code to a class path, for instance::
  12. # settings.py
  13. OSCAR_PARTNER_WRAPPERS = {
  14. 'partner-a': 'myproject.wrappers.PartnerAWrapper',
  15. }
  16. The default wrapper is :class:`oscar.apps.partner.wrappers.DefaultWrapper`,
  17. which provides methods of the same name.
  18. .. autoclass:: oscar.apps.partner.wrappers.DefaultWrapper
  19. :members: availability, availability_code
  20. :noindex:
  21. Custom wrappers should subclass this class and override the appropriate methods.
  22. Here's an example wrapper that provides custom availability messaging::
  23. # myproject/wrappers.py
  24. from oscar.apps.partner import wrappers
  25. class PartnerAWrapper(wrappers.DefaultWrapper):
  26. def availability(self, stockrecord):
  27. if stockrecord.net_stock_level > 0:
  28. return "Available to buy now!"
  29. return "Sorry, not available"
  30. def availability_code(self, stockrecord):
  31. if stockrecord.net_stock_level > 0:
  32. return "icon_tick"
  33. return "icon_cross"