shop.modules.api

Attributes

Classes

Api

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

Module Contents

shop.modules.api.logger
class shop.modules.api.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