I’m working on a project for work similar to a shopping cart. Everything works except for the item count next to the shopping cart. the shopping cart icon is part of the navigation (topNav.php) and like any shopping cart I like to add the total count of the of items next to the cart icon and maintain if not refresh the count when i moved to a different page.
I like to be able to count the number of items which is stored in the localStorage but when I move to a different page the count disappears. as of know the count works but it only works on the page that the user selects the items from. if the user clicks the cart icon, the count doesn’t appear. I know what’s going on but I’m unable to find a way to resolve my problem.
I tried AJAX, javascript, but i’m missing something that i cant put my finger on. i know its hard without looking at sample code but the code got a little complicated and it would just add to the confusion.
Im also trying to avoid from using thirdpart app to fix this problem such as jquery.
Looking for ideas, suggestions, sample code that could give me some directions
Thank you,
r
Well if you feel the code is a bit complicated and you can’t show a basic example, you should probably try to start there and see if you can recreate the problem in a simpler way. Without seeing what you are actually doing in code, it is hard to say where you are going wrong.
When you click the icon, does the count in localstorage still exist? is it erased? If it is still there, do you properly pull the value out when the user clicks? Again, hard to tell without seeing what you are doing. Even if you provide a website that we can visit and debug, that would help. But the fact that you can’t show a simple example of what is wrong tells us that either you need to do some serious code reworking/refactoring or you don’t fully understand the problem to the point of showing us a bare bones example of the problem.
It sounds like session_start(); is missing, where cart items might be saved to a session key like $_SESSION['cart'] but on the next page $_SESSION['cart'] can’t be read as session was not started.
When you click the icon, does the count in localstorage still exist? is it erased? If it is still there, do you properly pull the value out when the user clicks? Again, hard to tell without seeing what you are doing. Even if you provide a website that we can visit and debug, that would help. But the fact that you can’t show a simple example of what is wrong tells us that either you need to do some serious code reworking/refactoring or you don’t fully understand the problem to the point of showing us a bare bones example of the problem.