|
12 | 12 | use Magento\Framework\Exception\NotFoundException;
|
13 | 13 | use Magento\Framework\Exception\NoSuchEntityException;
|
14 | 14 | use Magento\Framework\Controller\ResultFactory;
|
| 15 | +use Magento\Framework\App\ObjectManager; |
| 16 | +use Magento\Framework\UrlInterface; |
| 17 | +use Magento\Framework\App\Response\RedirectInterface; |
15 | 18 |
|
16 | 19 | /**
|
17 | 20 | * Wish list Add controller
|
@@ -40,31 +43,39 @@ class Add extends \Magento\Wishlist\Controller\AbstractIndex implements HttpPost
|
40 | 43 | */
|
41 | 44 | protected $formKeyValidator;
|
42 | 45 |
|
| 46 | + private $redirect; |
| 47 | + |
| 48 | + private $urlBuilder; |
| 49 | + |
43 | 50 | /**
|
44 | 51 | * @param Action\Context $context
|
45 | 52 | * @param \Magento\Customer\Model\Session $customerSession
|
46 | 53 | * @param \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider
|
47 | 54 | * @param ProductRepositoryInterface $productRepository
|
48 | 55 | * @param Validator $formKeyValidator
|
| 56 | + * @param RedirectInterface $redirect |
| 57 | + * @param UrlInterface $urlBuilder |
49 | 58 | */
|
50 | 59 | public function __construct(
|
51 | 60 | Action\Context $context,
|
52 | 61 | \Magento\Customer\Model\Session $customerSession,
|
53 | 62 | \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider,
|
54 | 63 | ProductRepositoryInterface $productRepository,
|
55 |
| - Validator $formKeyValidator |
| 64 | + Validator $formKeyValidator, |
| 65 | + RedirectInterface $redirect = null, |
| 66 | + UrlInterface $urlBuilder = null |
56 | 67 | ) {
|
57 | 68 | $this->_customerSession = $customerSession;
|
58 | 69 | $this->wishlistProvider = $wishlistProvider;
|
59 | 70 | $this->productRepository = $productRepository;
|
60 | 71 | $this->formKeyValidator = $formKeyValidator;
|
| 72 | + $this->redirect = $redirect ?: ObjectManager::getInstance()->get(RedirectInterface::class); |
| 73 | + $this->urlBuilder = $urlBuilder ?: ObjectManager::getInstance()->get(UrlInterface::class); |
61 | 74 | parent::__construct($context);
|
62 | 75 | }
|
63 | 76 |
|
64 | 77 | /**
|
65 |
| - * Adding new item |
66 |
| - * |
67 |
| - * @return \Magento\Framework\Controller\Result\Redirect |
| 78 | + * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface |
68 | 79 | * @throws NotFoundException
|
69 | 80 | * @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
70 | 81 | * @SuppressWarnings(PHPMD.NPathComplexity)
|
@@ -153,7 +164,16 @@ public function execute()
|
153 | 164 | );
|
154 | 165 | }
|
155 | 166 |
|
| 167 | + if ($this->getRequest()->isAjax()) { |
| 168 | + $url = $this->urlBuilder->getUrl('*', $this->redirect->updatePathParams(['wishlist_id' => $wishlist->getId()])); |
| 169 | + /** @var Json $resultJson */ |
| 170 | + $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); |
| 171 | + $resultJson->setData(['backUrl' => $url]); |
| 172 | + |
| 173 | + return $resultJson; |
| 174 | + } |
156 | 175 | $resultRedirect->setPath('*', ['wishlist_id' => $wishlist->getId()]);
|
| 176 | + |
157 | 177 | return $resultRedirect;
|
158 | 178 | }
|
159 | 179 | }
|
0 commit comments