Beispiel #1
0
def ccbasket_adapter(request):
    """An adapter function for django-ccbasket"""
    # get the checkout
    try:
        checkout = Checkout.objects.get(session_id=request.session.session_key)
    except Checkout.DoesNotExist:
        checkout = Checkout()
        checkout.session_id = request.session.session_key
        checkout.save()
    # get the basket
    basket_name = getattr(settings, "CCBASKET_SESSION_KEY_NAME", ccbasket_settings.CCBASKET_SESSION_KEY_NAME)
    basket = request.session[basket_name]
    # now set up the items
    checkout.items = basket.basketitem_set.all()
    # and item total
    checkout.item_total = basket.total_price()
    # and the lines
    lines = 0
    for b in basket.basketitem_set.all():
        lines += b.quantity
    checkout.lines = lines
    # attatch and save the session
    request.session["cccheckout"] = checkout
    request.session.save()
    # return it
    return checkout