Skip to main content

Easy to use django shopping multi cart.

Project description

StandWithUkraine Stand With Ukraine

NOTICE

This frameworks is a fork of another with the same name... Some improvement were made with the target in mind that increase the capabilities of the django-cart

INSTALATION

pip3 install django-new-cart

USAGE

The target of this module is to allow programmers to handle easily the cart of his/her shop web app...

Update urls.py with this url

urlpatterns += [ 
    path("cart/add/<id>/", add, name="cart_add"),
    path("cart/add/<id>/<quantity>/", add_quant, name="cart_add_quantity"),
    path("cart/remove/<id>/", remove, name="cart_remove"),
    path("cart/remove/<id>/<quantity>/", remove_quant, name="cart_remove_quantity"),
    path("cart/clear/", cart_clear, name="cart_clear"),
    path("cart/pop/", cart_pop, name="cart_pop"),
    path("cart/clear/<id>/", item_clear, name="cart_clear_id"),
    path("cart/details/<id>/", cart_detail, name="cart_details"),
    path("cart/update/", update_cart, name="cart_update"),
]

Adding an element

@require_POST
def add(request: HttpRequest, id: int):
    cart = Cart(request)
    cart.add(product=Products.objects.filter(id=id).first())
    return JsonResponse({"result": "ok", 
        "amount": cart.session[CART_SESSION_ID].get(id, {"quantity": 0})["quantity"]
    }

Get details of the cart

@require_POST
def cart_detail(request:HttpRequest, id: int):
    return JsonResponse({"result": Cart(request).get_item(id)})

Cleaning the cart

@require_POST
def cart_clear(request:HttpRequest):
    Cart(request).clear()
    return JsonResponse({"result": "ok", "amount": 0})

Remove all elements of a type from cart

@require_POST
def item_clear(request: HttpRequest, id:int):
    cart = Cart(request)
    cart.remove(product=Products.objects.filter(id=id).first())
    return JsonResponse({
        "result": "ok", 
        "amount": cart.get_sum_of("quantity") 
    })

Removing N elements from cart

@require_POST
def remove_quant(request:HttpRequest, id:int, quantity: int):
    Cart(request).add(product=Products.objects.filter(id=id).first(), quantity=quantity, action="remove")
    return JsonResponse({"result": "ok"})

Remove element

@require_POST
def remove(request:HttpRequest, id: int):
    Cart(request).decrement(product=Products.objects.filter(id=id).first())
    return JsonResponse({"result": "ok"})

Pop last element

@require_POST
def cart_pop(request:HttpRequest,):
    cart = Cart(request)
    cart.pop()
    return JsonResponse({"result": "ok",
        "amount": cart.get_sum_of("quantity")
    })

Adding N elements to cart

@require_POST
def add_quant(request:HttpRequest, id:int, quantity: int):
    cart = Cart(request)
    cart.add(Producsts.objects.filter(id=id).first(), quantity)
    return JsonResponse({"result": "ok", 
        "amount": cart.session[CART_SESSION_ID].get(id, {"quantity": quantity})["quantity"]})

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

django-new-cart-1.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_new_cart-1.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file django-new-cart-1.1.0.tar.gz.

File metadata

  • Download URL: django-new-cart-1.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for django-new-cart-1.1.0.tar.gz
Algorithm Hash digest
SHA256 9fdfb5111bef903176e56760e02bef270b739b09e73ffe5ee324efd4cbda3ded
MD5 a00fc97d517ecddd32e9dff7a8150a4f
BLAKE2b-256 9f6918a8472735b0127b80c006761337ab6d995f1cf965887acffb1f33a6c3fd

See more details on using hashes here.

File details

Details for the file django_new_cart-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_new_cart-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63aec75140b5e17434861406171a35c5b13fc3fbb9331904687e0f8addc6cce5
MD5 2997256a49e3e9182d5c6ccde4e504a1
BLAKE2b-256 61f38383bca759fb89b28b1aff81f9d23c4cd98b6ba25d3b7df37a89fa4cddaf

See more details on using hashes here.

Supported by

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