Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 1.8: get_cart fails in templates #21

Open
alexandervlpl opened this issue Aug 21, 2015 · 5 comments
Open

Django 1.8: get_cart fails in templates #21

alexandervlpl opened this issue Aug 21, 2015 · 5 comments

Comments

@alexandervlpl
Copy link

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
Copy link

bastiW commented Sep 9, 2015

Did you solve it already?

@alexandervlpl
Copy link
Author

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

@lionelsaintecluque
Copy link

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
Copy link
Author

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

@lionelsaintecluque
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants