LFS order numbers generator is pluggable. In this tutorial you will learn how to add an own one.
Please see also the complete example application or refer to the default implementation of LFS within lfs_order_numbers.
First you need to create a default Django application (or use an existing one). If you do not know how to do this, please refer to the excellent Django tutorial.
The structure of the application should look at least like this:
my_order_numbers
__init__.py
models.py
Within models.py file of your application create a class called OrderNumberGenerator which inherits from LFS’ OrderNumberGenerator base class and add a method to it called get_next:
from lfs.plugins import OrderNumberGenerator as Base
class OrderNumberGenerator(Base):
def get_next(formatted):
return "DOE-4711"
The get_next method is called when the shop customer submits a new order. It must return a character value which will become the order number of the new order.
Now as the code is ready, you can easily plugin your payment method:
Add your application to the PYTHONPATH.
Add your class to settings.py
LFS_ORDER_NUMBER_GENERATOR = “my_order_numbers.models.OrderNumberGenerator”
Add the form to settings.py
LFS_ORDER_NUMBER_GENERATOR_FORM = “my_order_numbers.forms.OrderNumberGeneratorForm”
Add your application to settings.INSTALLED_APPS and sync the database.
You should now see your form within the Order Numbers tab within Shop/Preference and the get_next method of your model should be called to generate a new order number.
Optionally you can add your own HTML for the management interface. For this just add the order_numbers_tab.html template to your application:
my_order_numbers
templates
manage
order_numbers
order_numbers_tab.html
Please refer to the standard template of LFS to get more details. You can find this on following place:
lfs/templates/manage/order_numbers/order_numbers_tab.html
In this case please make sure that your my_order_numbers application stands before lfs within INSTALLED_APPS of settings.py so that LFS’ default order_numbers_tab.html template is overwritten.
Within the get_next method of your new class you have access to following information:
Please note that you have also access to the products of the order via the items attribute. For instance:
for item in self.order.items.all():
product = item.product
See the also the Order and OrderItem classes for more information.