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

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\HttpKernel\Exception\NotFoundHttpException;
  18. final class OrderItemController extends BaseController
  19. {
  20.     public function addAction(Request $request): Response
  21.     {
  22.         $cart $this->getCurrentCart();
  23.         $configuration $this->requestConfigurationFactory->create($this->metadata$request);
  24.         $this->isGrantedOr403($configurationCartActions::ADD);
  25.         /** @var OrderItemInterface $orderItem */
  26.         $orderItem $this->newResourceFactory->create($configuration$this->factory);
  27.         $this->getQuantityModifier()->modify($orderItem1);
  28.         /** @var string $formType */
  29.         $formType $configuration->getFormType();
  30.         $form $this->getFormFactory()->create(
  31.             $formType,
  32.             $this->createAddToCartCommand($cart$orderItem),
  33.             $configuration->getFormOptions()
  34.         );
  35.         $form->handleRequest($request);
  36.         /** @var SubmitButton $addToWishlist */
  37.         $addToWishlist $form->get('addToWishlist');
  38.         if ($addToWishlist->isClicked()) {
  39.             /** @var AddToCartCommandInterface $addToCartCommand */
  40.             $addToCartCommand $form->getData();
  41.             /** @var OrderItemInterface $item */
  42.             $item $addToCartCommand->getCartItem();
  43.             $variant $item->getVariant();
  44.             /** @var WishlistInterface $wishlist */
  45.             $wishlist $form->get('wishlists')->getData();
  46.             if (null === $variant) {
  47.                 throw new NotFoundHttpException('Could not find variant');
  48.             }
  49.             return new Response($this->generateUrl('bitbag_sylius_wishlist_plugin_shop_wishlist_add_product_variant', [
  50.                 'wishlistId' => $wishlist->getId(),
  51.                 'variantId' => $variant->getId(),
  52.             ]));
  53.         }
  54.         return parent::addAction($request);
  55.     }
  56. }