public function add(Product $toBeAdded) { foreach ($this->products as $product) { if ($product->getUniqueString() === $toBeAdded->getUniqueString()) { throw new \Exception("You cannot have two products with the same id"); } } $key = $toBeAdded->getUniqueString(); $this->products[$key] = $toBeAdded; }
public function add(Product $toBeAdded) { $stmt = $this->database->prepare("INSERT INTO `store`.`Products` (\n\t\t\t`pk` , `title` , `description` , `price` )\n\t\t\t\tVALUES (?, ?, ?, ?)"); if ($stmt === FALSE) { throw new \Exception($this->database->error); } $pk = $toBeAdded->getUniqueString(); $title = $toBeAdded->getTitle(); $description = $toBeAdded->getDescription(); $price = $toBeAdded->getPrice(); $stmt->bind_param('sssd', $pk, $title, $description, $price); $stmt->execute(); }
public function __construct(Product $p) { $this->productID = $p->getUniqueString(); }