73 lines
1.8 KiB
PHP
Raw Normal View History

2018-07-14 18:50:47 +02:00
<?php
namespace controller\order;
2018-07-15 12:15:06 +02:00
use controller\AbstractDefaultController;
2018-07-15 13:09:06 +02:00
use core\CoreInterface;
use repository\order\OrderInterface as OrderRepositoryInterface;
use repository\product\ProductInterface as ProductRepositoryInterface;
use repository\product\Product as ProductRepository;
2018-07-15 14:32:56 +02:00
use entity\payment\AbstractPayment;
use repository\order\Order as OrderRepository;
use entity\order\Order as OrderEntity;
2018-07-14 18:50:47 +02:00
/**
*
* @author kevinfrantz
*
*/
2018-07-15 12:15:06 +02:00
final class Order extends AbstractDefaultController implements OrderInterface
2018-07-14 18:50:47 +02:00
{
2018-07-15 13:09:06 +02:00
/**
*
* @var OrderRepositoryInterface
*/
protected $orderRepository;
/**
*
* @var ProductRepositoryInterface
*/
protected $productRepository;
public function __construct(CoreInterface $core)
{
parent::__construct($core);
$this->productRepository = new ProductRepository($this->core);
$this->orderRepository = new OrderRepository($this->core);
2018-07-15 13:09:06 +02:00
}
private function addProduct(): void
{
$this->core->getBasket()->addProduct($this->productRepository->getById($this->post['add']));
}
private function store(): void
2018-07-15 16:17:11 +02:00
{
$this->core->getBasket()->setCustomer($this->core->getUser());
$this->core->setBasket(new OrderEntity());
}
2018-07-14 18:50:47 +02:00
public function basket(): void
2018-07-15 12:15:06 +02:00
{
2018-07-15 13:09:06 +02:00
if ($this->post) {
$this->postRoutine();
}
$this->render('order/basket.html.twig', [
2018-07-15 14:32:56 +02:00
'basket' => $this->core->getBasket(),
'payment_methods'=>AbstractPayment::getPaymentMethods(),
2018-07-15 13:09:06 +02:00
]);
}
private function postRoutine(): void
{
if ($this->post['add']) {
$this->addProduct();
}
if ($this->post['store']){
2018-07-15 16:17:11 +02:00
$this->store();
}
2018-07-15 12:15:06 +02:00
}
2018-07-14 18:50:47 +02:00
}