Skip to content

Commit

Permalink
Merge pull request #138 from BitBagCommerce/OPSRC-587/Add_validation_…
Browse files Browse the repository at this point in the history
…for_wishlist

add missing validate for wishlist
  • Loading branch information
PiotrSzymanski2000 authored Jun 28, 2022
2 parents 413ca9c + 4080f35 commit ac69ec8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/Controller/Action/ShowChosenWishlistAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
use Sylius\Component\Order\Context\CartContextInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;

final class ShowChosenWishlistAction
Expand All @@ -33,33 +35,40 @@ final class ShowChosenWishlistAction

private WishlistCommandProcessorInterface $wishlistCommandProcessor;

private UrlGeneratorInterface $urlGenerator;

public function __construct(
WishlistRepositoryInterface $wishlistRepository,
CartContextInterface $cartContext,
FormFactoryInterface $formFactory,
Environment $twigEnvironment,
WishlistCommandProcessorInterface $wishlistCommandProcessor
WishlistCommandProcessorInterface $wishlistCommandProcessor,
UrlGeneratorInterface $urlGenerator
) {
$this->wishlistRepository = $wishlistRepository;
$this->cartContext = $cartContext;
$this->formFactory = $formFactory;
$this->twigEnvironment = $twigEnvironment;
$this->wishlistCommandProcessor = $wishlistCommandProcessor;
$this->urlGenerator = $urlGenerator;
}

public function __invoke(int $wishlistId, Request $request): Response
public function __invoke(string $wishlistId, Request $request): Response
{
/** @var WishlistInterface $wishlist */
$wishlist = $this->wishlistRepository->find($wishlistId);

$form = $this->createForm($wishlist);

return new Response(
$this->twigEnvironment->render('@BitBagSyliusWishlistPlugin/WishlistDetails/index.html.twig', [
'wishlist' => $wishlist,
'form' => $form->createView(),
])
);
$wishlist = $this->wishlistRepository->find((int)$wishlistId);

if ($wishlist instanceof WishlistInterface) {
$form = $this->createForm($wishlist);
return new Response(
$this->twigEnvironment->render('@BitBagSyliusWishlistPlugin/WishlistDetails/index.html.twig', [
'wishlist' => $wishlist,
'form' => $form->createView(),
])
);
}

return new RedirectResponse($this->urlGenerator->generate("bitbag_sylius_wishlist_plugin_shop_wishlist_list_wishlists"));
}

private function createForm(WishlistInterface $wishlist): FormInterface
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ services:
- "@form.factory"
- "@twig"
- "@bitbag_sylius_wishlist_plugin.processor.wishlist_command_processor"
- "@router.default"
tags:
- { name: controller.service_arguments }

Expand Down

0 comments on commit ac69ec8

Please sign in to comment.