diff --git a/src/repository/product/Product.php b/src/repository/product/Product.php index 8b51506..5e94dd8 100644 --- a/src/repository/product/Product.php +++ b/src/repository/product/Product.php @@ -4,7 +4,11 @@ namespace repository\product; use Doctrine\Common\Collections\ArrayCollection; use repository\AbstractRepository; use entity\product\ProductInterface as ProductEntityInterface; +use entity\product\Product as ProductEntity; use core\Core; +use entity\currency\Euro; +use entity\price\Price; +use entity\image\UrlImage; /** * @@ -41,7 +45,29 @@ final class Product extends AbstractRepository implements ProductInterface } public function getAllProducts(): ArrayCollection - {} + { + $statement = $this->database->prepare('SELECT * FROM '.self::TABLE.';'); + $statement->execute(); + foreach ($statement->fetchAll() as $product){ + + } + } + + static public function createProduct(string $name, string $color, int $cents, int $tax, string $imagePath):ProductEntity{ + $product = new ProductEntity(); + $product->setName($name); + $product->setColor($color); + $euro = new Euro(); + $euro->setCents($cents); + $price = new Price(); + $price->setPrice($euro); + $price->setTax($tax); + $product->setPrice($price); + $image = new UrlImage(); + $image->setImage($imagePath); + $product->setImage($image); + return $product; + } public function deleteAllProducts(): void {} diff --git a/src/setup/setup.php b/src/setup/setup.php index 5dbff29..82a2f98 100644 --- a/src/setup/setup.php +++ b/src/setup/setup.php @@ -1,10 +1,6 @@ $line) { $colums = explode(',', $line); - $product = new Product(); - $product->setName($colums[0]); - $product->setColor($colums[1]); - $euro = new Euro(); - $euro->setCents((int) (floatval($colums[2]) * 100)); - $price = new Price(); - $price->setPrice($euro); - $price->setTax((int)$colums[3]); - $product->setPrice($price); - $image = new UrlImage(); - $image->setImage($colums[4]); - $product->setImage($image); + $product = ProductRepository::createProduct( + $colums[0], + $colums[1], + (int) (floatval($colums[2]) * 100), + (int)$colums[3], + $colums[4]); echo $number.'. product '.$product->getName()." added to collection...\n"; $products->add($product); }