shop.modules

Submodules

Classes

Address

Abstract Class for all viur-shop sub/nested modules.

Api

Abstract Class for all viur-shop sub/nested modules.

Cart

Abstract Class for all viur-shop sub/nested modules.

Discount

Abstract Class for all viur-shop sub/nested modules.

DiscountCondition

Order

Abstract Class for all viur-shop sub/nested modules.

Shipping

ShippingConfig

Abstract Class for all viur-shop sub/nested modules.

VatRate

Package Contents

class shop.modules.Address(moduleName=None, modulePath=None, shop=None, *args, **kwargs)

Bases: shop.modules.abstract.ShopModuleAbstract, viur.core.prototypes.List

Abstract Class for all viur-shop sub/nested modules.

The implementations should set moduleName as class variable, so the final module name for routing it not affected by the name of custom classes.

Parameters:
  • moduleName (str)

  • modulePath (str)

  • shop (viur.shop.Shop)

moduleName = 'address'
kindName = '{{viur_shop_modulename}}_address'
reference_user_created_skeletons_in_session = True

If True, keys of skeletons that the current user has created will be stored in the session.

default_order: viur.core.prototypes.skelmodule.DEFAULT_ORDER_TYPE
adminInfo()
Return type:

dict

canAdd()
Return type:

bool

canEdit(skel)
Parameters:

skel (viur.core.skeleton.SkeletonInstance)

Return type:

bool

listFilter(query)
Parameters:

query (viur.core.db.Query)

Return type:

Optional[viur.core.db.Query]

onAdded(skel)
Parameters:

skel (viur.core.skeleton.SkeletonInstance)

onEdited(skel)
Parameters:

skel (viur.core.skeleton.SkeletonInstance)

_disable_old_default(skel)

Disable old is_default

Parameters:

skel (viur.core.skeleton.SkeletonInstance)

Return type:

None

clone_address(key)
Parameters:

key (viur.core.db.Key)

Return type:

shop.types.SkeletonInstance_T[shop.skeletons.AddressSkel]

class shop.modules.Api(moduleName=None, modulePath=None, shop=None, *args, **kwargs)

Bases: viur.shop.modules.abstract.ShopModuleAbstract

Abstract Class for all viur-shop sub/nested modules.

The implementations should set moduleName as class variable, so the final module name for routing it not affected by the name of custom classes.

Parameters:
  • moduleName (str)

  • modulePath (str)

  • shop (viur.shop.Shop)

property json_renderer: viur.core.render.json.default.DefaultRender
Return type:

viur.core.render.json.default.DefaultRender

article_view(article_key, parent_cart_key)

View an article in the cart

Parameters:
  • article_key (str | viur.core.db.Key)

  • parent_cart_key (str | viur.core.db.Key)

article_add(*, article_key, quantity=1, quantity_mode=QuantityMode.REPLACE, parent_cart_key=SENTINEL, **kwargs)

Add an article to the cart

Parameters:
  • article_key (str | viur.core.db.Key) – Key of the article to add.

  • quantity (int) – Quantity of the article to add.

  • quantity_mode (viur.shop.types.QuantityMode) – Behavior of the quantity: absolute or relative valuation

  • parent_cart_key (str | viur.core.db.Key | viur.shop.types.t.Literal[BASKET]) – Key of the (sub) cart (node) to which this leaf will be added as a child. Use “BASKET” as key to use the basket of the current session.

article_update(*, article_key, quantity, quantity_mode=QuantityMode.REPLACE, parent_cart_key=SENTINEL, **kwargs)

Update an existing article in the cart

Parameters:
  • article_key (str | viur.core.db.Key) – Key of the article to update. Note: This is not the key of the leaf skel!

  • quantity (int) – Quantity of the article to update.

  • quantity_mode (viur.shop.types.QuantityMode) – Behavior of the quantity: absolute or relative valuation

  • parent_cart_key (str | viur.core.db.Key | viur.shop.types.t.Literal[BASKET]) – Optional. Key of the (sub) cart (node) to which this leaf will be moved to as a child. Use “BASKET” as key to use the basket of the current session.

article_remove(*, article_key, parent_cart_key, **kwargs)

Remove an article from the cart

Parameters:
  • article_key (str | viur.core.db.Key)

  • parent_cart_key (str | viur.core.db.Key)

article_move(*, article_key, parent_cart_key, new_parent_cart_key)

Move an article inside a cart

Parameters:
  • article_key (str | viur.core.db.Key)

  • parent_cart_key (str | viur.core.db.Key)

  • new_parent_cart_key (str | viur.core.db.Key)

cart_add(*, parent_cart_key=None, cart_type=SENTINEL, name=SENTINEL, customer_comment=SENTINEL, shipping_address_key=SENTINEL, shipping_key=SENTINEL, discount_key=SENTINEL, **kwargs)

Add a new cart node

Parameters:
  • parent_cart_key (str | viur.core.db.Key) – Key of the parent cart

  • cart_type (viur.shop.types.CartType) – Type of the cart node, see CartType

  • name (str) – Optional. Name of the cart node

  • customer_comment (str) – Optional. Comment to this node, by customer.

  • shipping_address_key (str | viur.core.db.Key) – Optional. Key of the address

  • shipping_key (str | viur.core.db.Key) – Optional. Key of the shipping

  • discount_key (str | viur.core.db.Key) – Optional. Key of the discount

Returns: The created cart node skel

cart_update(*, cart_key, cart_type=SENTINEL, name=SENTINEL, customer_comment=SENTINEL, shipping_address_key=SENTINEL, shipping_key=SENTINEL, discount_key=SENTINEL, **kwargs)

Update an existing cart node

Parameters:
  • cart_key (str | viur.core.db.Key) – Key of the cart node to be updated

  • cart_type (viur.shop.types.CartType) – Type of the cart node, see CartType

  • name (str) – Optional. Name of the cart node

  • customer_comment (str) – Optional. Comment to this node, by customer.

  • shipping_address_key (str | viur.core.db.Key) – Optional. Key of the address

  • shipping_key (str | viur.core.db.Key) – Optional. Key of the shipping

  • discount_key (str | viur.core.db.Key) – Optional. Key of the discount

Returns: The updated cart node skel

cart_remove(*, cart_key)

Remove a cart node.

Removes itself and all children :param cart_key: Key of the cart node to be removed

Parameters:

cart_key (str | viur.core.db.Key)

cart_clear(*, cart_key=SENTINEL, keep_sub_carts=False)

Remove direct or all children

Parameters:
  • cart_key (str | viur.core.db.Key | viur.shop.types.t.Literal[BASKET]) – Key of the (sub) cart (node) from which the children should be removed. Use “BASKET” as key to use the basket of the current session.

  • keep_sub_carts (bool) – Keep child nodes, remove only leafs

basket_list()

List the children of the basket (the cart stored in the session)

Raises:

errors.PreconditionFailed – If no basket created yet for this session

basket_view(*, create_if_missing=False)

View the basket (the cart stored in the session) itself

Parameters:

create_if_missing (bool) – Create the basket if not already created for this session

Raises:

errors.PreconditionFailed – If no basket created yet for this session (and it should not be created)

See also basket_view() to view any cart.

cart_list(cart_key=None)

List root nodes or children of a cart

If a cart key is provided, the direct children (nodes and leafs) will be returned. Otherwise (without a key), the root nodes will be returned.

Parameters:

cart_key (str | viur.core.db.Key | None) – list direct children (nodes and leafs) of this parent node

cart_view(cart_key)

View a cart itself

See also basket_view() to view the current basket.

Parameters:

cart_key (str | viur.core.db.Key)

order_add(*, cart_key, payment_provider=SENTINEL, billing_address_key=SENTINEL, customer_key=SENTINEL, state_ordered=SENTINEL, state_paid=SENTINEL, state_rts=SENTINEL, **kwargs)
Parameters:
  • cart_key (str | viur.core.db.Key)

  • payment_provider (str)

  • billing_address_key (str | viur.core.db.Key)

  • customer_key (str | viur.core.db.Key)

  • state_ordered (bool)

  • state_paid (bool)

  • state_rts (bool)

order_update(*, order_key, payment_provider=SENTINEL, billing_address_key=SENTINEL, customer_key=SENTINEL, state_ordered=SENTINEL, state_paid=SENTINEL, state_rts=SENTINEL, **kwargs)
Parameters:
  • order_key (str | viur.core.db.Key)

  • payment_provider (str)

  • billing_address_key (str | viur.core.db.Key)

  • customer_key (str | viur.core.db.Key)

  • state_ordered (bool)

  • state_paid (bool)

  • state_rts (bool)

order_remove(*, order_key)
Parameters:

order_key (str | viur.core.db.Key)

order_list(**kwargs)

List the orders of the current user

Return type:

viur.shop.types.JsonResponse[list[viur.shop.types.OrderViewResult]]

order_view(order_key='SESSION')

View an order

Parameters:

order_key (str | viur.core.db.Key | viur.shop.types.t.Literal[SESSION]) – Key of the order to view. Use “SESSION” as key to view the order of the current session

Return type:

viur.shop.types.JsonResponse[viur.shop.types.OrderViewResult]

_get_order_view_result(order_skel)
Parameters:

order_skel (viur.shop.types.SkeletonInstance_T[OrderSkel])

Return type:

viur.shop.types.OrderViewResult

discount_add(*, code=None, discount_key=None)

parameter code xor discount_key: str | db.Key

Sucht nach Rabatt mit dem code xor key, je nach Typ (Artikel/Warenkorb) suche …ende parent_node oder erzeuge eine und setze dort die discount Relation.

Parameters:
  • code (str)

  • discount_key (str | viur.core.db.Key)

discount_remove(*, discount_key)
Parameters:

discount_key (str | viur.core.db.Key)

shipping_list(cart_key)

Lists available shipping options for a (sub)cart

Parameters:

cart_key (str | viur.core.db.Key) – Key of the parent cart

Returns:

list of ShippingSkel `SkeletonInstance`s

Return type:

viur.shop.types.JsonResponse[list[viur.shop.types.SkeletonInstance_T[viur.shop.skeletons.ShippingSkel]]]

_normalize_external_key(external_key, parameter_name, can_be_None=False)

Convert urlsafe key to db.Key and raise an error on invalid in key.

Parameters:
  • external_key (str)

  • parameter_name (str)

  • can_be_None (bool)

Return type:

viur.core.db.Key | None

class shop.modules.Cart(moduleName=None, modulePath=None, shop=None, *args, **kwargs)

Bases: viur.shop.modules.abstract.ShopModuleAbstract, viur.core.prototypes.Tree

Abstract Class for all viur-shop sub/nested modules.

The implementations should set moduleName as class variable, so the final module name for routing it not affected by the name of custom classes.

Parameters:
  • moduleName (str)

  • modulePath (str)

  • shop (viur.shop.Shop)

moduleName = 'cart'
nodeSkelCls
leafSkelCls
adminInfo()
Return type:

dict

baseSkel(skelType, sub_skel=None, *args, **kwargs)

Extend default baseSkel() by sub_skel parameter

Parameters:
  • skelType (viur.core.prototypes.tree.SkelType)

  • sub_skel (str | list[str] | None)

Return type:

viur.core.skeleton.SkeletonInstance

canView(skelType, skel)
Parameters:
  • skelType (viur.core.prototypes.tree.SkelType)

  • skel (viur.core.skeleton.SkeletonInstance)

Return type:

bool

property current_session_cart_key: viur.core.db.Key | None
Return type:

viur.core.db.Key | None

get_current_session_cart_key(*, create_if_missing=False)
Parameters:

create_if_missing (bool)

Return type:

viur.core.db.Key | None

property current_session_cart: viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel]
Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel]

_ensure_current_session_cart()
Return type:

viur.core.db.Key

detach_session_cart()
Return type:

viur.core.db.Key

static _set_basket_txn(user_key, basket_key)
Parameters:
  • user_key (viur.core.db.Key)

  • basket_key (viur.core.db.Key | None)

Return type:

viur.core.skeleton.SkeletonInstance

get_available_root_nodes(*args, **kwargs)
Return type:

list[dict[viur.shop.types.t.Literal[name, key], str]]

getAvailableRootNodes
listRootNodes(*args, **kwargs)

Renders a list of all available repositories for the current user using the modules default renderer.

Returns:

The rendered representation of the available root-nodes.

Return type:

viur.shop.types.t.Any

is_valid_node(node_key, root_node=False)

is this a valid node key for the user?

Parameters:
  • node_key (viur.core.db.Key) – Key of node to check

  • root_node (bool) – Must this be a root node, or is any node okay?

Return type:

bool

get_children(parent_cart_key, **filters)
Parameters:
  • parent_cart_key (viur.core.db.Key)

  • filters (viur.shop.types.t.Any)

Return type:

viur.shop.types.t.Iterator[viur.core.skeleton.SkeletonInstance]

get_children_from_cache(parent_cart_key)
Parameters:

parent_cart_key (viur.core.db.Key)

Return type:

list[viur.core.skeleton.SkeletonInstance]

clear_children_cache()
Return type:

None

cart_get(cart_key, skel_type)
Parameters:
  • cart_key (viur.core.db.Key)

  • skel_type (viur.core.prototypes.tree.SkelType)

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel | shop.skeletons.cart.CartItemSkel] | None

get_article(article_key, parent_cart_key, *, must_be_listed=True)
Parameters:
  • article_key (viur.core.db.Key)

  • parent_cart_key (viur.core.db.Key)

  • must_be_listed (bool)

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartItemSkel]

add_or_update_article(article_key, parent_cart_key, *, quantity, quantity_mode, **kwargs)
Parameters:
  • article_key (viur.core.db.Key)

  • parent_cart_key (viur.core.db.Key)

  • quantity (int)

  • quantity_mode (viur.shop.types.QuantityMode)

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartItemSkel] | None

copy_article_values(article_skel, skel)

Copy values from the article to the cart leaf

Parameters:
Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartItemSkel]

move_article(article_key, parent_cart_key, new_parent_cart_key)
Parameters:
  • article_key (viur.core.db.Key)

  • parent_cart_key (viur.core.db.Key)

  • new_parent_cart_key (viur.core.db.Key)

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartItemSkel] | None

cart_add(*, parent_cart_key=None, cart_type=None, name=SENTINEL, customer_comment=SENTINEL, shipping_address_key=SENTINEL, shipping_key=SENTINEL, discount_key=SENTINEL, **kwargs)
Parameters:
  • parent_cart_key (str | viur.core.db.Key)

  • cart_type (viur.shop.types.CartType)

  • name (str)

  • customer_comment (str)

  • shipping_address_key (str | viur.core.db.Key)

  • shipping_key (str | viur.core.db.Key)

  • discount_key (str | viur.core.db.Key)

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel] | None

cart_update(cart_key, *, parent_cart_key=SENTINEL, cart_type=None, name=SENTINEL, customer_comment=SENTINEL, shipping_address_key=SENTINEL, shipping_key=SENTINEL, discount_key=SENTINEL, **kwargs)
Parameters:
  • cart_key (viur.core.db.Key)

  • parent_cart_key (str | viur.core.db.Key)

  • cart_type (viur.shop.types.CartType)

  • name (str)

  • customer_comment (str)

  • shipping_address_key (str | viur.core.db.Key)

  • shipping_key (str | viur.core.db.Key)

  • discount_key (str | viur.core.db.Key)

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel] | None

_cart_set_values(skel, *, parent_cart_key=SENTINEL, cart_type=None, name=SENTINEL, customer_comment=SENTINEL, shipping_address_key=SENTINEL, shipping_key=SENTINEL, discount_key=SENTINEL)
Parameters:
  • skel (viur.core.skeleton.SkeletonInstance | shop.skeletons.cart.CartNodeSkel)

  • parent_cart_key (viur.core.db.Key)

  • cart_type (viur.shop.types.CartType)

  • name (str)

  • customer_comment (str)

  • shipping_address_key (str | viur.core.db.Key)

  • shipping_key (str | viur.core.db.Key)

  • discount_key (str | viur.core.db.Key)

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel]

cart_remove(cart_key)
Parameters:

cart_key (viur.core.db.Key)

Return type:

None

cart_clear(cart_key, *, keep_sub_carts=False)
Parameters:
  • cart_key (viur.core.db.Key)

  • keep_sub_carts (bool)

Return type:

None

additional_add_or_update_article(skel, /, **kwargs)

Hook method called by add_or_update_article() before the skeleton is saved.

This method can be overridden in a subclass to implement additional API fields or make further modifications to the cart skeleton (skel). By default, it raises an exception if unexpected arguments (kwargs) are provided and returns the unchanged skel object.

Parameters:
  • skel (viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartItemSkel]) – The current instance of the cart item skeleton.

  • kwargs – Additional optional arguments for extended implementations.

Raises:

TooManyArgumentsException – If unexpected arguments are passed in kwargs.

Returns:

The (potentially modified) cart item skeleton.

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartItemSkel]

additional_cart_add(skel, /, **kwargs)

Hook method called by cart_add() before the skeleton is saved.

This method can be overridden in a subclass to implement additional API fields or make further modifications to the cart skeleton (skel). By default, it raises an exception if unexpected arguments (kwargs) are provided and returns the unchanged skel object.

Parameters:
  • skel (viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel]) – The current instance of the cart skeleton.

  • kwargs – Additional optional arguments for extended implementations.

Raises:

TooManyArgumentsException – If unexpected arguments are passed in kwargs.

Returns:

The (potentially modified) cart skeleton.

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel]

additional_cart_update(skel, /, **kwargs)

Hook method called by cart_update() before the skeleton is saved.

This method can be overridden in a subclass to implement additional API fields or make further modifications to the cart skeleton (skel). By default, it raises an exception if unexpected arguments (kwargs) are provided and returns the unchanged skel object.

Parameters:
  • skel (viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel]) – The current instance of the cart skeleton.

  • kwargs – Additional optional arguments for extended implementations.

Raises:

TooManyArgumentsException – If unexpected arguments are passed in kwargs.

Returns:

The (potentially modified) cart skeleton.

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel]

freeze_cart(cart_key)

Freeze (lock) cart values and children items.

Parameters:

cart_key (viur.core.db.Key) – Key of the (sub-)cart skeleton.

Returns:

The frozen CartNode skeleton.

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel]

freeze_leaf(leaf_skel)
Parameters:

leaf_skel (viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartItemSkel])

get_discount_for_leaf(leaf_key_or_skel)
Parameters:

leaf_key_or_skel (viur.core.db.Key | viur.core.skeleton.SkeletonInstance)

Return type:

list[viur.core.skeleton.SkeletonInstance]

add_new_parent(leaf_skel, **kwargs)
get_cached_cart_skel(key)
Parameters:

key (viur.core.db.Key)

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel]

get_closest_node(start, condition=lambda skel: ...)
Parameters:
Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.cart.CartNodeSkel] | None

class shop.modules.Discount(moduleName=None, modulePath=None, shop=None, *args, **kwargs)

Bases: shop.modules.abstract.ShopModuleAbstract, viur.core.prototypes.List

Abstract Class for all viur-shop sub/nested modules.

The implementations should set moduleName as class variable, so the final module name for routing it not affected by the name of custom classes.

Parameters:
  • moduleName (str)

  • modulePath (str)

  • shop (viur.shop.Shop)

moduleName = 'discount'
kindName = '{{viur_shop_modulename}}_discount'
adminInfo()
Return type:

dict

search(code=None, discount_key=None)
Parameters:
  • code (str | None)

  • discount_key (viur.core.db.Key | None)

Return type:

list[viur.core.skeleton.SkeletonInstance]

apply(code=None, discount_key=None)
Parameters:
  • code (str | None)

  • discount_key (viur.core.db.Key | None)

Return type:

viur.shop.types.t.Any

can_apply(skel, *, cart_key=None, article_skel=None, code=None, context=DiscountValidationContext.NORMAL)
Parameters:
  • skel (viur.shop.types.SkeletonInstance_T[shop.skeletons.DiscountSkel])

  • cart_key (viur.core.db.Key | None)

  • article_skel (viur.core.skeleton.SkeletonInstance | None)

  • code (str | None)

  • context (viur.shop.types.DiscountValidationContext)

Return type:

tuple[bool, shop.types.dc_scope.DiscountValidator | None]

property current_automatically_discounts: list[viur.shop.types.SkeletonInstance_T[shop.skeletons.DiscountSkel]]
Return type:

list[viur.shop.types.SkeletonInstance_T[shop.skeletons.DiscountSkel]]

remove(discount_key)
Parameters:

discount_key (viur.core.db.Key)

Return type:

viur.shop.types.t.Any

class shop.modules.DiscountCondition

Bases: shop.modules.abstract.ShopModuleAbstract, viur.core.prototypes.List

moduleName = 'discount_condition'
kindName = '{{viur_shop_modulename}}_discount_condition'
adminInfo()
Return type:

dict

canEdit(skel)
editSkel(*args, **kwargs)
Return type:

viur.core.skeleton.SkeletonInstance

onAdd(skel)
Parameters:

skel (viur.core.skeleton.SkeletonInstance)

onEdit(skel)
Parameters:

skel (viur.core.skeleton.SkeletonInstance)

onClone(skel, src_skel)
Parameters:
  • skel (viur.core.skeleton.SkeletonInstance)

  • src_skel (viur.core.skeleton.SkeletonInstance)

onAdded(skel)
Parameters:

skel (viur.core.skeleton.SkeletonInstance)

onEdited(skel)
Parameters:

skel (viur.core.skeleton.SkeletonInstance)

onCloned(skel, src_skel)
Parameters:
  • skel (viur.core.skeleton.SkeletonInstance)

  • src_skel (viur.core.skeleton.SkeletonInstance)

on_change(skel, event)
Parameters:
  • skel (viur.core.skeleton.SkeletonInstance)

  • event (str)

Return type:

None

on_changed(skel, event)
Parameters:
  • skel (viur.core.skeleton.SkeletonInstance)

  • event (str)

Return type:

None

generate_subcodes(parent_key, prefix, amount)

Generate subcodes for a parent individual code.

Parameters:
  • parent_key (viur.core.db.Key)

  • prefix (str)

  • amount (int)

Return type:

None

classmethod get_skel(key)
Parameters:

key (viur.core.db.Key)

Return type:

shop.types.SkeletonInstance_T[shop.skeletons.DiscountConditionSkel] | None

get_by_code(code=None)
Parameters:

code (str)

Return type:

Iterator[viur.core.skeleton.SkeletonInstance]

get_discounts_from_cart(cart_key)
Parameters:

cart_key (viur.core.db.Key)

Return type:

list[viur.core.db.Key]

static mark_discount_used(order_skel, payment, *args, **kwargs)

Increase quantity_used on discount of an ordered cart

Parameters:

order_skel (shop.types.SkeletonInstance_T[shop.skeletons.OrderSkel])

Return type:

None

class shop.modules.Order(moduleName=None, modulePath=None, shop=None, *args, **kwargs)

Bases: shop.modules.abstract.ShopModuleAbstract, viur.core.prototypes.List

Abstract Class for all viur-shop sub/nested modules.

The implementations should set moduleName as class variable, so the final module name for routing it not affected by the name of custom classes.

Parameters:
  • moduleName (str)

  • modulePath (str)

  • shop (viur.shop.Shop)

moduleName = 'order'
kindName = '{{viur_shop_modulename}}_order'
reference_user_created_skeletons_in_session = True

If True, keys of skeletons that the current user has created will be stored in the session.

adminInfo()
Return type:

dict

property current_session_order_key: viur.core.db.Key | None
Return type:

viur.core.db.Key | None

property current_order_skel: viur.shop.types.SkeletonInstance_T[shop.skeletons.order.OrderSkel] | None
Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.order.OrderSkel] | None

canView(skel)
Parameters:

skel (viur.core.skeleton.SkeletonInstance)

Return type:

bool

payment_providers_list(only_available=True)

Get a list of payment providers.

This method returns a JSON response containing a dictionary of payment providers. The keys represent provider identifiers, and the values are instances of PaymentProviderResult (dict) containing the details of each provider.

Parameters:

only_available (bool) – If True (default), only payment providers that are currently available will be included in the response. If False, all providers will be listed regardless of availability.

Returns:

A JSON response with a dictionary of payment providers.

Return type:

viur.shop.types.JsonResponse[dict[str, viur.shop.types.results.PaymentProviderResult]]

get_payment_providers(only_available=True)
Parameters:

only_available (bool)

Return type:

dict[str, viur.shop.types.results.PaymentProviderResult]

order_get(order_key)
Parameters:

order_key (viur.core.db.Key)

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.order.OrderSkel] | None

order_add(cart_key, payment_provider=SENTINEL, billing_address_key=SENTINEL, customer_key=SENTINEL, state_ordered=SENTINEL, state_paid=SENTINEL, state_rts=SENTINEL, **kwargs)
Parameters:
  • cart_key (viur.core.db.Key)

  • payment_provider (str)

  • billing_address_key (viur.core.db.Key)

  • customer_key (viur.core.db.Key)

  • state_ordered (bool)

  • state_paid (bool)

  • state_rts (bool)

order_update(order_key, payment_provider=SENTINEL, billing_address_key=SENTINEL, customer_key=SENTINEL, state_ordered=SENTINEL, state_paid=SENTINEL, state_rts=SENTINEL, **kwargs)
Parameters:
  • order_key (viur.core.db.Key)

  • payment_provider (str)

  • billing_address_key (viur.core.db.Key)

  • customer_key (viur.core.db.Key)

  • state_ordered (bool)

  • state_paid (bool)

  • state_rts (bool)

_order_set_values(skel, *, payment_provider=SENTINEL, billing_address_key=SENTINEL, customer_key=SENTINEL, state_ordered=SENTINEL, state_paid=SENTINEL, state_rts=SENTINEL)
Parameters:
  • skel (viur.shop.types.SkeletonInstance_T[shop.skeletons.order.OrderSkel])

  • payment_provider (str)

  • billing_address_key (viur.core.db.Key)

  • customer_key (viur.core.db.Key)

  • state_ordered (bool)

  • state_paid (bool)

  • state_rts (bool)

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.order.OrderSkel]

customer_is_valid(order_skel, customer_key)

Checks if the given customer is a valid customer for this skel.

The customer must be the same user or an root user.

Parameters:
Return type:

bool

checkout_start(order_key)

Start the checkout process.

Requires no errors in self.can_checkout().

Parameters:

order_key (viur.core.db.Key)

can_checkout(order_skel)
Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

list[viur.shop.types.ClientError]

freeze_order(order_skel)
Parameters:

order_skel (viur.shop.types.SkeletonInstance_T[shop.skeletons.order.OrderSkel])

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.order.OrderSkel]

_default_assign_uid(order_skel)

Default order assign id method.

Called as default/fallback for Hook.ORDER_ASSIGN_UID.

Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

viur.core.skeleton.SkeletonInstance

checkout_order(order_key)

The final order now step.

Requires no errors in self.can_order().

Parameters:

order_key (viur.core.db.Key)

can_order(order_skel)
Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

list[viur.shop.types.ClientError]

set_checkout_in_progress(order_skel)

Set an order to the state is_checkout_in_progress

Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

viur.core.skeleton.SkeletonInstance

set_ordered(order_skel, payment)

Set an order to the state ordered

Parameters:
  • order_skel (viur.core.skeleton.SkeletonInstance)

  • payment (viur.shop.types.t.Any)

Return type:

viur.core.skeleton.SkeletonInstance

set_paid(order_skel)

Set an order to the state paid

Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

viur.core.skeleton.SkeletonInstance

set_rts(order_skel)

Set an order to the state Ready to ship

Parameters:

order_skel (viur.core.skeleton.SkeletonInstance)

Return type:

viur.core.skeleton.SkeletonInstance

additional_order_add(skel, /, **kwargs)

Hook method called by order_add() before the skeleton is saved.

This method can be overridden in a subclass to implement additional API fields or make further modifications to the order skeleton (skel). By default, it raises an exception if unexpected arguments (kwargs) are provided and returns the unchanged skel object.

Parameters:
  • skel (viur.shop.types.SkeletonInstance_T[shop.skeletons.order.OrderSkel]) – The current instance of the order skeleton.

  • kwargs – Additional optional arguments for extended implementations.

Raises:

TooManyArgumentsException – If unexpected arguments are passed in kwargs.

Returns:

The (potentially modified) order skeleton.

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.order.OrderSkel]

additional_order_update(skel, /, **kwargs)

Hook method called by order_update() before the skeleton is saved.

This method can be overridden in a subclass to implement additional API fields or make further modifications to the order skeleton (skel). By default, it raises an exception if unexpected arguments (kwargs) are provided and returns the unchanged skel object.

Parameters:
  • skel (viur.shop.types.SkeletonInstance_T[shop.skeletons.order.OrderSkel]) – The current instance of the order skeleton.

  • kwargs – Additional optional arguments for extended implementations.

Raises:

TooManyArgumentsException – If unexpected arguments are passed in kwargs.

Returns:

The (potentially modified) order skeleton.

Return type:

viur.shop.types.SkeletonInstance_T[shop.skeletons.order.OrderSkel]

get_payment_provider_by_name(payment_provider_name)
Parameters:

payment_provider_name (str)

Return type:

shop.payment_providers.PaymentProviderAbstract

class shop.modules.Shipping

Bases: shop.modules.abstract.ShopModuleAbstract, viur.core.prototypes.List

moduleName = 'shipping'
kindName = '{{viur_shop_modulename}}_shipping'
adminInfo()
Return type:

dict

choose_shipping_skel_for_article(article_skel, *, country=None)

Chooses always the cheapest, applicable shipping for an article

Ignores the supplier

Parameters:
  • country (str | None) – Ignore the context and get shipping for this country.

  • article_skel (viur.shop.types.SkeletonInstance_T[viur.shop.skeletons.ArticleAbstractSkel])

Return type:

viur.shop.types.SkeletonInstance_T[viur.shop.skeletons.ShippingSkel] | None | Literal[False]

# TODO(discuss): List all options?

get_shipping_skels_for_cart(*, cart_key=SENTINEL, cart_skel=SENTINEL, country=None, use_cache=False)

Get all configured and applicable shippings of all items in the cart

# TODO: how do we handle free shipping discounts?

Parameters:
  • cart_key (viur.core.db.Key) – Key of the parent cart node, can be a sub-cart too

  • country (str | None) – Ignore the context and get shipping for this country.

  • cart_skel (viur.shop.types.SkeletonInstance_T[viur.shop.skeletons.CartNodeSkel])

  • use_cache (bool)

Returns:

A list of SkeletonInstance`s for the :class:`ShippingSkel.

Return type:

list[viur.shop.types.SkeletonInstance_T[viur.shop.skeletons.ShippingSkel]]

class shop.modules.ShippingConfig(moduleName=None, modulePath=None, shop=None, *args, **kwargs)

Bases: shop.modules.abstract.ShopModuleAbstract, viur.core.prototypes.List

Abstract Class for all viur-shop sub/nested modules.

The implementations should set moduleName as class variable, so the final module name for routing it not affected by the name of custom classes.

Parameters:
  • moduleName (str)

  • modulePath (str)

  • shop (viur.shop.Shop)

moduleName = 'shipping_config'
kindName = '{{viur_shop_modulename}}_shipping_config'
adminInfo()
Return type:

dict

is_applicable(dest, rel, *, article_skel=None, cart_skel=None, country=None)

Check if a shipping configuration is applicable in the current context.

Provide eiter article_skel for single article context xor cart_skel for cart context.

Parameters:
  • country (str | None) – If provided, check if the shipping configuration is applicable for this country.

  • dest (viur.core.skeleton.RefSkel)

  • rel (viur.core.skeleton.RelSkel)

  • article_skel (viur.shop.types.SkeletonInstance_T[viur.shop.skeletons.ArticleAbstractSkel] | None)

  • cart_skel (viur.shop.types.SkeletonInstance_T[viur.shop.skeletons.CartNodeSkel] | None)

Return type:

tuple[bool, str]

class shop.modules.VatRate

Bases: shop.modules.abstract.ShopModuleAbstract, viur.core.prototypes.List

moduleName = 'vat_rate'
kindName = '{{viur_shop_modulename}}_vat_rate'
adminInfo()
Return type:

dict

vat_rates()

Cache the vat rates

Since this configuration will not change much, we cache the whole thing persistently within the instance. So after changing the VAT rates, the instance would have to be restarted – or someone would have to create a pull request with an alternative solution.

_vat_skel()
get_vat_rate_for_country(*, country=None, category)

Get the configured vat rate percentage for a country.

Parameters:
Return type:

float