dj-shop-cart


Namedj-shop-cart JSON
Version 7.0.3 PyPI version JSON
download
home_pagehttps://tobi-de.github.io/dj-shop-cart/
SummarySimple django cart manager for your django projects.
upload_time2023-06-06 14:40:39
maintainer
docs_urlNone
authorTobi DEGNON
requires_python>=3.7,<4.0
licenseMIT
keywords django python cart shop ecommerce
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dj-shop-cart

A simple and flexible cart manager for your django projects.

[![pypi](https://badge.fury.io/py/dj-shop-cart.svg)](https://pypi.org/project/dj-shop-cart/)
[![python](https://img.shields.io/pypi/pyversions/dj-shop-cart)](https://github.com/Tobi-De/dj-shop-cart)
[![django](https://img.shields.io/pypi/djversions/dj-shop-cart)](https://github.com/Tobi-De/dj-shop-cart)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?)](https://github.com/Tobi-De/dj-shop-cart/blob/master/LICENSE)
[![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

✨📚✨ [Read the full documentation](https://tobi-de.github.io/dj-shop-cart/)

## 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
- Each item in the cart hold a reference to the associated product
- 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
- Swappable backend storage, with session and database provided by default


## Installation

Install **dj-shop-cart** with pip or poetry.

```bash
  pip install dj-shop-cart
```

## Quickstart

```python3

# settings.py

TEMPLATES = [
    {
        "OPTIONS": {
            "context_processors": [
                ...,
                "dj_shop_cart.context_processors.cart", # If you want access to the cart instance in all templates
            ],
        },
    }
]

# models.py

from django.db import models
from dj_shop_cart.cart import CartItem
from dj_shop_cart.protocols import Numeric

class Product(models.Model):
    ...

    def get_price(self, item:CartItem) -> Numeric:
        """The only requirements of the dj_shop_cart package apart from the fact that the products you add
        to the cart must be instances of django based models. You can use a different name for this method
        but be sure to update the corresponding setting (see Configuration). Even if you change the name the
        function signature should match this one.
        """


# views.py

from dj_shop_cart.cart import get_cart_class
from django.http import HttpRequest
from django.views.decorators.http import require_POST
from django.shortcuts import get_object_or_404

from .models import Product

Cart = get_cart_class()


@require_POST
def add_product(request: HttpRequest, product_id:int):
    product = get_object_or_404(Product.objects.all(), pk=product_id)
    quantity = int(request.POST.get("quantity"))
    cart = Cart.new(request)
    cart.add(product, quantity=quantity)
    ...


@require_POST
def remove_product(request: HttpRequest):
    item_id = request.POST.get("item_id")
    quantity = int(request.POST.get("quantity"))
    cart = Cart.new(request)
    cart.remove(item_id=item_id, quantity=quantity)
    ...


@require_POST
def empty_cart(request: HttpRequest):
    Cart.new(request).empty()
    ...

```

## Used By

This project is used by the following companies:

- [Fêmy bien être](https://www.femybienetre.com/)

## Development

Poetry is required (not really, you can set up the environment however you want and install the requirements
manually) to set up a virtualenv, install it then run the following:

```sh
poetry install
pre-commit install --install-hooks
```

Tests can then be run quickly in that environment:

```sh
pytest
```

## Feedback

If you have any feedback, please reach out to me at tobidegnon@proton.me.

## Credits

Thanks to [Jetbrains](https://jb.gg/OpenSource) for providing an Open Source license for this project.

<img height="200" src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="JetBrains Logo (Main) logo.">

            

Raw data

            {
    "_id": null,
    "home_page": "https://tobi-de.github.io/dj-shop-cart/",
    "name": "dj-shop-cart",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "django,python,cart,shop,ecommerce",
    "author": "Tobi DEGNON",
    "author_email": "tobidegnon@protonmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0d/0a/efc10cc3b69bd9d010fc039dd3791f13e8a8b3bc1c35907933842a45f1c0/dj_shop_cart-7.0.3.tar.gz",
    "platform": null,
    "description": "# dj-shop-cart\n\nA simple and flexible cart manager for your django projects.\n\n[![pypi](https://badge.fury.io/py/dj-shop-cart.svg)](https://pypi.org/project/dj-shop-cart/)\n[![python](https://img.shields.io/pypi/pyversions/dj-shop-cart)](https://github.com/Tobi-De/dj-shop-cart)\n[![django](https://img.shields.io/pypi/djversions/dj-shop-cart)](https://github.com/Tobi-De/dj-shop-cart)\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?)](https://github.com/Tobi-De/dj-shop-cart/blob/master/LICENSE)\n[![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n\u2728\ud83d\udcda\u2728 [Read the full documentation](https://tobi-de.github.io/dj-shop-cart/)\n\n## Features\n\n- Add, remove, decrement and clear items from cart\n- Authenticated users cart can be saved to database\n- Write custom methods to easily hook into the items add / remove flow\n- Custom **get_price** method to ensure that the cart always have an up-to-date products price\n- Each item in the cart hold a reference to the associated product\n- Metadata data can be attached to cart items\n- Supports specification of product variation details\n- Available context processor for easy access to the user cart in all your django templates\n- Swappable backend storage, with session and database provided by default\n\n\n## Installation\n\nInstall **dj-shop-cart** with pip or poetry.\n\n```bash\n  pip install dj-shop-cart\n```\n\n## Quickstart\n\n```python3\n\n# settings.py\n\nTEMPLATES = [\n    {\n        \"OPTIONS\": {\n            \"context_processors\": [\n                ...,\n                \"dj_shop_cart.context_processors.cart\", # If you want access to the cart instance in all templates\n            ],\n        },\n    }\n]\n\n# models.py\n\nfrom django.db import models\nfrom dj_shop_cart.cart import CartItem\nfrom dj_shop_cart.protocols import Numeric\n\nclass Product(models.Model):\n    ...\n\n    def get_price(self, item:CartItem) -> Numeric:\n        \"\"\"The only requirements of the dj_shop_cart package apart from the fact that the products you add\n        to the cart must be instances of django based models. You can use a different name for this method\n        but be sure to update the corresponding setting (see Configuration). Even if you change the name the\n        function signature should match this one.\n        \"\"\"\n\n\n# views.py\n\nfrom dj_shop_cart.cart import get_cart_class\nfrom django.http import HttpRequest\nfrom django.views.decorators.http import require_POST\nfrom django.shortcuts import get_object_or_404\n\nfrom .models import Product\n\nCart = get_cart_class()\n\n\n@require_POST\ndef add_product(request: HttpRequest, product_id:int):\n    product = get_object_or_404(Product.objects.all(), pk=product_id)\n    quantity = int(request.POST.get(\"quantity\"))\n    cart = Cart.new(request)\n    cart.add(product, quantity=quantity)\n    ...\n\n\n@require_POST\ndef remove_product(request: HttpRequest):\n    item_id = request.POST.get(\"item_id\")\n    quantity = int(request.POST.get(\"quantity\"))\n    cart = Cart.new(request)\n    cart.remove(item_id=item_id, quantity=quantity)\n    ...\n\n\n@require_POST\ndef empty_cart(request: HttpRequest):\n    Cart.new(request).empty()\n    ...\n\n```\n\n## Used By\n\nThis project is used by the following companies:\n\n- [F\u00eamy bien \u00eatre](https://www.femybienetre.com/)\n\n## Development\n\nPoetry is required (not really, you can set up the environment however you want and install the requirements\nmanually) to set up a virtualenv, install it then run the following:\n\n```sh\npoetry install\npre-commit install --install-hooks\n```\n\nTests can then be run quickly in that environment:\n\n```sh\npytest\n```\n\n## Feedback\n\nIf you have any feedback, please reach out to me at tobidegnon@proton.me.\n\n## Credits\n\nThanks to [Jetbrains](https://jb.gg/OpenSource) for providing an Open Source license for this project.\n\n<img height=\"200\" src=\"https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png\" alt=\"JetBrains Logo (Main) logo.\">\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple django cart manager for your django projects.",
    "version": "7.0.3",
    "project_urls": {
        "Homepage": "https://tobi-de.github.io/dj-shop-cart/",
        "Repository": "https://github.com/Tobi-De/dj-shop-cart"
    },
    "split_keywords": [
        "django",
        "python",
        "cart",
        "shop",
        "ecommerce"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "953523d8056957530ab1e770b6028a8feff27f813cd650f71b7bc23598b2178a",
                "md5": "e81e4d718f3d2744eebfc0cb35a3db7f",
                "sha256": "e6bc130a8ea1bfbbbb8538f894827d40f09e6df425e7284261e6b7773bdb698c"
            },
            "downloads": -1,
            "filename": "dj_shop_cart-7.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e81e4d718f3d2744eebfc0cb35a3db7f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 11502,
            "upload_time": "2023-06-06T14:40:37",
            "upload_time_iso_8601": "2023-06-06T14:40:37.447867Z",
            "url": "https://files.pythonhosted.org/packages/95/35/23d8056957530ab1e770b6028a8feff27f813cd650f71b7bc23598b2178a/dj_shop_cart-7.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0d0aefc10cc3b69bd9d010fc039dd3791f13e8a8b3bc1c35907933842a45f1c0",
                "md5": "f92a3d0255cf8b8100e884ba5fe1c612",
                "sha256": "4719d75bc8b9740d752049969390cde2e4a58084a5c6e30b16023c6e38cf06ef"
            },
            "downloads": -1,
            "filename": "dj_shop_cart-7.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "f92a3d0255cf8b8100e884ba5fe1c612",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 10290,
            "upload_time": "2023-06-06T14:40:39",
            "upload_time_iso_8601": "2023-06-06T14:40:39.261464Z",
            "url": "https://files.pythonhosted.org/packages/0d/0a/efc10cc3b69bd9d010fc039dd3791f13e8a8b3bc1c35907933842a45f1c0/dj_shop_cart-7.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-06 14:40:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Tobi-De",
    "github_project": "dj-shop-cart",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dj-shop-cart"
}
        
Elapsed time: 0.14785s