public function create(Category $category, $name, $price, $stock, $image, $description) { $errors = array(); $item = new Item($this->db); try { $item->setCategory($category); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $item->setName($name); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $item->setPrice($price); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $item->setStock($stock); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $item->setImage($image); } catch (Exception $e) { $errors[] = $e->getMessage(); } try { $item->setDescription($description); } catch (Exception $e) { $errors[] = $e->getMessage(); } if (count($errors) == 0) { $name = $this->db->quote($item->getName()); $price = $this->db->quote($item->getPrice()); $stock = $this->db->quote($item->getStock()); $image = $this->db->quote($item->getImage()); $description = $this->db->quote($item->getDescription()); $idCategory = $item->getCategory()->getId(); $query = ' INSERT INTO item (id_category, name, price, stock, image, description) VALUES(' . $idCategory . ',' . $name . ',' . $price . ',' . $stock . ',' . $image . ',' . $description . ')'; $res = $this->db->exec($query); if ($res) { $id = $this->db->lastInsertId(); if ($id) { return $this->readByID($id); } else { throw new Exception('Internal server Error'); } } } }
function getProduct($id) { //Get item from db $sql_p = "SELECT * from products WHERE product_id = '" . $id . "'"; $result_p = mysql_query($sql_p, $this->conn); if (mysql_num_rows($result_p) == 0) { return null; } $row = mysql_fetch_assoc($result_p); $temp = new Item(); $temp->amt = $row["price"]; $temp->name = $row["product_name"]; $temp->desc = $row["description"]; $temp->short_desc = $row["description"]; $temp->setImage($row["image"]); $temp->charity = $row["charity_id"]; $temp->seller = $this->getUser($row["user_id"]); return $temp; }
<?php $items = array(); $item = new Item(); $item->setName("RaumZeitLabor T-Shirt"); $item->setDescription("Das Super RZL Shirt"); $item->setImage("tshirt.jpg"); $item->addSizePrice(new SizePrice("XXL", 15.9)); $item->addSizePrice(new SizePrice("XL", 14.9)); $item->addSizePrice(new SizePrice("L", 13.9)); $item->addSizePrice(new SizePrice("M", 12.9)); $item->addSizePrice(new SizePrice("S", 11.9)); $items[] = $item; $item = new Item(); $item->setName("RZL LabCoat"); $item->setDescription("Das Pflichtprogramm für jeden Laboraten! Ein bestickter Labcoat, der auch " . "wunderbar für Ätzsessions geeignet ist. Die Bestickung wird von Unicorn oder Inte " . "mittels unserer Stickmaschine vorgenommen."); $item->setImage("labcoat.jpg"); $item->addSizePrice(new SizePrice("XXL", 15.9)); $item->addSizePrice(new SizePrice("XL", 14.9)); $item->addSizePrice(new SizePrice("L", 13.9)); $item->addSizePrice(new SizePrice("M", 12.9)); $item->addSizePrice(new SizePrice("S", 11.9)); $items[] = $item;
$item->addSizePrice(new SizePrice("M", 25.0)); $item->addSizePrice(new SizePrice("S", 25.0)); $items[] = $item; $item = new Item(); $item->setName("Zipper"); $item->setDescription("Wer mag es nicht, das flauschige Allwetterkleidungsstück für den Nerd von heute. " . "\n\nAuf Wunsch mit eigenem Schriftzug."); $item->setImage("zipper.jpg"); $item->addSizePrice(new SizePrice("XXL", 35.0)); $item->addSizePrice(new SizePrice("XL", 35.0)); $item->addSizePrice(new SizePrice("L", 35.0)); $item->addSizePrice(new SizePrice("M", 35.0)); $item->addSizePrice(new SizePrice("S", 35.0)); $items[] = $item; $item = new Item(); $item->setName("Laser-Foo"); $item->setDescription("Diverse Gegenstände, die wir erfolgreich einer Laserbehandlung unterzogen haben."); $item->setImage("pfannenwender.jpg"); $item->addSizePrice(new SizePrice("Pfannenwender mit Logo", 5.0)); $item->addSizePrice(new SizePrice("Minecraft-Spaten", 5.0)); $items[] = $item; $item = new Item(); $item->setName("Schürze"); $item->setDescription("Es soll auch Nerds geben, die sich in die Küche trauen. Das wollen wir natürlich " . "unterstützen! Die Bestickung wird von unseren Fachkräften Unicorn oder Inte mittels " . "unserer programmierbaren Stickmaschine vorgenommen."); $item->setImage("schuerze.jpg"); $item->addSizePrice(new SizePrice("XXL", 20.0)); $item->addSizePrice(new SizePrice("XL", 20.0)); $item->addSizePrice(new SizePrice("L", 20.0)); $item->addSizePrice(new SizePrice("M", 20.0)); $item->addSizePrice(new SizePrice("S", 20.0)); $items[] = $item; $targetMails = array("*****@*****.**", "*****@*****.**");