Skip to main content

Simple django cart manager for your django projects.

Project description

dj-shop-cart

A simple and flexible cart manager for your django projects.

pypi python MIT License

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


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)

Uploaded Source

Built Distribution

dj_shop_cart-3.0.2-py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page