mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-12-22 23:25:03 +01:00
Refactored function
This commit is contained in:
parent
0ace91c6a7
commit
560c70de38
@ -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
|
||||
{}
|
||||
|
@ -1,10 +1,6 @@
|
||||
<?php
|
||||
use core\Core;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use entity\product\Product;
|
||||
use entity\currency\Euro;
|
||||
use entity\price\Price;
|
||||
use entity\image\UrlImage;
|
||||
use repository\product\Product as ProductRepository;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
@ -38,18 +34,12 @@ $lines = explode("\n", trim(file_get_contents(__DIR__ . '/monking/product.csv'))
|
||||
unset($lines[0]);
|
||||
foreach ($lines as $number=>$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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user