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

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. Both these methods delegate to a "partner wrapper" instance. These are defined
  9. in the ``OSCAR_PARTNER_WRAPPERS`` setting which is a dict mapping from partner
  10. name to a class path, for instance::
  11. # settings.py
  12. OSCAR_PARTNER_WRAPPERS = {
  13. 'Partner A': 'myproject.wrappers.PartnerAWrapper',
  14. }
  15. The default wrapper is :class:`oscar.apps.partner.wrappers.DefaultWrapper`,
  16. which provides methods of the same name.
  17. .. autoclass:: oscar.apps.partner.wrappers.DefaultWrapper
  18. :members: availability, availability_code
  19. Custom wrappers should subclass this class and override the appropriate methods.
  20. Here's an example wrapper that provides custom availability messaging::
  21. # myproject/wrappers.py
  22. from oscar.apps.partner import wrappers
  23. class PartnerAWrapper(wrappers.DefaultWrapper):
  24. def availability(self, stockrecord):
  25. if stockrecord.net_stock_level > 0:
  26. return "Available to buy now!"
  27. return "Sorry, not available"
  28. def availability_code(self, stockrecord):
  29. if stockrecord.net_stock_level > 0:
  30. return "icon_tick"
  31. return "icon_cross"