-
Notifications
You must be signed in to change notification settings - Fork 113
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
Unable to do add to cart in Quick View page #28
Comments
Yeah, you are right, and also the cart is not updating on every page. If you get the solution, please explain to me too. |
i Solved it by adding same javascript but still name is not updating in popover of quick view page and console.log(cart) is showing the following values
|
Hi jaishivnani can you give the JS code for the productview page??? |
Hello Abhishek,
JS code is there on my github for product view page.
giving it again
{% extends 'shop/basic.html' %}
{% block title%} {{product.product_name}} - My Awesome Cart {% endblock %}
{% block body %}
<div class="container my-4">
<div class="row">
<div class="col-md-4">
<div class="row">
<img src="/media/{{product.image}}" width="360px" height="400px">
</div>
<div class="row">
<button class="btn btn-primary mx-3 my-1">Buy Now</button>
<button class="btn btn-primary mx-3 my-1">Add To Cart</button>
</div>
</div>
<div class="col-md-8">
<h5> {{product.product_name}}</h5>
<p><b>Rs.{{product.price}}</b></p>
<p>{{product.desc}}</p>
</div>
</div>
</div>
{% endblock %}
{% block js %}
<script>
console.log("working")
if (localStorage.getItem('cart') == null) {
// < !--creating object array-- >
var cart = {};
}
else {
// < !--Converting string to object array using JSON.parse-- >
cart = JSON.parse(localStorage.getItem('cart'));
document.getElementById('cart').innerHTML = Object.keys(cart).length;
}
$('.cart').click(function () {
console.log('clicked');
var idstr = this.id.toString();
console.log(idstr);
if (cart[idstr] != undefined) {
cart[idstr] = cart[idstr] + 1;
}
else {
cart[idstr] = 1;
}
console.log(cart);
localStorage.setItem('cart', JSON.stringify(cart));
document.getElementById('cart').innerHTML = Object.keys(cart).length;
});
$('#popcart').popover();
document.getElementById("popcart").setAttribute('data-content', '<h5>Cart
for your items in my shopping cart</h5>');
</script>
{% endblock js %}
…On Sun, Nov 15, 2020 at 5:12 PM Abhishek rana ***@***.***> wrote:
Hi jaishivnani can you give the JS code for the productview page???
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#28 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHMAOIXADV6NLL4A4C2WZWDSP65BFANCNFSM4S5SB34A>
.
|
mine is also same but idk why it's not working |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: