54 $this->_customerSession = $customerSession;
58 parent::__construct($context);
74 if (!$this->formKeyValidator->validate($this->getRequest())) {
75 return $resultRedirect->setPath(
'*/');
78 $wishlist = $this->wishlistProvider->getWishlist();
85 $requestParams = $this->getRequest()->getParams();
87 if (
$session->getBeforeWishlistRequest()) {
88 $requestParams =
$session->getBeforeWishlistRequest();
89 $session->unsBeforeWishlistRequest();
92 $productId = isset($requestParams[
'product']) ? (int)$requestParams[
'product'] :
null;
94 $resultRedirect->setPath(
'*/');
95 return $resultRedirect;
100 }
catch (NoSuchEntityException $e) {
105 $this->messageManager->addErrorMessage(
__(
'We can\'t specify a product.'));
106 $resultRedirect->setPath(
'*/');
107 return $resultRedirect;
111 $buyRequest = new \Magento\Framework\DataObject($requestParams);
115 throw new \Magento\Framework\Exception\LocalizedException(
__(
$result));
120 $this->_eventManager->dispatch(
121 'wishlist_add_product',
125 $referer =
$session->getBeforeWishlistUrl();
127 $session->setBeforeWishlistUrl(
null);
129 $referer = $this->_redirect->getRefererUrl();
132 $this->_objectManager->get(\
Magento\Wishlist\Helper\Data::class)->calculate();
134 $this->messageManager->addComplexSuccessMessage(
135 'addProductSuccessMessage',
137 'product_name' =>
$product->getName(),
138 'referer' => $referer
141 }
catch (\
Magento\Framework\Exception\LocalizedException $e) {
142 $this->messageManager->addErrorMessage(
143 __(
'We can\'t add the item to Wish List right now: %1.', $e->getMessage())
145 }
catch (\Exception $e) {
146 $this->messageManager->addExceptionMessage(
148 __(
'We can\'t add the item to Wish List right now.')
152 $resultRedirect->setPath(
'*', [
'wishlist_id' =>
$wishlist->getId()]);
153 return $resultRedirect;
__construct(Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider, ProductRepositoryInterface $productRepository, Validator $formKeyValidator)
foreach($product->getExtensionAttributes() ->getBundleProductOptions() as $option) $buyRequest