Adding Items to the cart will increase the cart jobs count while emptying the cart or removing items from the cart will not decrease the total number displayed.

I tracked this issue and found the following.

The constructor is assigning the SESSION to the cart variable by reference.
Emptying the cart will remove this reference by assigning a new empty array to the cart variable which will make it impossible at this case to update the values stored in the session.

<?php
protected function __construct() {
  if (!isset($_SESSION[$this->session_key])) {
    $_SESSION[$this->session_key] = array();
  }
  $this->cart = &$_SESSION[$this->session_key];
}
?>
<?php
public function emptyCart() {
  $this->cart = array();
}
?>

I recommend using manipulating the SESSION values directly without using a reference.

Comments

mqanneh created an issue. See original summary.

mqanneh’s picture

Title: Jobs in cart number is wrong » Jobs number in cart is wrong
Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new2.86 KB
mqanneh’s picture

Issue summary: View changes
mqanneh’s picture

Issue summary: View changes
berdir’s picture

I'm not sure I understand. Would be great to expand our test coverage to show the bug :)

mqanneh’s picture

just try to add items to the cart then remove done of them.
When you add items the cart counter will be increased while removing items won't change the count.

apply my patchand test again
;)

leksat’s picture

Status: Needs review » Postponed (maintainer needs more info)

I can't reproduce this. For me $this->cart = array() does not break the reference to $_SESSION[$this->session_key]. See https://3v4l.org/rQ8jE

Maybe this is somehow related to #2629800: PDOException: When trying to empty an empty cart?

mqanneh’s picture

@leksat to reproduce this ...
try removing some items from your cart and check the cart menu item, it will not change.

apply the patch and try again.

Status: Postponed (maintainer needs more info) » Needs work

The last submitted patch, 2: jobs_number_in_cart_is_wrong-2630104-2.patch, failed testing.

mqanneh’s picture

Status: Needs work » Needs review