diff --git a/dj_shop_cart/cart.py b/dj_shop_cart/cart.py index 59ce0c0..b4c0290 100644 --- a/dj_shop_cart/cart.py +++ b/dj_shop_cart/cart.py @@ -271,6 +271,14 @@ def update_metadata(self, metadata: dict) -> None: self._metadata.update(metadata) self.save() + def clear_metadata(self, *keys: list[str]) -> None: + if keys: + for key in keys: + self._metadata.pop(key, None) + else: + self._metadata = {} + self.save() + @classmethod def new(cls, request: HttpRequest, prefix: str = DEFAULT_CART_PREFIX) -> Cart: """Appropriately create a new cart instance. This builder load existing cart if needed.""" diff --git a/docs/usage.md b/docs/usage.md index 3abee17..01597d3 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -124,6 +124,7 @@ def my_view(request): - **products** : A list of associated products. - **metadata** : A dictionary containing the metadata of the cart. - **update_metadata(metadata:dict)** : Update the metadata of the cart. +- **clear_metadata(\*keys:list[str])** : Clear the metadata of the cart. Takes an optional list of keys to clear, if no keys are specified, all metadata is cleared. - **find(\*\*criteria)** : Returns a list of cart items matching the given criteria. - **find_one(\*\*criteria)** : Returns the first cart item that matches the given criteria, if no match is found return None. - **variants_group_by_product()** : Return a dictionary with the products ids as keys and a list of variant as values. diff --git a/pyproject.toml b/pyproject.toml index 6afed9e..a618271 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dj-shop-cart" -version = "6.0.1" +version = "6.1.0" description = "Simple django cart manager for your django projects." authors = ["Tobi DEGNON "] license = "MIT"