lazybird / django-carton

A simple and lightweight application for shopping carts and wish lists.
Other
274 stars 101 forks source link

Django 1.8: get_cart fails in templates #21

Open alexandervlpl opened 9 years ago

alexandervlpl commented 9 years ago

I have django-carton installed correctly in my Django 1.8 project, and I can use the Cart object in my views as expected to add, delete and access items. The get_cart template tag does not seem to work, however. I included the carton_tags as documented:

{% load carton_tags %}
{% get_cart as cart %}

It looks like cart is just None. The items list is empty. To access the items in my template, I have to pass them in from the view like this:

def basket_view(request,company_name,webshop_id):
    cart = Cart(request.session)
    context = {"items": cart.items}
    return render(request,"frontpage/company/webshop/basket.html",context=context)

Can anyone reproduce this? Am I missing something here?

bastiW commented 9 years ago

Did you solve it already?

alexandervlpl commented 9 years ago

No, this is the only way I can use the cart in my project.

lionelsaintecluque commented 8 years ago

Hello

I have the same issue and I do not know how to investigate. Can someone help me ?

I have no clue about where to start.

alexandervlpl commented 8 years ago

@lionelsaintecluque : is adding the cart to your template contexts not working? This was my workaround (see above).

lionelsaintecluque commented 8 years ago

I fixed the bug now.

In cart.py Iine 44 : self.session_key = session_key or carton_settings.CART_SESSION_KEY returns a list of a single item, this item is None. Then the block of code starting with : if self.session_key in self.session: fails. I catched the error with the following patch : try : products_queryset = self.get_queryset().filter(pk__in=ids_in_cart) except : products_queryset = []

Thanks for your reply.