Skip to content

Commit

Permalink
feat: metadata should be cleared when cart is emptied
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi-De committed Mar 30, 2023
1 parent 2a68333 commit fb96999
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dj_shop_cart/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,19 @@ def save(self) -> None:
data[self.prefix] = {"items": items, "metadata": self.metadata}
self.storage.save(data)

def empty(self) -> None:
def empty(self, clear_metadata: bool = True) -> None:
"""Delete all items in the cart, and optionally clear the metadata."""
self._items = []
self._metadata = {}
data = self.storage.load()
with contextlib.suppress(KeyError):
data.pop(self.prefix)
if clear_metadata:
self._metadata.clear()
self.storage.save(data)

def empty_all(self) -> None:
"""Empty all carts, prefixed or not."""
self._items = []
self._metadata = {}
self.storage.clear()
Expand Down

0 comments on commit fb96999

Please sign in to comment.