mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-11-22 10:11:04 +01:00
Implemented product list
This commit is contained in:
parent
560c70de38
commit
1bc7219caa
@ -2,6 +2,7 @@
|
|||||||
namespace controller\product;
|
namespace controller\product;
|
||||||
|
|
||||||
use controller\AbstractController;
|
use controller\AbstractController;
|
||||||
|
use repository\product\Product as ProductRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -11,7 +12,10 @@ use controller\AbstractController;
|
|||||||
final class Product extends AbstractController implements ProductInterface
|
final class Product extends AbstractController implements ProductInterface
|
||||||
{
|
{
|
||||||
public function list(): void
|
public function list(): void
|
||||||
{}
|
{
|
||||||
|
$productRepository = new ProductRepository($this->core->getDatabase());
|
||||||
|
$this->render('product/list.html.twig',['products'=>$productRepository->getAllProducts()->toArray()]);
|
||||||
|
}
|
||||||
|
|
||||||
public function colorFilter(string $color): void
|
public function colorFilter(string $color): void
|
||||||
{}
|
{}
|
||||||
|
@ -21,6 +21,6 @@ interface ImageInterface
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getImageThumbnail():string;
|
public function getThumbnail():string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ final class UrlImage implements ImageInterface
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* @see \entity\image\ImageInterface::getImageThumbnail()
|
* @see \entity\image\ImageInterface::getImageThumbnail()
|
||||||
*/
|
*/
|
||||||
public function getImageThumbnail(): string
|
public function getThumbnail(): string
|
||||||
{
|
{
|
||||||
return $this->path;
|
return str_replace('200/300', '200/200', $this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getImage(): string
|
public function getImage(): string
|
||||||
|
@ -10,7 +10,9 @@ use PHPUnit\Framework\TestCase;
|
|||||||
*/
|
*/
|
||||||
class UrlImageTest extends TestCase
|
class UrlImageTest extends TestCase
|
||||||
{
|
{
|
||||||
const IMAGE_URL = 'http://dummy.image/test.jpg';
|
const IMAGE_URL = 'http://dummy.image/200/300/test.jpg';
|
||||||
|
|
||||||
|
const IMAGE_THUMB_URL = 'http://dummy.image/200/200/test.jpg';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var UrlImage
|
* @var UrlImage
|
||||||
@ -27,7 +29,7 @@ class UrlImageTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testThumbnail():void{
|
public function testThumbnail():void{
|
||||||
$this->assertEquals(self::IMAGE_URL, $this->urlImage->getImageThumbnail());
|
$this->assertEquals(self::IMAGE_THUMB_URL, $this->urlImage->getThumbnail());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,23 +37,30 @@ final class Product extends AbstractRepository implements ProductInterface
|
|||||||
$statement->execute([
|
$statement->execute([
|
||||||
$product->getName(),
|
$product->getName(),
|
||||||
$product->getColor(),
|
$product->getColor(),
|
||||||
$product->getPrice()->getNetto()->getCents(),
|
$product->getPrice()
|
||||||
$product->getPrice()->getTax(),
|
->getNetto()
|
||||||
$product->getImage()->getImage(),
|
->getCents(),
|
||||||
|
$product->getPrice()
|
||||||
|
->getTax(),
|
||||||
|
$product->getImage()
|
||||||
|
->getImage()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllProducts(): ArrayCollection
|
public function getAllProducts(): ArrayCollection
|
||||||
{
|
{
|
||||||
$statement = $this->database->prepare('SELECT * FROM '.self::TABLE.';');
|
$statement = $this->database->prepare('SELECT * FROM ' . self::TABLE . ';');
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
foreach ($statement->fetchAll() as $product){
|
$products = new ArrayCollection();
|
||||||
|
foreach ($statement->fetchAll() as $product) {
|
||||||
|
$products->add($this->createProduct($product['name'], $product['color'], $product['price'], $product['tax'], $product['image']));
|
||||||
}
|
}
|
||||||
|
return $products;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function createProduct(string $name, string $color, int $cents, int $tax, string $imagePath):ProductEntity{
|
static public function createProduct(string $name, string $color, int $cents, int $tax, string $imagePath): ProductEntity
|
||||||
|
{
|
||||||
$product = new ProductEntity();
|
$product = new ProductEntity();
|
||||||
$product->setName($name);
|
$product->setName($name);
|
||||||
$product->setColor($color);
|
$product->setColor($color);
|
||||||
@ -69,9 +76,6 @@ final class Product extends AbstractRepository implements ProductInterface
|
|||||||
return $product;
|
return $product;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteAllProducts(): void
|
|
||||||
{}
|
|
||||||
|
|
||||||
public function getProductById(int $id): ProductEntityInterface
|
public function getProductById(int $id): ProductEntityInterface
|
||||||
{}
|
{}
|
||||||
}
|
}
|
@ -12,11 +12,6 @@ interface ProductInterface
|
|||||||
{
|
{
|
||||||
public function getAllProducts():ArrayCollection;
|
public function getAllProducts():ArrayCollection;
|
||||||
|
|
||||||
/**
|
|
||||||
* Just exists for maintaining reasons ;)
|
|
||||||
*/
|
|
||||||
public function deleteAllProducts():void;
|
|
||||||
|
|
||||||
public function addProducts(ArrayCollection $products):void;
|
public function addProducts(ArrayCollection $products):void;
|
||||||
|
|
||||||
public function getProductById(int $id):ProductEntityInterface;
|
public function getProductById(int $id):ProductEntityInterface;
|
||||||
|
18
src/router/Button.php
Normal file
18
src/router/Button.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
namespace router;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A button containes out of a link and post parameters
|
||||||
|
* @author kevinfrantz
|
||||||
|
* @deprecated
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class Button
|
||||||
|
{
|
||||||
|
private $link;
|
||||||
|
|
||||||
|
public function __construct(Link $link,array $post){
|
||||||
|
$this->link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,11 +2,11 @@
|
|||||||
namespace router;
|
namespace router;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* A link containes out of get parameters
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Link
|
final class Link
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* ArrayCollection would be nicer but I have to save time ;)
|
* ArrayCollection would be nicer but I have to save time ;)
|
||||||
|
@ -50,7 +50,7 @@ final class Router implements RouterInterface
|
|||||||
return $userController->register();
|
return $userController->register();
|
||||||
}
|
}
|
||||||
case 'product':
|
case 'product':
|
||||||
$productController = new Product();
|
$productController = new Product($this->core);
|
||||||
switch ($this->get['action']) {
|
switch ($this->get['action']) {
|
||||||
case 'list':
|
case 'list':
|
||||||
return $productController->list();
|
return $productController->list();
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
name,color,price_eur,tax,image
|
name,color,price_eur,tax,image
|
||||||
Continental,Goldenrod,73.19,19,https://picsum.photos/200/300/?random
|
Continental,Goldenrod,73.19,19,https://picsum.photos/200/300/?image=1
|
||||||
Mustang,Goldenrod,49.75,20,https://picsum.photos/200/300/?random
|
Mustang,Goldenrod,49.75,20,https://picsum.photos/200/300/?image=2
|
||||||
Grand Vitara,Turquoise,19.06,21,https://picsum.photos/200/300/?random
|
Grand Vitara,Turquoise,19.06,21,https://picsum.photos/200/300/?image=3
|
||||||
Pajero,Puce,35.7,22,https://picsum.photos/200/300/?random
|
Pajero,Puce,35.7,22,https://picsum.photos/200/300/?image=4
|
||||||
EXP,Aquamarine,26.13,23,https://picsum.photos/200/300/?random
|
EXP,Aquamarine,26.13,23,https://picsum.photos/200/300/?image=5
|
||||||
Golf,Fuscia,50.64,24,https://picsum.photos/200/300/?random
|
Golf,Fuscia,50.64,24,https://picsum.photos/200/300/?image=6
|
||||||
Explorer Sport Trac,Puce,76.08,25,https://picsum.photos/200/300/?random
|
Explorer Sport Trac,Puce,76.08,25,https://picsum.photos/200/300/?image=7
|
||||||
Rally Wagon 2500,Red,56.14,26,https://picsum.photos/200/300/?random
|
Rally Wagon 2500,Red,56.14,26,https://picsum.photos/200/300/?image=8
|
||||||
J,Turquoise,44.02,27,https://picsum.photos/200/300/?random
|
J,Turquoise,44.02,27,https://picsum.photos/200/300/?image=9
|
||||||
Astro,Turquoise,33.65,28,https://picsum.photos/200/300/?random
|
Astro,Turquoise,33.65,28,https://picsum.photos/200/300/?image=10
|
||||||
Sierra 2500,Purple,26.97,29,https://picsum.photos/200/300/?random
|
Sierra 2500,Purple,26.97,29,https://picsum.photos/200/300/?image=11
|
||||||
Continental GT,Fuscia,30.26,30,https://picsum.photos/200/300/?random
|
Continental GT,Fuscia,30.26,30,https://picsum.photos/200/300/?image=12
|
||||||
Continental GT,Mauv,63.78,31,https://picsum.photos/200/300/?random
|
Continental GT,Mauv,63.78,31,https://picsum.photos/200/300/?image=13
|
||||||
Esteem,Goldenrod,61.47,32,https://picsum.photos/200/300/?random
|
Esteem,Goldenrod,61.47,32,https://picsum.photos/200/300/?image=14
|
||||||
LS,Aquamarine,23.38,33,https://picsum.photos/200/300/?random
|
LS,Aquamarine,23.38,33,https://picsum.photos/200/300/?image=15
|
||||||
Outlook,Teal,66.99,34,https://picsum.photos/200/300/?random
|
Outlook,Teal,66.99,34,https://picsum.photos/200/300/?image=16
|
||||||
911,Orange,25.83,35,https://picsum.photos/200/300/?random
|
911,Orange,25.83,35,https://picsum.photos/200/300/?image=17
|
||||||
Jetta,Green,42.49,36,https://picsum.photos/200/300/?random
|
Jetta,Green,42.49,36,https://picsum.photos/200/300/?image=18
|
||||||
Bronco,Pink,60.81,37,https://picsum.photos/200/300/?random
|
Bronco,Pink,60.81,37,https://picsum.photos/200/300/?image=19
|
||||||
Savana,Yellow,63.5,38,https://picsum.photos/200/300/?random
|
Savana,Yellow,63.5,38,https://picsum.photos/200/300/?image=20
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
<?php
|
|
@ -1 +0,0 @@
|
|||||||
<?php
|
|
24
src/template/product/list.html.twig
Normal file
24
src/template/product/list.html.twig
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{% extends 'frames/default.html.twig' %}
|
||||||
|
{% block title %}product overview{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="card-columns">
|
||||||
|
{% for product in products %}
|
||||||
|
<div class="card" style="width: 18rem;">
|
||||||
|
<img class="card-img-top" src="{{ product.getImage.getThumbnail }}" alt="Card image cap">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">
|
||||||
|
{{ product.getName }} <i>({{ product.getColor }})</i>
|
||||||
|
</h5>
|
||||||
|
<span class="card-text">
|
||||||
|
<b>price:</b>
|
||||||
|
<ul>
|
||||||
|
<li>{{ product.getPrice.getNetto.getFloat }} {{ product.getPrice.getNetto.getSymbol }} <i>(net)</i></li>
|
||||||
|
<li>{{ product.getPrice.getGross.getFloat }} {{ product.getPrice.getGross.getSymbol }} <i>(gross)</i></li>
|
||||||
|
</ul>
|
||||||
|
</span>
|
||||||
|
<a href="#" class="btn btn-primary">Add to basket</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -1 +0,0 @@
|
|||||||
<?php
|
|
@ -1 +0,0 @@
|
|||||||
<?php
|
|
@ -1 +0,0 @@
|
|||||||
<?php
|
|
Loading…
Reference in New Issue
Block a user