mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-11-01 00:53:10 +01:00
In between commit implementing basket
This commit is contained in:
parent
9f059d1202
commit
7470686c56
@ -2,6 +2,10 @@
|
|||||||
namespace controller\order;
|
namespace controller\order;
|
||||||
|
|
||||||
use controller\AbstractDefaultController;
|
use controller\AbstractDefaultController;
|
||||||
|
use core\CoreInterface;
|
||||||
|
use repository\order\OrderInterface as OrderRepositoryInterface;
|
||||||
|
use repository\product\ProductInterface as ProductRepositoryInterface;
|
||||||
|
use repository\product\Product as ProductRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -10,15 +14,48 @@ use controller\AbstractDefaultController;
|
|||||||
*/
|
*/
|
||||||
final class Order extends AbstractDefaultController implements OrderInterface
|
final class Order extends AbstractDefaultController implements OrderInterface
|
||||||
{
|
{
|
||||||
public function addProduct(): void
|
|
||||||
{}
|
|
||||||
|
|
||||||
public function store(): void
|
/**
|
||||||
|
*
|
||||||
|
* @var OrderRepositoryInterface
|
||||||
|
*/
|
||||||
|
protected $orderRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var ProductRepositoryInterface
|
||||||
|
*/
|
||||||
|
protected $productRepository;
|
||||||
|
|
||||||
|
public function __construct(CoreInterface $core)
|
||||||
|
{
|
||||||
|
parent::__construct($core);
|
||||||
|
$this->productRepository = new ProductRepository($this->core);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addProduct(): void
|
||||||
|
{
|
||||||
|
$this->core->getBasket()->addProduct($this->productRepository->getById($this->post['add']));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function store(): void
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public function basket(): void
|
public function basket(): void
|
||||||
{
|
{
|
||||||
$this->render('order/basket.html.twig',['basket'=>$this->core->getBasket()]);
|
if ($this->post) {
|
||||||
|
$this->postRoutine();
|
||||||
|
}
|
||||||
|
$this->render('order/basket.html.twig', [
|
||||||
|
'basket' => $this->core->getBasket()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function postRoutine(): void
|
||||||
|
{
|
||||||
|
if ($this->post['add']) {
|
||||||
|
$this->addProduct();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function selectPaymentMethod(): void
|
public function selectPaymentMethod(): void
|
||||||
|
@ -7,13 +7,6 @@ namespace controller\order;
|
|||||||
*/
|
*/
|
||||||
interface OrderInterface
|
interface OrderInterface
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Saves the order
|
|
||||||
*/
|
|
||||||
public function store():void;
|
|
||||||
|
|
||||||
public function addProduct():void;
|
|
||||||
|
|
||||||
public function basket():void;
|
public function basket():void;
|
||||||
|
|
||||||
public function selectPaymentMethod():void;
|
public function selectPaymentMethod():void;
|
||||||
|
@ -37,6 +37,7 @@ final class Product extends AbstractDefaultController implements ProductInterfac
|
|||||||
}
|
}
|
||||||
$this->render('product/list.html.twig', [
|
$this->render('product/list.html.twig', [
|
||||||
'products' => $products,
|
'products' => $products,
|
||||||
|
'add_to_basket'=> new Link(['controller'=>'order','action'=>'basket']),
|
||||||
'colors' => $this->getColors(),
|
'colors' => $this->getColors(),
|
||||||
'menu_items'=>[$this->getColors()]
|
'menu_items'=>[$this->getColors()]
|
||||||
]);
|
]);
|
||||||
|
@ -21,8 +21,6 @@ final class Product extends AbstractRepository implements ProductInterface
|
|||||||
const TABLE = 'product';
|
const TABLE = 'product';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Out of time reasons the values are not escaped!
|
|
||||||
*
|
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
* @see \repository\product\ProductInterface::addProducts()
|
* @see \repository\product\ProductInterface::addProducts()
|
||||||
*/
|
*/
|
||||||
@ -59,7 +57,7 @@ final class Product extends AbstractRepository implements ProductInterface
|
|||||||
{
|
{
|
||||||
$products = new ArrayCollection();
|
$products = new ArrayCollection();
|
||||||
foreach ($fetch as $product) {
|
foreach ($fetch as $product) {
|
||||||
$products->add($this->createProduct($product['name'], $product['color'], $product['price'], $product['tax'], $product['image']));
|
$products->add($this->createProduct($product['name'], $product['color'], $product['price'], $product['tax'], $product['image'],$product['id']));
|
||||||
}
|
}
|
||||||
return $products;
|
return $products;
|
||||||
}
|
}
|
||||||
@ -71,7 +69,7 @@ final class Product extends AbstractRepository implements ProductInterface
|
|||||||
return $this->transformFetchToArrayCollection($statement->fetchAll());
|
return $this->transformFetchToArrayCollection($statement->fetchAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
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,?int $id=null): ProductEntity
|
||||||
{
|
{
|
||||||
$product = new ProductEntity();
|
$product = new ProductEntity();
|
||||||
$product->setName($name);
|
$product->setName($name);
|
||||||
@ -85,6 +83,9 @@ final class Product extends AbstractRepository implements ProductInterface
|
|||||||
$image = new UrlImage();
|
$image = new UrlImage();
|
||||||
$image->setImage($imagePath);
|
$image->setImage($imagePath);
|
||||||
$product->setImage($image);
|
$product->setImage($image);
|
||||||
|
if($id){
|
||||||
|
$product->setId($id);
|
||||||
|
}
|
||||||
return $product;
|
return $product;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,4 +95,13 @@ final class Product extends AbstractRepository implements ProductInterface
|
|||||||
$statement->execute([$color]);
|
$statement->execute([$color]);
|
||||||
return $this->transformFetchToArrayCollection($statement->fetchAll());
|
return $this->transformFetchToArrayCollection($statement->fetchAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getById(int $id): ProductEntityInterface
|
||||||
|
{
|
||||||
|
$statement = $this->database->prepare('SELECT * FROM ' . self::TABLE . ' WHERE id = ?;');
|
||||||
|
$statement->execute([$id]);
|
||||||
|
$product = $statement->fetch();
|
||||||
|
return $this->createProduct($product['name'], $product['color'], $product['price'], $product['tax'], $product['image'],$product['id']);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
namespace repository\product;
|
namespace repository\product;
|
||||||
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use entity\product\ProductInterface as EntityProductInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -17,5 +18,7 @@ interface ProductInterface
|
|||||||
public function getColors():array;
|
public function getColors():array;
|
||||||
|
|
||||||
public function getAllByColor(string $color):ArrayCollection;
|
public function getAllByColor(string $color):ArrayCollection;
|
||||||
|
|
||||||
|
public function getById(int $id):EntityProductInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,11 +14,11 @@ basket
|
|||||||
</tr>
|
</tr>
|
||||||
{% for product in basket.products %}
|
{% for product in basket.products %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>product.id</td>
|
<td>{{product.id}}</td>
|
||||||
<td>product.name</td>
|
<td>{{product.name}}</td>
|
||||||
<td>product.price.netto.float</td>
|
<td>{{product.price.netto.float}}</td>
|
||||||
<td>product.price.tax</td>
|
<td>{{product.price.tax}}</td>
|
||||||
<td>product.price.gross.float</td>
|
<td>{{product.price.gross.float}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
@ -1,22 +1,31 @@
|
|||||||
{% extends 'frames/default.html.twig' %}
|
{% extends 'frames/default.html.twig' %}
|
||||||
{% block title %}product overview{% endblock %}
|
{% block title %}
|
||||||
|
product overview
|
||||||
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="card-columns">
|
<div class="card-columns">
|
||||||
{% for product in products %}
|
{% for product in products %}
|
||||||
<div class="card" style="width: 18rem;">
|
<div class="card" style="width: 18rem;">
|
||||||
<img class="card-img-top" src="{{ product.getImage.getThumbnail }}" alt="Card image cap">
|
<img class="card-img-top" src="{{ product.getImage.getThumbnail }}"
|
||||||
|
alt="Card image cap">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">
|
<h5 class="card-title">
|
||||||
{{ product.getName }} <i>({{ product.getColor }})</i>
|
{{ product.getName }}
|
||||||
|
<i>({{ product.getColor }})
|
||||||
|
</i>
|
||||||
</h5>
|
</h5>
|
||||||
<span class="card-text">
|
<span class="card-text"> <b>price:</b>
|
||||||
<b>price:</b>
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>{{ product.getPrice.getNetto.getFloat }} {{ product.getPrice.getNetto.getSymbol }} <i>(net)</i></li>
|
<li>{{ product.getPrice.getNetto.getFloat }} {{ product.getPrice.getNetto.getSymbol }}
|
||||||
<li>{{ product.getPrice.getGross.getFloat }} {{ product.getPrice.getGross.getSymbol }} <i>(gross)</i>, Tax: {{ product.getPrice.getTax }} %</li>
|
<i>(net)</i></li>
|
||||||
|
<li>{{ product.getPrice.getGross.getFloat }} {{ product.getPrice.getGross.getSymbol }}
|
||||||
|
<i>(gross)</i>, Tax: {{ product.getPrice.getTax }} %</li>
|
||||||
</ul>
|
</ul>
|
||||||
</span>
|
</span>
|
||||||
<a href="#" class="btn btn-primary">Add to basket</a>
|
<form action="{{ add_to_basket.url }}" method="post">
|
||||||
|
<input type="hidden" name="add" value="{{ product.id }}" />
|
||||||
|
<input type="submit" class="btn btn-primary" value="Add to basket" />
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Loading…
Reference in New Issue
Block a user