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

Please add example using Ajax to edit quantities or delete #26

Open
beckastar opened this issue Jun 14, 2016 · 1 comment
Open

Please add example using Ajax to edit quantities or delete #26

beckastar opened this issue Jun 14, 2016 · 1 comment

Comments

@beckastar
Copy link
Contributor

I apologize. I don't know where else to go for support, and I am trying to figure out how to pass an id from my cart to my view so that I can edit quantities or delete an item by clicking the button. It would be so great to see an example of this with Ajax. I've asked a SO question here

@joaovitorsilvestre
Copy link

To pass the id to template, you can just do the following:

#views.py
from carton.cart import Cart
def show(request):
    cart = Cart(request.session)
    response = []
    for item in cart.items:
       response.append({'name': item.product.name,'id': item.product.custom_id, 'price': item.subtotal})
    return render(request, 'home/show.html', {'items': response})

In your template, in this case 'show.html', do something lick this:

{% for item in items %}
    <p>item name:</p> {{item.name}}
    <p>item id:</p> {{item.id}}
    <p>item price:</p> {{item.price}}
{% endfor %}

In https://github.com/lazybird/django-carton/blob/master/carton/tests/views.py have a function called remove, it's an example of how delete items. Put this function in some view, and make a javascript to send a 'POST' with a 'product_id'. If you need some help with this, just ask. :)

Sorry if i get something wrong, but that was what I understand about your question.

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

2 participants