vendor/bitbag/wishlist-plugin/src/Controller/OrderItemController.php line 26

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file was created by developers working at BitBag
  4.  * Do you need more information about us and what we do? Visit our https://bitbag.io website!
  5.  * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
  6. */
  7. declare(strict_types=1);
  8. namespace BitBag\SyliusWishlistPlugin\Controller;
  9. use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface;
  10. use Sylius\Bundle\OrderBundle\Controller\AddToCartCommandInterface;
  11. use Sylius\Bundle\OrderBundle\Controller\OrderItemController as BaseController;
  12. use Sylius\Component\Core\Model\OrderItemInterface;
  13. use Sylius\Component\Order\CartActions;
  14. use Symfony\Component\Form\SubmitButton;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\HttpFoundation\Session\Session;
  18. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  19. final class OrderItemController extends BaseController
  20. {
  21.     public function addAction(Request $request): Response
  22.     {
  23.         $cart $this->getCurrentCart();
  24.         $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  25.         $this->isGrantedOr403($configurationCartActions::ADD);
  26.         /** @var OrderItemInterface $orderItem */
  27.         $orderItem $this->newResourceFactory->create($configuration$this->factory);
  28.         $this->getQuantityModifier()->modify($orderItem1);
  29.         /** @var string $formType */
  30.         $formType $configuration->getFormType();
  31.         $form $this->getFormFactory()->create(
  32.             $formType,
  33.             $this->createAddToCartCommand($cart$orderItem),
  34.             $configuration->getFormOptions()
  35.         );
  36.         $form->handleRequest($request);
  37.         /** @var SubmitButton $addToWishlist */
  38.         $addToWishlist $form->get('addToWishlist');
  39.         if ($addToWishlist->isClicked()) {
  40.             /** @var AddToCartCommandInterface $addToCartCommand */
  41.             $addToCartCommand $form->getData();
  42.             /** @var OrderItemInterface $item */
  43.             $item $addToCartCommand->getCartItem();
  44.             $variant $item->getVariant();
  45.             /** @var WishlistInterface $wishlist */
  46.             $wishlist $form->get('wishlists')->getData();
  47.             if (null === $variant) {
  48.                 throw new NotFoundHttpException('Could not find variant');
  49.             }
  50.             if (null === $wishlist || null === $variant) {
  51.                 /** @var Session $session */
  52.                 $session $request->getSession();
  53.                 $translator $this->get('translator');
  54.                 if (null !== $translator) {
  55.                     $session->getFlashBag()->add('error'$translator->trans('bitbag_sylius_wishlist_plugin.ui.go_to_wishlist_failure'));
  56.                 }
  57.                 return new Response($this->generateUrl('sylius_shop_homepage'));
  58.             }
  59.             return new Response($this->generateUrl('bitbag_sylius_wishlist_plugin_shop_wishlist_add_product_variant', [
  60.                 'wishlistId' => $wishlist->getId(),
  61.                 'variantId' => $variant->getId(),
  62.             ]));
  63.         }
  64.         return parent::addAction($request);
  65.     }
  66. }