shop.services

Submodules

Attributes

Classes

Event

Defines the available events used within the system.

EventService

Customization

Abstract base class for own implementations.

Hook

The hook'able events / actions.

HookService

Note: Methods should be called only with positional arguments. Or keyword-only if really necessary.

Functions

on_event(event)

Package Contents

shop.services.EVENT_SERVICE
class shop.services.Event

Bases: enum.IntEnum

Defines the available events used within the system.

This enumeration serves as the central registry for all predefined events that can be triggered and observed by the EventService.

Initialize self. See help(type(self)) for accurate signature.

ARTICLE_CHANGED

Triggered when an article inside the cart (leaf) changed.

CART_CHANGED

Triggered when a cart (node) changed.

ORDER_CHANGED

Triggered when an order changed.

CHECKOUT_STARTED

Triggered when a user begins the checkout process.

ORDER_ORDERED

Triggered when a user confirmed the order (“order now”) in the final checkout step.

ORDER_PAID

Triggered when payment for an order is completed.

ORDER_RTS

Triggered when an order is marked as ready to ship (RTS).

class shop.services.EventService
observer: Final[dict[[Event, list[Callable]]]]
register(event, func)
Parameters:
  • event (Event)

  • func (Callable)

Return type:

Callable

unregister(func, event=None)
Parameters:
  • func (Callable)

  • event (Event)

Return type:

None

call(_event, _raise_errors=False, *args, **kwargs)
Parameters:
  • _event (Event)

  • _raise_errors (bool)

Return type:

None

shop.services.on_event(event)
Parameters:

event (Event)

Return type:

Callable

class shop.services.Customization

Bases: abc.ABC

Abstract base class for own implementations.

property kind: Hook
Abstractmethod:

Return type:

Hook

The action this implementation is for

abstract __call__(*args, **kwargs)

The main logic of this implementation

Return type:

Any

__repr__()
Return type:

str

classmethod from_method(func, kind)

Just a handy variant to define an implementation without a class definition

Parameters:
  • func (Callable)

  • kind (Hook)

Return type:

Self

shop.services.HOOK_SERVICE
class shop.services.Hook

Bases: enum.IntEnum

The hook’able events / actions.

Initialize self. See help(type(self)) for accurate signature.

ORDER_ASSIGN_UID

Hook that assign a order id on a OrderSkel type: (order_skel: SkeletonInstance_T[OrderSkel]) -> SkeletonInstance_T[OrderSkel]

CURRENT_COUNTRY

Provide the country of a global site context type: (context: t.Literal[“cart”, “article”, “vat_rate”]) -> str

ORDER_ADD_ADDITION

Do some additional modifications on the OrderSkel on order_add action. Called in viur.shop.modules.order.Order.order_add() before saving with Skeleton.write(). type: (order_skel: SkeletonInstance_T[OrderSkel]) -> SkeletonInstance_T[OrderSkel]

ORDER_UPDATE_ADDITION

Do some additional modifications on the OrderSkel on order_update action. Called in viur.shop.modules.order.Order.order_update() before saving with Skeleton.write(). type: (order_skel: SkeletonInstance_T[OrderSkel]) -> SkeletonInstance_T[OrderSkel]

ORDER_CHECKOUT_START_ADDITION

Do some additional modifications on the OrderSkel on checkout_start action. Called in viur.shop.modules.order.Order.checkout_start() before saving with Skeleton.write(). type: (order_skel: SkeletonInstance_T[OrderSkel]) -> SkeletonInstance_T[OrderSkel]

PAYMENT_RETURN_HANDLER_SUCCESS

The action that is executed after the customer has returned from the payment provider and the payment has been successful. This can be, for example, a rendered template or a redirect to another page. type: (order_skel: SkeletonInstance_T[OrderSkel], payment_data: t.Any) -> t.Any

PAYMENT_RETURN_HANDLER_ERROR

The action that is executed after the customer has returned from the payment provider and the payment has failed. This can be, for example, a rendered template or a redirect to another page. type: (order_skel: SkeletonInstance_T[OrderSkel], payment_data: t.Any) -> t.Any

class shop.services.HookService

Note: Methods should be called only with positional arguments. Or keyword-only if really necessary.

customizations: Final[list[Customization]] = []
register(customization)

Register a customization with this service

Can be used as class decorator too

@HOOK_SERVICE.register
class MyImplementation(Customization):
    kind = Hook.ORDER_ASSIGN_UID

    def __call__(self, *args, **kwargs) -> t.Any:
        ...
Parameters:

customization (Customization | Type[Customization])

Return type:

Customization

unregister(customization)
Parameters:

customization (Customization)

dispatch(kind, default=None)

Choose the matching registered customization for this kind

Parameters:
  • kind (Hook)

  • default (Callable)

Return type:

Callable