-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Controller\Admin; | ||
|
||
use App\Entity\Product; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\SlugField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; | ||
|
||
class ProductCrudController extends AbstractCrudController | ||
{ | ||
public static function getEntityFqcn(): string | ||
{ | ||
return Product::class; | ||
} | ||
|
||
|
||
public function configureFields(string $pageName): iterable | ||
{ | ||
return[ | ||
TextField::new('name'), | ||
SlugField::new('slug')->setTargetFieldName('name'), | ||
ImageField::new('illustration')->setBasePath('uploads/')->setUploadDir('public/uploads')->setUploadedFileNamePattern('[randomhash].[extension]'), | ||
TextField::new('subtitle'), | ||
TextareaField::new('description'), | ||
MoneyField::new('price')->setCurrency('EUR'), | ||
AssociationField::new('category') | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Entity\Product; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
|
||
class ProductController extends AbstractController | ||
{ | ||
private $entityManager; | ||
|
||
public function __construct(EntityManagerInterface $entityManager) | ||
{ | ||
$this->entityManager=$entityManager; | ||
} | ||
|
||
/** | ||
* @Route("/nos-produits", name="products") | ||
*/ | ||
public function index(): Response | ||
{ | ||
$products = $this->entityManager->getRepository(Product::class)->findAll(); | ||
return $this->render('product/index.html.twig', [ | ||
'products' => $products | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/produit/{slug}", name="product") | ||
*/ | ||
public function show($slug): Response | ||
{ | ||
$product = $this->entityManager->getRepository(Product::class)->findOneBySlug($slug); | ||
if(!$product) | ||
{ | ||
return $this->redirectToRoute('products'); | ||
} | ||
else | ||
{ | ||
return $this->render('product/show.html.twig', [ | ||
'product' => $product | ||
]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block title %}Nos produits | Ma boutique Symfony{% endblock %} | ||
|
||
{% block content %} | ||
<h1>Nos produits</h1> | ||
<div class="row product-container"> | ||
{% for product in products %} | ||
<div class="col-md-4"> | ||
<div class="product-item text-center"> | ||
<a href="{{ path('product', {'slug' : product.slug }) }}"><img src="/uploads/{{ product.illustration }}" alt="produit" class="img-fluid"></a> | ||
<h5>{{ product.name }}</h5> | ||
<span class="product-subtitle">{{ product.subtitle }}</span> | ||
<span class="product-price">{{ (product.price / 100)|number_format(2, ',') }}€</span> | ||
</div> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
|
||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block title %}{{ product.name }} | Ma boutique Symfony{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<div class="row"> | ||
<div class="col-md-5"> | ||
<img src="/uploads/{{ product.illustration }}" alt="{{ product.name }}" class="img-fluid"> | ||
</div> | ||
<div class="col-md-7 my-auto"> | ||
<h3>{{ product.name }}</h3> | ||
<p>{{ product.subtitle }}</p> | ||
<span class="product-page-price">{{ (product.price / 100)|number_format(2, ',') }}€</span> | ||
<hr> | ||
<p> | ||
{{ product.description }} | ||
</p> | ||
<a href="" class="btn btn-primary">Ajouter au panier</a> | ||
</div> | ||
|
||
|
||
|
||
{% endblock %} |