Simple django cart manager for your django projects.
Project description
dj-shop-cart
A simple and flexible cart manager for your django projects.
This is a work in progress, expect api breaking changes, pin the exact version you are using
Features
- Add, remove, decrement and clear items from cart
- Authenticated users cart can be saved to database
- Write custom methods to easily hook into the items add / remove flow
- Custom get_price method to ensure that the cart always have an up-to-date products price
- Access to your django database Product instance from the cart items
- Metadata data can be attached to cart items
- Supports specification of product variation details
- Available context processor for easy access to the user cart in all your django templates
Installation
Install dj-shop-cart with pip or poetry.
pip install dj-shop-cart
Usage/Examples
# settings.py
INSTALLED_APPS = [
...,
"dj_shop_cart", # If you want the cart to be stored in the database when users are authenticated
...,
]
TEMPLATES = [
{
"OPTIONS": {
"context_processors": [
...,
"dj_shop_cart.context_processors.cart", # If you want access to the cart instance in all templates
],
},
}
]
# views.py
from dj_shop_cart.cart import get_cart_manager_class
from django.http import HttpRequest
from django.views.decorators.http import require_POST
from .helpers import collect_params
Cart = get_cart_manager_class()
@require_POST
def add_product(request: HttpRequest):
product, quantity = collect_params(request)
cart = Cart.new(request)
cart.add(product, quantity=quantity)
...
@require_POST
def remove_product(request: HttpRequest):
product, quantity = collect_params(request)
cart = Cart.new(request)
cart.remove(product, quantity=quantity)
...
@require_POST
def empty_cart(request: HttpRequest):
Cart.new(request).empty()
...
Feedback
If you have any feedback, please reach out to me at degnonfrancis@gmail.com
Todos
- More examples
- Add api reference
- Add Used by section to readme
- Write more tests
- Add local dev section to readme
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dj-shop-cart-3.0.2.tar.gz
(8.5 kB
view hashes)
Built Distribution
Close
Hashes for dj_shop_cart-3.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 877c776b33f58184a1d18043c65d43680b153e92af3e51c4008ffe1093b981d0 |
|
MD5 | 8401d841b84d59a6e266bb3e52c2b9bd |
|
BLAKE2b-256 | 17c2b662e376869b5fbfce60a6002e11a108f732e1fea8fed767783c860d3234 |