Ajout du modification catégory avec modiciation categorie produit en live
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Controller\Dashboard;
|
||||
use App\Entity\Category;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerAddress;
|
||||
use App\Entity\Product;
|
||||
use App\Form\CategoryType;
|
||||
use App\Form\CustomerAddAddressType;
|
||||
use App\Form\CustomerAddType;
|
||||
@@ -76,6 +77,34 @@ class CategoryController extends AbstractController
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
#[Route('/edit/{id}', name: 'app_crm_category_edit', options: ['sitemap' => false], methods: ['GET', 'POST'])]
|
||||
public function edit(?Category $category,Request $request, CategoryRepository $categoryRepository): Response
|
||||
{
|
||||
if(!$category instanceof Category) {
|
||||
return $this->redirectToRoute('app_crm_category');
|
||||
}
|
||||
$this->appLogger->record('VIEW', 'Consultation de la catégorie '.$category->getName());
|
||||
|
||||
$oldName = $category->getName();
|
||||
$form = $this->createForm(CategoryType::class, $category);
|
||||
$form->handleRequest($request);
|
||||
if($form->isSubmitted() && $form->isValid()) {
|
||||
|
||||
|
||||
$products = $this->em->getRepository(Product::class)->findBy(['category'=>$oldName]);
|
||||
foreach ($products as $product) {
|
||||
$product->setCategory($category->getName());
|
||||
$this->em->persist($product);
|
||||
}
|
||||
$this->appLogger->record('VIEW', 'Modification d\'une catégorie');
|
||||
$this->em->persist($category);
|
||||
$this->em->flush();
|
||||
return $this->redirectToRoute('app_crm_category');
|
||||
}
|
||||
return $this->render('dashboard/category/edit.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/delete/{id}', name: 'app_crm_category_delete', options: ['sitemap' => false], methods: ['GET'])]
|
||||
public function delete(
|
||||
|
||||
28
templates/dashboard/category/edit.twig
Normal file
28
templates/dashboard/category/edit.twig
Normal file
@@ -0,0 +1,28 @@
|
||||
{% extends 'dashboard/base.twig' %}
|
||||
{% block title %}Modification Catégorie{% endblock %}
|
||||
{% block title_header %}Modification <span class="text-blue-500">Catégorie</span>{% endblock %}
|
||||
|
||||
|
||||
{% block body %}
|
||||
<div class="backdrop-blur-xl bg-[#1e293b]/40 border border-white/5 rounded-[2.5rem] shadow-2xl overflow-hidden">
|
||||
|
||||
|
||||
<div class="p-10">
|
||||
{{ form_start(form, {'attr': {'class': 'space-y-12'}}) }}
|
||||
{{ form_row(form.name) }}
|
||||
{# ACTIONS : Boutons espacés #}
|
||||
<div class="pt-10 border-t border-white/5 flex items-center justify-end">
|
||||
<div class="flex items-center space-x-16"> {# Espace large entre les deux boutons #}
|
||||
<a data-turbo="false" href="{{ path('app_crm_category') }}" class="mr-2 text-[10px] font-black text-slate-300 hover:text-rose-500 uppercase tracking-widest transition-colors">
|
||||
Annuler l'opération
|
||||
</a>
|
||||
<button type="submit" class="p-2 px-16 py-4 bg-blue-600 hover:bg-blue-500 text-white text-[10px] font-black uppercase tracking-[0.2em] rounded-2xl shadow-lg shadow-blue-600/20 transition-all hover:scale-105 active:scale-95">
|
||||
Valider et enregistrer
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{{ form_end(form) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -41,6 +41,9 @@
|
||||
{# ACTIONS #}
|
||||
<td class="px-6 py-4 text-right">
|
||||
<div class="flex items-center justify-end space-x-2">
|
||||
<a data-turbo="false" href="{{ path('app_crm_category_edit', {id: category.id}) }}" class="p-2 bg-blue-600/10 hover:bg-blue-600 text-blue-500 hover:text-white rounded-xl transition-all border border-blue-500/20 shadow-lg shadow-blue-600/5">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" /></svg>
|
||||
</a>
|
||||
<a data-turbo="false" href="{{ path('app_crm_category_delete', {id: category.id}) }}?_token={{ csrf_token('delete' ~ category.id) }}"
|
||||
data-turbo-method="post"
|
||||
data-turbo-confirm="Confirmer la suppression de la catégorie {{ category.name }} ?"
|
||||
|
||||
Reference in New Issue
Block a user