deleting cart item issue
-
I was testing the plugin to see if I can use it on future projects and I have found a little bug that sometimes happens when deleting an item at the cart.
It seems that when the user deletes an item and later tries to add a new one, the new item moves out of the cart one of current ones. So I made some checks and tested while seeing what was being added at the database ( wp_shop_cart table), and saw that all the items were there, however, they two related with the issue were sharing the same “sess_group” value, and only the last one was the one that was being shown at the cart front end.
So I thought this was the problem, and started to debug a little more.
I found that when calling the add_to_cart method (at com_shop.helpers.cat.php) it is using the length of the session cart object as value of the group of the new item:
$k = count($_SESSION[‘cart’] > 0) ? count($_SESSION[‘cart’]) : 0; //–>around line 288
so as it is not checking that the value is already being used by other of the cart items then when a value overlaps to an existing one the bug jumps.
I am not a coding expert, in fact I am just a designer. I have been able to fixit it replacing that line with the following:
$maxGroup = -1;
while ($p = $this->get_item()) {
$maxGroup = max ($maxGroup, $p->group );
echo ‘g-> ‘ .$output;
}
$k = count($_SESSION[‘cart’] > 0 ) ? $maxGroup+1 : 0;
Not sure if it is the best way to solve this bug, but at least it is working for me.
Please if there is a better way to do it please tell us, or if you know this fix above may affect other piece of code.Thanks
pd: I am not a native english speaker, so my apologies about my english.
- The topic ‘deleting cart item issue’ is closed to new replies.