Cart Quantity Bug
Hey there!
I have encountered a few bugs with the quantity in the cart. I am not sure if they are all separate, so I am making individual posts for each.
You can reproduce the bug by following these steps:
- Select Product 19
- Add to Cart
- Click "View Cart"
- Up or Lower Quantity.
Upping the quantity seems to not work anymore once you click "view cart" through the navbar.
The bug also seems to persist when going through the store itself.
You can reproduce the bug by going through the shop to product 19. Then selecting inside the page the quantity.
This one I have not yet found how to re-produce. Reloading the page will fix this bug.
I found another one around the view cart function in which the window remains open and clothes can't be removed from inside the cart.
Here is a GIF to show what happens. First time the window closes and I get a message "Product removed". When trying to remove it again, the view cart window does not close anymore.
Update:
While trying to find a fix for the issue I started looking at the cart.php in ....\system\cart\cart.php, as I was getting errors for an undefined array key "weight" in line 199.
I will keep looking for a fix, I feel the one in 1. and 2. might be a good one to look at either way, that's why I included them. My current lead is 3.
My first assumption was, that the problem lies with the overwriting values in the updateCart() method in the loop that iterates over the products, the code uses $product instead of $prod when checking if the product exists in the products list.
Here $product would be undefined at the point of the check?
That did not fix the issue, but might be interesting for you.
Another idea could be that product data coming in includes its own quantity field that ends up overwriting the cart's stored quantity during the merge in updateCart()?
I am looking particularly at line:
$prod = array_merge($prod, $product);
An idea for a fix was to merge in reverse order into:
$prod = array_merge($product, $prod);
My hope was that this way, if both arrays have a quantity key, the one in $prod (your cart’s value) will be kept. Which did not seem to be a fix either. Unsetting the quantity from the product array so that it doesn't override the cart's quantity also did not fix the issue.
My current lead is that it could have to do with the cart key generation in add() and URL Construction in updateCart(). The URL in updateCart only includes the product ID and slug, but not the unique key that was originally created. The remove and update methods expect the unique cart key in order to locate the item. So this would mean that when I try to remove or update an item from the navbar view, the code isn't finding the matching key in $this->products.
Thank you for testing and reporting bugs.
Some of the bugs were introduced by recent changes to theme that add more ajax/spa support while some cart js code was not fully updated to support all cases.
I updated js code and fixed some newly discovered bugs, I checked product/cart page remove/update and it works fine now.
Please redownload latest.zip and update the files on your server, you might need to clear browser cache to load changed js files.
Let me know if there are still things that don't work.
Thank you for your quick response!
I have not yet tried it out on my own install, so I did some more testing on the demo itself.
I am using Firefox for this particular test and could reproduce it in chrome on the live demo:
Here you can see me adding items, deleting them and then getting an undefined as a result.
How I could reproduce this:
- Add an item multiple times (in my case 7) to the cart through the shop window.
- Go to "Cart View".
- Remove items through navbar view.
- Get "undefined" error message
Thanks for the bug report, it's fixed in latest.zip you might need to clear browser cache to load new js files on demo.
Hey there!
Thank you so much for your fast response. I have applied the fixes in latest.zip, but for me the quantity still seems buggy.
Here are a few screens of what's happening for me, tested on firefox and chrome.
This is on my own installation:
-
Quantity through shop does not work, only works after refreshing the page. Happens both in Chrome and Firefox on Windows
-
Getting undefined when viewing card and then removing items through navbar, undefined only appears after scrolling down.
This is on the live demo:
-
Quantity increases in increments of 2 instead of 1.
-
Quantity can't be deleted through navbar without causing follow-up bugs. (See GIF, I only added 1 item, but cart shows 4)
Thanks for testing.
I was able to reproduce the cart product remove not working when product has options/subscription and fixed it in the latest.zip and updated demo.
The quantity increase bug I think it might be caused by browser cache loading old js files, please try to clear browser cache.