Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 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();
 }
Esempio n. 3
0
 public function __construct(Product $p)
 {
     $this->productID = $p->getUniqueString();
 }