From b17ade146165c9177e8f919486945053ded5ae19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Tue, 19 Nov 2024 09:57:15 +0100 Subject: [PATCH] Comment out functionality that will be added in a later version --- src/Controller/AddToWishlistAction.php | 23 ++++---------- src/Controller/RemoveFromWishlistAction.php | 33 ++++++-------------- src/Resources/config/services/controller.xml | 2 -- 3 files changed, 16 insertions(+), 42 deletions(-) diff --git a/src/Controller/AddToWishlistAction.php b/src/Controller/AddToWishlistAction.php index b4ef576..82c5070 100644 --- a/src/Controller/AddToWishlistAction.php +++ b/src/Controller/AddToWishlistAction.php @@ -6,13 +6,10 @@ use Doctrine\Persistence\ManagerRegistry; use Setono\Doctrine\ORMTrait; -use Setono\SyliusWishlistPlugin\Controller\Command\SelectWishlistsCommand; use Setono\SyliusWishlistPlugin\Factory\WishlistItemFactoryInterface; -use Setono\SyliusWishlistPlugin\Form\Type\SelectWishlistsType; use Setono\SyliusWishlistPlugin\Provider\WishlistProviderInterface; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Model\ProductVariantInterface; -use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -28,7 +25,6 @@ final class AddToWishlistAction public function __construct( private readonly WishlistProviderInterface $wishlistProvider, private readonly WishlistItemFactoryInterface $wishlistItemFactory, - private readonly FormFactoryInterface $formFactory, private readonly Environment $twig, ManagerRegistry $managerRegistry, /** @var class-string $className */ @@ -57,24 +53,17 @@ public function __invoke(int $id): Response $manager->flush(); - $form = $this->formFactory->create( - SelectWishlistsType::class, - new SelectWishlistsCommand($this->wishlistProvider->getWishlists()), - [ - 'selected' => $preSelectedWishlists, - ], - ); - return new JsonResponse([ 'toggleButton' => $this->twig->render('@SetonoSyliusWishlistPlugin/shop/wishlist/_toggle_button.html.twig', [ 'product' => $entity instanceof ProductInterface ? $entity : $entity->getProduct(), 'productVariant' => $entity instanceof ProductVariantInterface ? $entity : null, ]), - 'selectWishlistsForm' => $this->twig->render('@SetonoSyliusWishlistPlugin/shop/wishlist/_select_wishlists.html.twig', [ - 'product' => $entity instanceof ProductInterface ? $entity : $entity->getProduct(), - 'productVariant' => $entity instanceof ProductVariantInterface ? $entity : null, - 'form' => $form->createView(), - ]), +// Will be added in a later version +// 'selectWishlistsForm' => $this->twig->render('@SetonoSyliusWishlistPlugin/shop/wishlist/_select_wishlists.html.twig', [ +// 'product' => $entity instanceof ProductInterface ? $entity : $entity->getProduct(), +// 'productVariant' => $entity instanceof ProductVariantInterface ? $entity : null, +// 'form' => $form->createView(), +// ]), ]); } } diff --git a/src/Controller/RemoveFromWishlistAction.php b/src/Controller/RemoveFromWishlistAction.php index b75eeb0..5ea6a66 100644 --- a/src/Controller/RemoveFromWishlistAction.php +++ b/src/Controller/RemoveFromWishlistAction.php @@ -10,11 +10,8 @@ use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Core\Model\ProductVariantInterface; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Twig\Environment; /** @@ -28,14 +25,13 @@ public function __construct( private readonly WishlistProviderInterface $wishlistProvider, private readonly Environment $twig, ManagerRegistry $managerRegistry, - private readonly UrlGeneratorInterface $urlGenerator, /** @var class-string $className */ private readonly string $className, ) { $this->managerRegistry = $managerRegistry; } - public function __invoke(Request $request, int $id): Response + public function __invoke(Request $request, int $id): JsonResponse { $entity = $this->getManager($this->className)->find($this->className, $id); @@ -49,23 +45,14 @@ public function __invoke(Request $request, int $id): Response $this->getManager($entity)->flush(); - if ($request->isXmlHttpRequest()) { - return new JsonResponse([ - 'toggleButton' => $this->twig->render( - '@SetonoSyliusWishlistPlugin/shop/wishlist/_toggle_button.html.twig', - [ - 'product' => $entity instanceof ProductInterface ? $entity : $entity->getProduct(), - 'productVariant' => $entity instanceof ProductVariantInterface ? $entity : null, - ], - ), - ]); - } - - return new RedirectResponse($this->getRedirectUrl($request)); - } - - private function getRedirectUrl(Request $request): string - { - return $request->headers->get('referer') ?? $this->urlGenerator->generate('setono_sylius_wishlist_shop_wishlist_index'); + return new JsonResponse([ + 'toggleButton' => $this->twig->render( + '@SetonoSyliusWishlistPlugin/shop/wishlist/_toggle_button.html.twig', + [ + 'product' => $entity instanceof ProductInterface ? $entity : $entity->getProduct(), + 'productVariant' => $entity instanceof ProductVariantInterface ? $entity : null, + ], + ), + ]); } } diff --git a/src/Resources/config/services/controller.xml b/src/Resources/config/services/controller.xml index 9084325..373711c 100644 --- a/src/Resources/config/services/controller.xml +++ b/src/Resources/config/services/controller.xml @@ -44,7 +44,6 @@ class="Setono\SyliusWishlistPlugin\Controller\AddToWishlistAction" public="true" abstract="true"> - @@ -65,7 +64,6 @@ -