id = $product->id; $this->name = $product->name; $this->product = $product; $this->qty = $qty; $this->price = $product->getPrice(); $this->subtotal = $product->getPrice() * $qty; } public function updateAttribute(array $newItemData) { if (isset($newItemData['qty'])) { $this->qty = $newItemData['qty']; $this->subtotal = $this->price * $this->qty; } if (isset($newItemData['item_discount'])) { $this->setItemDiscount($newItemData['item_discount']); } return $this; } public function setItemDiscount(int $discount) { $this->item_discount = $discount; $this->item_discount_subtotal = $discount * $this->qty; } }