Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 1.54 KB

basket_modifiers.rst

File metadata and controls

48 lines (33 loc) · 1.54 KB

Basket modifiers

Sometimes we need to add extra charges or discounts to the basket and its items. This is done using basket modifiers which allow for manipulation of both the items individually and the basket itself. When a custom modifier is defined it can choose to process the basket or item or both.

Modifiers are registered in SALESMAN_BASKET_MODIFIERS setting and should be formatted as a list of dotted paths to a class extending salesman.basket.modifiers.BasketModifier class.

Note

For this example, we assume your custom app is named shop.

Create modifiers

A unique identifier property is required to be set on modifiers. To add extra rows to basket or items individually use salesman.basket.modifiers.BasketModifier.add_extra_row method. Eg:

/../example/shop/modifiers/basic.py

A more complex modifier

Basket modifiers support additional hooks that allow for more control.

/../example/shop/modifiers/complex.py

Register modifiers

Register modifiers in your settings.py, ordering is preserved when processing:

SALESMAN_BASKET_MODIFIERS = [
    'shop.modifiers.DiscountModifier',
    'shop.modifiers.SpecialTaxModifier',
    'shop.modifiers.ShippingCostModifier',
    'shop.modifiers.ComplexModifier',
]

Your basket will now contain extra rows when needed. They will appear as extra_rows list field on both the basket and its items.