public function add(Product $newproduct) { $productupdated = false; //check if product is already in cart if yes sum-up, if not add new product to cart if ($this->products) { foreach ($this->products as $product) { if ($product->__get('number') == $newproduct->__get('number') && $product->__get('selectedoption') == $newproduct->__get('selectedoption')) { $this->update($product->__get('uid'), $product->__get('amount') + $newproduct->__get('amount')); $productupdated = true; break; } } } if (!$productupdated) { $this->products[] = $newproduct; } $this->updateBalance(); }