Skip to content

Commit

Permalink
Comment out functionality that will be added in a later version
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Nov 19, 2024
1 parent 136a829 commit b17ade1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 42 deletions.
23 changes: 6 additions & 17 deletions src/Controller/AddToWishlistAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ProductInterface|ProductVariantInterface> $className */
Expand Down Expand Up @@ -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(),
// ]),
]);
}
}
33 changes: 10 additions & 23 deletions src/Controller/RemoveFromWishlistAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -28,14 +25,13 @@ public function __construct(
private readonly WishlistProviderInterface $wishlistProvider,
private readonly Environment $twig,
ManagerRegistry $managerRegistry,
private readonly UrlGeneratorInterface $urlGenerator,
/** @var class-string<ProductInterface|ProductVariantInterface> $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);

Expand All @@ -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,
],
),
]);
}
}
2 changes: 0 additions & 2 deletions src/Resources/config/services/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
class="Setono\SyliusWishlistPlugin\Controller\AddToWishlistAction" public="true" abstract="true">
<argument type="service" id="Setono\SyliusWishlistPlugin\Provider\WishlistProviderInterface"/>
<argument type="service" id="Setono\SyliusWishlistPlugin\Factory\WishlistItemFactoryInterface"/>
<argument type="service" id="form.factory"/>
<argument type="service" id="twig"/>
<argument type="service" id="doctrine"/>
</service>
Expand All @@ -65,7 +64,6 @@
<argument type="service" id="Setono\SyliusWishlistPlugin\Provider\WishlistProviderInterface"/>
<argument type="service" id="twig"/>
<argument type="service" id="doctrine"/>
<argument type="service" id="router"/>
</service>

<service id="setono_sylius_wishlist.controller.remove_product_from_wishlist"
Expand Down

0 comments on commit b17ade1

Please sign in to comment.