mirror of
				https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
				synced 2025-10-31 17:18:59 +00:00 
			
		
		
		
	Implemented product list
This commit is contained in:
		| @@ -2,6 +2,7 @@ | ||||
| namespace controller\product; | ||||
|  | ||||
| use controller\AbstractController; | ||||
| use repository\product\Product as ProductRepository; | ||||
|  | ||||
| /** | ||||
|  * | ||||
| @@ -11,7 +12,10 @@ use controller\AbstractController; | ||||
| final class Product extends AbstractController implements ProductInterface | ||||
| { | ||||
|     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 | ||||
|     {} | ||||
|   | ||||
| @@ -21,6 +21,6 @@ interface ImageInterface | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getImageThumbnail():string; | ||||
|     public function getThumbnail():string; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -17,9 +17,9 @@ final class UrlImage implements ImageInterface | ||||
|      * {@inheritDoc} | ||||
|      * @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 | ||||
|   | ||||
| @@ -10,7 +10,9 @@ use PHPUnit\Framework\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 | ||||
| @@ -27,7 +29,7 @@ class UrlImageTest extends TestCase | ||||
|     } | ||||
|      | ||||
|     public function testThumbnail():void{ | ||||
|         $this->assertEquals(self::IMAGE_URL, $this->urlImage->getImageThumbnail()); | ||||
|         $this->assertEquals(self::IMAGE_THUMB_URL, $this->urlImage->getThumbnail()); | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -37,9 +37,13 @@ final class Product extends AbstractRepository implements ProductInterface | ||||
|             $statement->execute([ | ||||
|                 $product->getName(), | ||||
|                 $product->getColor(), | ||||
|                 $product->getPrice()->getNetto()->getCents(), | ||||
|                 $product->getPrice()->getTax(), | ||||
|                 $product->getImage()->getImage(), | ||||
|                 $product->getPrice() | ||||
|                     ->getNetto() | ||||
|                     ->getCents(), | ||||
|                 $product->getPrice() | ||||
|                     ->getTax(), | ||||
|                 $product->getImage() | ||||
|                     ->getImage() | ||||
|             ]); | ||||
|         } | ||||
|     } | ||||
| @@ -48,12 +52,15 @@ final class Product extends AbstractRepository implements ProductInterface | ||||
|     { | ||||
|         $statement = $this->database->prepare('SELECT * FROM ' . self::TABLE . ';'); | ||||
|         $statement->execute(); | ||||
|         $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->setName($name); | ||||
|         $product->setColor($color); | ||||
| @@ -69,9 +76,6 @@ final class Product extends AbstractRepository implements ProductInterface | ||||
|         return $product; | ||||
|     } | ||||
|  | ||||
|     public function deleteAllProducts(): void | ||||
|     {} | ||||
|  | ||||
|     public function getProductById(int $id): ProductEntityInterface | ||||
|     {} | ||||
| } | ||||
| @@ -12,11 +12,6 @@ interface ProductInterface | ||||
| { | ||||
|     public function getAllProducts():ArrayCollection; | ||||
|      | ||||
|     /** | ||||
|      * Just exists for maintaining reasons ;) | ||||
|      */ | ||||
|     public function deleteAllProducts():void; | ||||
|      | ||||
|     public function addProducts(ArrayCollection $products):void; | ||||
|      | ||||
|     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; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * A link containes out of get parameters | ||||
|  * @author kevinfrantz | ||||
|  *         | ||||
|  */ | ||||
| class Link | ||||
| final class Link | ||||
| { | ||||
|     /**  | ||||
|      * ArrayCollection would be nicer but I have to save time ;) | ||||
|   | ||||
| @@ -50,7 +50,7 @@ final class Router implements RouterInterface | ||||
|                             return $userController->register(); | ||||
|                     } | ||||
|                 case 'product': | ||||
|                     $productController = new Product(); | ||||
|                     $productController = new Product($this->core); | ||||
|                     switch ($this->get['action']) { | ||||
|                         case 'list': | ||||
|                             return $productController->list(); | ||||
|   | ||||
| @@ -1,21 +1,21 @@ | ||||
| name,color,price_eur,tax,image | ||||
| Continental,Goldenrod,73.19,19,https://picsum.photos/200/300/?random | ||||
| Mustang,Goldenrod,49.75,20,https://picsum.photos/200/300/?random | ||||
| Grand Vitara,Turquoise,19.06,21,https://picsum.photos/200/300/?random | ||||
| Pajero,Puce,35.7,22,https://picsum.photos/200/300/?random | ||||
| EXP,Aquamarine,26.13,23,https://picsum.photos/200/300/?random | ||||
| Golf,Fuscia,50.64,24,https://picsum.photos/200/300/?random | ||||
| Explorer Sport Trac,Puce,76.08,25,https://picsum.photos/200/300/?random | ||||
| Rally Wagon 2500,Red,56.14,26,https://picsum.photos/200/300/?random | ||||
| J,Turquoise,44.02,27,https://picsum.photos/200/300/?random | ||||
| Astro,Turquoise,33.65,28,https://picsum.photos/200/300/?random | ||||
| Sierra 2500,Purple,26.97,29,https://picsum.photos/200/300/?random | ||||
| Continental GT,Fuscia,30.26,30,https://picsum.photos/200/300/?random | ||||
| Continental GT,Mauv,63.78,31,https://picsum.photos/200/300/?random | ||||
| Esteem,Goldenrod,61.47,32,https://picsum.photos/200/300/?random | ||||
| LS,Aquamarine,23.38,33,https://picsum.photos/200/300/?random | ||||
| Outlook,Teal,66.99,34,https://picsum.photos/200/300/?random | ||||
| 911,Orange,25.83,35,https://picsum.photos/200/300/?random | ||||
| Jetta,Green,42.49,36,https://picsum.photos/200/300/?random | ||||
| Bronco,Pink,60.81,37,https://picsum.photos/200/300/?random | ||||
| Savana,Yellow,63.5,38,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/?image=2 | ||||
| Grand Vitara,Turquoise,19.06,21,https://picsum.photos/200/300/?image=3 | ||||
| Pajero,Puce,35.7,22,https://picsum.photos/200/300/?image=4 | ||||
| EXP,Aquamarine,26.13,23,https://picsum.photos/200/300/?image=5 | ||||
| Golf,Fuscia,50.64,24,https://picsum.photos/200/300/?image=6 | ||||
| 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/?image=8 | ||||
| J,Turquoise,44.02,27,https://picsum.photos/200/300/?image=9 | ||||
| Astro,Turquoise,33.65,28,https://picsum.photos/200/300/?image=10 | ||||
| Sierra 2500,Purple,26.97,29,https://picsum.photos/200/300/?image=11 | ||||
| Continental GT,Fuscia,30.26,30,https://picsum.photos/200/300/?image=12 | ||||
| Continental GT,Mauv,63.78,31,https://picsum.photos/200/300/?image=13 | ||||
| Esteem,Goldenrod,61.47,32,https://picsum.photos/200/300/?image=14 | ||||
| LS,Aquamarine,23.38,33,https://picsum.photos/200/300/?image=15 | ||||
| Outlook,Teal,66.99,34,https://picsum.photos/200/300/?image=16 | ||||
| 911,Orange,25.83,35,https://picsum.photos/200/300/?image=17 | ||||
| Jetta,Green,42.49,36,https://picsum.photos/200/300/?image=18 | ||||
| Bronco,Pink,60.81,37,https://picsum.photos/200/300/?image=19 | ||||
| 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 | ||||
		Reference in New Issue
	
	Block a user