...
 
Commits (3)
......@@ -1559,16 +1559,16 @@
},
{
"name": "sensio/framework-extra-bundle",
"version": "v5.5.1",
"version": "v5.5.3",
"source": {
"type": "git",
"url": "https://github.com/sensiolabs/SensioFrameworkExtraBundle.git",
"reference": "dfc2c4df9f7d465a65c770e9feb578fe071636f7"
"reference": "98f0807137b13d0acfdf3c255a731516e97015de"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/dfc2c4df9f7d465a65c770e9feb578fe071636f7",
"reference": "dfc2c4df9f7d465a65c770e9feb578fe071636f7",
"url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/98f0807137b13d0acfdf3c255a731516e97015de",
"reference": "98f0807137b13d0acfdf3c255a731516e97015de",
"shasum": ""
},
"require": {
......@@ -1633,7 +1633,7 @@
"annotations",
"controllers"
],
"time": "2019-10-16T18:54:45+00:00"
"time": "2019-12-27T08:57:19+00:00"
},
{
"name": "symfony/apache-pack",
......
......@@ -8,14 +8,12 @@ use App\Form\OrderType;
use App\Entity\OrderLine;
use App\Entity\OrderStatus;
use App\Entity\ShoppingCart;
use App\Repository\OrderRepository;
use App\Controller\Front\UserController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
/**
* @Route("/order", name="order_")
......@@ -191,6 +189,7 @@ class OrderController extends AbstractController
/**
* @Route("/{id}", name="order_delete", methods={"DELETE"}, requirements={"id":"\d+"})
* @IsGranted("ROLE_ADMIN")
*/
public function delete(Request $request, Order $order): Response
{
......
......@@ -6,12 +6,14 @@ use App\Entity\Order;
use App\Entity\Sandwich;
use App\Entity\OrderLine;
use App\Entity\ShoppingCart;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
* @Route("/order/line", name="order_line_")
*/
......@@ -129,9 +131,11 @@ class OrderLineController extends AbstractController
/**
* @Route("/{id}", name="delete", methods={"DELETE"})
* @IsGranted("ROLE_ADMIN")
*/
public function delete(Request $request, OrderLine $orderLine): Response
{
$this->denyAccessUnlessGranted('ROLE_ADMIN');
if ($this->isCsrfTokenValid('delete' . $orderLine->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($orderLine);
......
......@@ -23,10 +23,12 @@ class SandwichController extends AbstractController
/**
* @Route("/", name="index", methods={"GET"})
*/
public function index(SandwichRepository $sandwichRepository): Response
public function index(SandwichRepository $sandwichRepository, $aLaCarte = true): Response
{
$aLaCarte ? $sandwiches = $sandwichRepository->findBy(['aLaCarte' => true]) : $sandwiches = $sandwichRepository->findAll();
return $this->render('front/sandwich/index.html.twig', [
'sandwiches' => $sandwichRepository->findBy(['aLaCarte' => true]),
'sandwiches' => $sandwiches,
]);
}
......
......@@ -5,7 +5,34 @@
{% endblock %}
{% block body %}
{{ dump(sandwich) }}
<h1>{{sandwich.name}}</h1>
<p>{{sandwich.description}}</p>
{% set price = 0 %}
<ul class="list-group">
<li class="list-group-item">
Bread:
{{ sandwich.typeBread.name }}
{% set price = price + sandwich.typeBread.price %}
{# {{ dump(sandwich.typeBread.price ) }} #}
</li>
<li class="list-group-item">
Size:
{{ sandwich.typeSize }}
{# {{ dump(sandwich.typeSize ) }} #}
</li>
<li class="list-group-item">
Spread:
{% for spread in sandwich.typeSpreadId %}
{{ spread.name|lower }}
{% set price = price + spread.price %}
{# {{ dump(spread.price ) }} #}
{% endfor %}
</li>
</ul>
<p class="mt-4">
Price:
{% set price = price * (sandwich.typeSize.multiplier / 100) %}
{{(price / 100) | format_currency('EUR', {rounding_mode: 'floor'})}}</p>
Work in progress...
{% endblock %}
......@@ -5,9 +5,9 @@
{% block body %}
{# {{ dump(cart) }}{{ dump(cart.orderLine) }}{% for orderLine in cart.orderLine %}{{ dump(orderLine) }}{% endfor %} #}
{# {{ dump(cart) }}{{ dump(cart.orderLine) }} {% for orderLine in cart.orderLine %} {{ dump(orderLine) }} {% endfor %} #}
{% if cart is not empty %}
{% if cart.orderLine is not empty %}
{% set title = 'Shopping cart' %}
{% if not isComponent %}
......@@ -26,31 +26,40 @@
<a href="{{path('shopping_cart_index')}}" class="btn btn-primary">Order</a>
{% else %}
{# showAllDetails #}
{% if cart.orderLine is empty %}
<div class="alert alert-info" role="alert">
Your shopping cart is empty. Go to
<a href="{{ path('sandwich_index') }}">sandwich index</a>
to buy some delicious sandwiches
</div>
<div class="row row-cols-1 row-cols-md mt-2">
<div class="col mb-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">Total price
{{ (total / 100) | format_currency('EUR', {rounding_mode: 'floor'})}}</h5>
{% else %}
<div class="row row-cols-1 row-cols-md mt-2">
<div class="col mb-4">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">Total price
{{ (total / 100) | format_currency('EUR', {rounding_mode: 'floor'})}}</h5>
</div>
</div>
</div>
</div>
</div>
{% endif %}
{# orderThisOrder #}
<form name="form" action="{{ path('order_new_from_shopping_cart') }}" method="post">
<input id="shoppingCartId" class="btn btn-primary" type="submit" name="submit[{{cart.id}}]" value="Order Cart">
<input id="shoppingCartId" class="btn btn-primary" type="submit" {% if cart.orderLine is empty %} disabled {% endif %} name="submit[{{cart.id}}]" value="Order Cart">
</form>
{% endif %}
{% else %}
{% if not isComponent %}
<div class="alert alert-info" role="alert">
Your cart is empty
Your shopping cart is empty.
<br>
Go to
<a href="{{ path('sandwich_index') }}">sandwich index</a>
to buy some delicious sandwiches
</div>
{% endif %}
{# notification on sanwich index #}
{% endif %}
{% endblock %}
......@@ -31,6 +31,13 @@
<a class="dropdown-item" href="{{ path('user') }}">My account</a>
<a class="dropdown-item" href="{{path('order_index')}}">Orders</a>
<a class="dropdown-item" href="{{ path('app_logout') }}">Logout</a>
{% if is_granted("ROLE_ADMIN") %}
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ path('app_logout') }}">
is admin</a>
{% else %}
{% endif %}
{% else %}
{# anonymous #}
<a class="dropdown-item" href="{{ path('app_login') }}">Login</a>
......