/** * Add cart item to wishlist and remove from cart * * @return \Zend_Controller_Response_Abstract * @throws NotFoundException */ public function execute() { $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(); } $itemId = (int) $this->getRequest()->getParam('item'); /* @var \Magento\Checkout\Model\Cart $cart */ $cart = $this->_objectManager->get('Magento\\Checkout\\Model\\Cart'); $session = $this->_objectManager->get('Magento\\Checkout\\Model\\Session'); try { $item = $cart->getQuote()->getItemById($itemId); if (!$item) { throw new \Magento\Framework\Model\Exception(__("The requested cart item doesn't exist.")); } $productId = $item->getProductId(); $buyRequest = $item->getBuyRequest(); $wishlist->addNewItem($productId, $buyRequest); $productIds[] = $productId; $cart->getQuote()->removeItem($itemId); $cart->save(); $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); $productName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($item->getProduct()->getName()); $wishlistName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($wishlist->getName()); $this->messageManager->addSuccess(__("%1 has been moved to wish list %2", $productName, $wishlistName)); $wishlist->save(); } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('We can\'t move the item to the wish list.')); } return $this->getResponse()->setRedirect($this->_objectManager->get('Magento\\Checkout\\Helper\\Cart')->getCartUrl()); }
/** * Remove item * * @return void * @throws NotFoundException */ public function execute() { $id = (int) $this->getRequest()->getParam('item'); $item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item')->load($id); if (!$item->getId()) { throw new NotFoundException(); } $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { throw new NotFoundException(); } try { $item->delete(); $wishlist->save(); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError(__('An error occurred while deleting the item from wish list: %1', $e->getMessage())); } catch (\Exception $e) { $this->messageManager->addError(__('An error occurred while deleting the item from wish list.')); } $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); $request = $this->getRequest(); $refererUrl = (string) $request->getServer('HTTP_REFERER'); $url = (string) $request->getParam(\Magento\Framework\App\Response\RedirectInterface::PARAM_NAME_REFERER_URL); if ($url) { $refererUrl = $url; } if ($request->getParam(\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED) && $refererUrl) { $redirectUrl = $refererUrl; } else { $redirectUrl = $this->_redirect->getRedirectUrl($this->_url->getUrl('*/*')); } $this->getResponse()->setRedirect($redirectUrl); }
/** * Add cart item to wishlist and remove from cart * * @return \Magento\Framework\Controller\Result\Redirect * @throws NotFoundException * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function execute() { $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(__('Page not found.')); } try { $itemId = (int) $this->getRequest()->getParam('item'); $item = $this->cart->getQuote()->getItemById($itemId); if (!$item) { throw new LocalizedException(__('The requested cart item doesn\'t exist.')); } $productId = $item->getProductId(); $buyRequest = $item->getBuyRequest(); $wishlist->addNewItem($productId, $buyRequest); $this->cart->getQuote()->removeItem($itemId); $this->cart->save(); $this->wishlistHelper->calculate(); $wishlist->save(); $this->messageManager->addSuccessMessage(__("%1 has been moved to your wish list.", $this->escaper->escapeHtml($item->getProduct()->getName()))); } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addExceptionMessage($e, __('We can\'t move the item to the wish list.')); } /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setUrl($this->cartHelper->getCartUrl()); }
/** * Add cart item to wishlist and remove from cart * * @return \Magento\Framework\Controller\Result\Redirect * @throws NotFoundException * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function execute() { $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(__('Page not found.')); } $itemId = (int) $this->getRequest()->getParam('item'); /* @var \Magento\Checkout\Model\Cart $cart */ $cart = $this->_objectManager->get('Magento\\Checkout\\Model\\Cart'); $this->_objectManager->get('Magento\\Checkout\\Model\\Session'); $item = $cart->getQuote()->getItemById($itemId); if (!$item) { throw new \Magento\Framework\Exception\LocalizedException(__('The requested cart item doesn\'t exist.')); } $productId = $item->getProductId(); $buyRequest = $item->getBuyRequest(); $wishlist->addNewItem($productId, $buyRequest); $productIds[] = $productId; $cart->getQuote()->removeItem($itemId); $cart->save(); $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); $productName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($item->getProduct()->getName()); $wishlistName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($wishlist->getName()); $this->messageManager->addSuccess(__("%1 has been moved to wish list %2", $productName, $wishlistName)); $wishlist->save(); return $this->getDefaultResult(); }
/** * Display customer wishlist * * @return void * @throws NotFoundException */ public function execute() { if (!$this->wishlistProvider->getWishlist()) { throw new NotFoundException(); } $this->_view->loadLayout(); $this->_view->getLayout()->initMessages(); $this->_view->renderLayout(); }
/** * Display customer wishlist * * @return \Magento\Framework\View\Result\Page * @throws NotFoundException */ public function execute() { if (!$this->wishlistProvider->getWishlist()) { throw new NotFoundException(__('Page not found.')); } /** @var \Magento\Framework\View\Result\Page resultPage */ $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); return $resultPage; }
/** * Action to accept new configuration for a wishlist item * * @return \Magento\Framework\Controller\Result\Redirect */ public function executeInternal() { $productId = (int)$this->getRequest()->getParam('product'); /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$productId) { $resultRedirect->setPath('*/'); return $resultRedirect; } try { $product = $this->productRepository->getById($productId); } catch (NoSuchEntityException $e) { $product = null; } if (!$product || !$product->isVisibleInCatalog()) { $this->messageManager->addError(__('We can\'t specify a product.')); $resultRedirect->setPath('*/'); return $resultRedirect; } try { $id = (int)$this->getRequest()->getParam('id'); /* @var \Magento\Wishlist\Model\Item */ $item = $this->_objectManager->create('Magento\Wishlist\Model\Item'); $item->load($id); $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { $resultRedirect->setPath('*/'); return $resultRedirect; } $buyRequest = new \Magento\Framework\DataObject($this->getRequest()->getParams()); $wishlist->updateItem($id, $buyRequest)->save(); $this->_objectManager->get('Magento\Wishlist\Helper\Data')->calculate(); $this->_eventManager->dispatch( 'wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $wishlist->getItem($id)] ); $this->_objectManager->get('Magento\Wishlist\Helper\Data')->calculate(); $message = __('%1 has been updated in your Wish List.', $product->getName()); $this->messageManager->addSuccess($message); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t update your Wish List right now.')); $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); } $resultRedirect->setPath('*/*', ['wishlist_id' => $wishlist->getId()]); return $resultRedirect; }
/** * Action to reconfigure wishlist item * * @return \Magento\Framework\Controller\ResultInterface * @throws NotFoundException */ public function executeInternal() { $id = (int)$this->getRequest()->getParam('id'); /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); try { /* @var $item \Magento\Wishlist\Model\Item */ $item = $this->_objectManager->create('Magento\Wishlist\Model\Item'); $item->loadWithOptions($id); if (!$item->getId()) { throw new \Magento\Framework\Exception\LocalizedException( __('We can\'t load the Wish List item right now.') ); } $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { throw new NotFoundException(__('Page not found.')); } $this->_coreRegistry->register('wishlist_item', $item); $params = new \Magento\Framework\DataObject(); $params->setCategoryId(false); $params->setConfigureMode(true); $buyRequest = $item->getBuyRequest(); if (!$buyRequest->getQty() && $item->getQty()) { $buyRequest->setQty($item->getQty()); } if ($buyRequest->getQty() && !$item->getQty()) { $item->setQty($buyRequest->getQty()); $this->_objectManager->get('Magento\Wishlist\Helper\Data')->calculate(); } $params->setBuyRequest($buyRequest); /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); $this->_objectManager->get( 'Magento\Catalog\Helper\Product\View' )->prepareAndRender( $resultPage, $item->getProductId(), $this, $params ); return $resultPage; } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); $resultRedirect->setPath('*'); return $resultRedirect; } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t configure the product right now.')); $this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); $resultRedirect->setPath('*'); return $resultRedirect; } }
/** * Adding new item * * @return \Magento\Framework\Controller\Result\Redirect * @throws NotFoundException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function execute() { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$this->formKeyValidator->validate($this->getRequest())) { return $resultRedirect->setPath('*/'); } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(__('Page not found.')); } $session = $this->_customerSession; $requestParams = $this->getRequest()->getParams(); if ($session->getBeforeWishlistRequest()) { $requestParams = $session->getBeforeWishlistRequest(); $session->unsBeforeWishlistRequest(); } $productId = isset($requestParams['product']) ? (int) $requestParams['product'] : null; if (!$productId) { $resultRedirect->setPath('*/'); return $resultRedirect; } try { $product = $this->productRepository->getById($productId); } catch (NoSuchEntityException $e) { $product = null; } if (!$product || !$product->isVisibleInCatalog()) { $this->messageManager->addErrorMessage(__('We can\'t specify a product.')); $resultRedirect->setPath('*/'); return $resultRedirect; } try { $buyRequest = new \Magento\Framework\DataObject($requestParams); $result = $wishlist->addNewItem($product, $buyRequest); if (is_string($result)) { throw new \Magento\Framework\Exception\LocalizedException(__($result)); } $wishlist->save(); $this->_eventManager->dispatch('wishlist_add_product', ['wishlist' => $wishlist, 'product' => $product, 'item' => $result]); $referer = $session->getBeforeWishlistUrl(); if ($referer) { $session->setBeforeWishlistUrl(null); } else { $referer = $this->_redirect->getRefererUrl(); } $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); $this->messageManager->addComplexSuccessMessage('addProductSuccessMessage', ['product_name' => $product->getName(), 'referer' => $referer]); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addErrorMessage(__('We can\'t add the item to Wish List right now: %1.', $e->getMessage())); } catch (\Exception $e) { $this->messageManager->addExceptionMessage($e, __('We can\'t add the item to Wish List right now.')); } $resultRedirect->setPath('*', ['wishlist_id' => $wishlist->getId()]); return $resultRedirect; }
/** * Adding new item * * @return \Magento\Framework\Controller\Result\Redirect * @throws NotFoundException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function execute() { $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(__('Page not found.')); } $session = $this->_customerSession; $requestParams = $this->getRequest()->getParams(); if ($session->getBeforeWishlistRequest()) { $requestParams = $session->getBeforeWishlistRequest(); $session->unsBeforeWishlistRequest(); } $productId = isset($requestParams['product']) ? (int) $requestParams['product'] : null; /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$productId) { $resultRedirect->setPath('*/'); return $resultRedirect; } try { $product = $this->productRepository->getById($productId); } catch (NoSuchEntityException $e) { $product = null; } if (!$product || !$product->isVisibleInCatalog()) { $this->messageManager->addError(__('We can\'t specify a product.')); $resultRedirect->setPath('*/'); return $resultRedirect; } try { $buyRequest = new \Magento\Framework\Object($requestParams); $result = $wishlist->addNewItem($product, $buyRequest); if (is_string($result)) { throw new \Magento\Framework\Exception\LocalizedException(__($result)); } $wishlist->save(); $this->_eventManager->dispatch('wishlist_add_product', ['wishlist' => $wishlist, 'product' => $product, 'item' => $result]); $referer = $session->getBeforeWishlistUrl(); if ($referer) { $session->setBeforeWishlistUrl(null); } else { $referer = $this->_redirect->getRefererUrl(); } $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); $message = __('%1 has been added to your wishlist. Click <a href="%2">here</a> to continue shopping.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($product->getName()), $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeUrl($referer)); $this->messageManager->addSuccess($message); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError(__('An error occurred while adding item to wish list: %1', $e->getMessage())); } catch (\Exception $e) { $this->messageManager->addError(__('An error occurred while adding item to wish list.')); $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); } $resultRedirect->setPath('*', ['wishlist_id' => $wishlist->getId()]); return $resultRedirect; }
/** * Adding new item * * @return void * @throws NotFoundException */ public function execute() { $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(); } $session = $this->_customerSession; $requestParams = $this->getRequest()->getParams(); if ($session->getBeforeWishlistRequest()) { $requestParams = $session->getBeforeWishlistRequest(); $session->unsBeforeWishlistRequest(); } $productId = isset($requestParams['product']) ? (int) $requestParams['product'] : null; if (!$productId) { $this->_redirect('*/'); return; } $product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->load($productId); if (!$product->getId() || !$product->isVisibleInCatalog()) { $this->messageManager->addError(__('We can\'t specify a product.')); $this->_redirect('*/'); return; } try { $buyRequest = new \Magento\Framework\Object($requestParams); $result = $wishlist->addNewItem($product, $buyRequest); if (is_string($result)) { throw new \Magento\Framework\Model\Exception($result); } $wishlist->save(); $this->_eventManager->dispatch('wishlist_add_product', array('wishlist' => $wishlist, 'product' => $product, 'item' => $result)); $referer = $session->getBeforeWishlistUrl(); if ($referer) { $session->setBeforeWishlistUrl(null); } else { $referer = $this->_redirect->getRefererUrl(); } /** * Set referer to avoid referring to the compare popup window */ $session->setAddActionReferer($referer); /** @var $helper \Magento\Wishlist\Helper\Data */ $helper = $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); $message = __('%1 has been added to your wishlist. Click <a href="%2">here</a> to continue shopping.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($product->getName()), $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeUrl($referer)); $this->messageManager->addSuccess($message); } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError(__('An error occurred while adding item to wish list: %1', $e->getMessage())); } catch (\Exception $e) { $this->messageManager->addError(__('An error occurred while adding item to wish list.')); $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); } $this->_redirect('*', array('wishlist_id' => $wishlist->getId())); }
/** * Add all items from wishlist to shopping cart * * @return void */ public function execute() { if (!$this->formKeyValidator->validate($this->getRequest())) { $this->_forward('noroute'); return; } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { $this->_forward('noroute'); return; } $redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty')); $this->getResponse()->setRedirect($redirectUrl); }
public function testExecutePassed() { $url = 'http://redirect-url.com'; $wishlist = $this->getMock('Magento\Wishlist\Model\Wishlist', [], [], '', false); $this->formKeyValidator->expects($this->once()) ->method('validate') ->with($this->request) ->will($this->returnValue(true)); $this->request->expects($this->once()) ->method('getParam') ->with('qty') ->will($this->returnValue(2)); $this->wishlistProvider->expects($this->once()) ->method('getWishlist') ->will($this->returnValue($wishlist)); $this->itemCarrier->expects($this->once()) ->method('moveAllToCart') ->with($wishlist, 2) ->willReturn($url); $this->resultRedirectMock->expects($this->once()) ->method('setUrl') ->with($url) ->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->getController()->executeInternal()); }
/** * Add wishlist item to shopping cart and remove from wishlist * * If Product has required options - item removed from wishlist and redirect * to product view page with message about needed defined required options * * @return ResponseInterface * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() { $itemId = (int) $this->getRequest()->getParam('item'); /* @var $item \Magento\Wishlist\Model\Item */ $item = $this->itemFactory->create()->load($itemId); if (!$item->getId()) { return $this->_redirect('*/*'); } $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { return $this->_redirect('*/*'); } // Set qty $qty = $this->getRequest()->getParam('qty'); if (is_array($qty)) { if (isset($qty[$itemId])) { $qty = $qty[$itemId]; } else { $qty = 1; } } $qty = $this->quantityProcessor->process($qty); if ($qty) { $item->setQty($qty); } $redirectUrl = $this->_url->getUrl('*/*'); $configureUrl = $this->_url->getUrl('*/*/configure/', ['id' => $item->getId(), 'product_id' => $item->getProductId()]); try { /** @var \Magento\Wishlist\Model\Resource\Item\Option\Collection $options */ $options = $this->optionFactory->create()->getCollection()->addItemFilter([$itemId]); $item->setOptions($options->getOptionsByItem($itemId)); $buyRequest = $this->productHelper->addParamsToBuyRequest($this->getRequest()->getParams(), ['current_config' => $item->getBuyRequest()]); $item->mergeBuyRequest($buyRequest); $item->addToCart($this->cart, true); $this->cart->save()->getQuote()->collectTotals(); $wishlist->save(); if (!$this->cart->getQuote()->getHasError()) { $message = __('You added %1 to your shopping cart.', $this->escaper->escapeHtml($item->getProduct()->getName())); $this->messageManager->addSuccess($message); } if ($this->cart->getShouldRedirectToCart()) { $redirectUrl = $this->cart->getCartUrl(); } else { $refererUrl = $this->_redirect->getRefererUrl(); if ($refererUrl && $refererUrl != $configureUrl) { $redirectUrl = $refererUrl; } } } catch (ProductException $e) { $this->messageManager->addError(__('This product(s) is out of stock.')); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addNotice($e->getMessage()); $redirectUrl = $configureUrl; } catch (\Exception $e) { $this->messageManager->addException($e, __('Cannot add item to shopping cart')); } $this->helper->calculate(); return $this->getResponse()->setRedirect($redirectUrl); }
/** * Wishlist rss feed action * Show all public wishlists and private wishlists that belong to current user * * @return void */ public function execute() { if (!$this->rssWishlistHelper->isRssAllow()) { $this->_forward('noroute'); return; } /** @var \Magento\Wishlist\Model\Wishlist $wishlist */ $wishlist = $this->wishlistProvider->getWishlist(); if ($wishlist && ($wishlist->getVisibility() || $this->customerSession->authenticate($this) && $wishlist->getCustomerId() == $this->rssWishlistHelper->getCustomer()->getId())) { $this->getResponse()->setHeader('Content-Type', 'text/xml; charset=UTF-8'); $this->_view->loadLayout(false); $this->_view->renderLayout(); return; } /** @var \Magento\Rss\Helper\Data $rssHelper */ $rssHelper = $this->rssHelperFactory->create(); $rssHelper->sendEmptyRssFeed($this->getResponse()); }
/** * Display customer wishlist * * @return void * @throws NotFoundException */ public function execute() { if (!$this->wishlistProvider->getWishlist()) { throw new NotFoundException(); } $this->_view->loadLayout(); $session = $this->_customerSession; $block = $this->_view->getLayout()->getBlock('customer.wishlist'); $referer = $session->getAddActionReferer(true); if ($block) { $block->setRefererUrl($this->_redirect->getRefererUrl()); if ($referer) { $block->setRefererUrl($referer); } } $this->_view->getLayout()->initMessages(); $this->_view->renderLayout(); }
/** * Add all items from wishlist to shopping cart * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { /** @var \Magento\Framework\Controller\Result\Forward $resultForward */ $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); if (!$this->formKeyValidator->validate($this->getRequest())) { $resultForward->forward('noroute'); return $resultForward; } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { $resultForward->forward('noroute'); return $resultForward; } /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty')); $resultRedirect->setUrl($redirectUrl); return $resultRedirect; }
public function testExecutePassed() { $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false); $this->formKeyValidator->expects($this->once())->method('validate')->with($this->request)->will($this->returnValue(true)); $this->request->expects($this->once())->method('getParam')->with('qty')->will($this->returnValue(2)); $this->response->expects($this->once())->method('setRedirect')->will($this->returnValue('http://redirect-url.com')); $this->wishlistProvider->expects($this->once())->method('getWishlist')->will($this->returnValue($wishlist)); $this->itemCarrier->expects($this->once())->method('moveAllToCart')->with($wishlist, 2)->will($this->returnValue('http://redirect-url.com')); $this->getController()->execute(); }
/** * Action to accept new configuration for a wishlist item * * @return void */ public function execute() { $productId = (int) $this->getRequest()->getParam('product'); if (!$productId) { $this->_redirect('*/'); return; } try { $product = $this->productRepository->getById($productId); } catch (NoSuchEntityException $e) { $product = null; } if (!$product || !$product->isVisibleInCatalog()) { $this->messageManager->addError(__('We can\'t specify a product.')); $this->_redirect('*/'); return; } try { $id = (int) $this->getRequest()->getParam('id'); /* @var \Magento\Wishlist\Model\Item */ $item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item'); $item->load($id); $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { $this->_redirect('*/'); return; } $buyRequest = new \Magento\Framework\Object($this->getRequest()->getParams()); $wishlist->updateItem($id, $buyRequest)->save(); $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); $this->_eventManager->dispatch('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $wishlist->getItem($id)]); $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); $message = __('%1 has been updated in your wish list.', $product->getName()); $this->messageManager->addSuccess($message); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addError(__('An error occurred while updating wish list.')); $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); } $this->_redirect('*/*', ['wishlist_id' => $wishlist->getId()]); }
/** * Retrieve wishlist by logged in customer * * @return \Magento\Wishlist\Model\Wishlist */ public function getWishlist() { if ($this->_wishlist === null) { if ($this->_coreRegistry->registry('shared_wishlist')) { $this->_wishlist = $this->_coreRegistry->registry('shared_wishlist'); } else { $this->_wishlist = $this->wishlistProvider->getWishlist(); } } return $this->_wishlist; }
/** * Action to reconfigure wishlist item * * @return void * @throws NotFoundException */ public function execute() { $id = (int) $this->getRequest()->getParam('id'); try { /* @var $item \Magento\Wishlist\Model\Item */ $item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item'); $item->loadWithOptions($id); if (!$item->getId()) { throw new \Magento\Framework\Model\Exception(__('We can\'t load the wish list item.')); } $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { throw new NotFoundException(); } $this->_coreRegistry->register('wishlist_item', $item); $params = new \Magento\Framework\Object(); $params->setCategoryId(false); $params->setConfigureMode(true); $buyRequest = $item->getBuyRequest(); if (!$buyRequest->getQty() && $item->getQty()) { $buyRequest->setQty($item->getQty()); } if ($buyRequest->getQty() && !$item->getQty()) { $item->setQty($buyRequest->getQty()); $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); } $params->setBuyRequest($buyRequest); $this->_objectManager->get('Magento\\Catalog\\Helper\\Product\\View')->prepareAndRender($item->getProductId(), $this, $params); } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError($e->getMessage()); $this->_redirect('*'); return; } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t configure the product.')); $this->_objectManager->get('Magento\\Framework\\Logger')->logException($e); $this->_redirect('*'); return; } }
/** * Remove item * * @return \Magento\Framework\Controller\Result\Redirect * @throws NotFoundException */ public function execute() { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$this->formKeyValidator->validate($this->getRequest())) { return $resultRedirect->setPath('*/*/'); } $id = (int) $this->getRequest()->getParam('item'); $item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item')->load($id); if (!$item->getId()) { throw new NotFoundException(__('Page not found.')); } $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { throw new NotFoundException(__('Page not found.')); } try { $item->delete(); $wishlist->save(); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError(__('We can\'t delete the item from Wish List right now because of an error: %1.', $e->getMessage())); } catch (\Exception $e) { $this->messageManager->addError(__('We can\'t delete the item from the Wish List right now.')); } $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); $request = $this->getRequest(); $refererUrl = (string) $request->getServer('HTTP_REFERER'); $url = (string) $request->getParam(\Magento\Framework\App\Response\RedirectInterface::PARAM_NAME_REFERER_URL); if ($url) { $refererUrl = $url; } if ($request->getParam(\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED) && $refererUrl) { $redirectUrl = $refererUrl; } else { $redirectUrl = $this->_redirect->getRedirectUrl($this->_url->getUrl('*/*')); } $resultRedirect->setUrl($redirectUrl); return $resultRedirect; }
/** * Remove item * * @return void * @throws NotFoundException */ public function execute() { $id = (int) $this->getRequest()->getParam('item'); $item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item')->load($id); if (!$item->getId()) { throw new NotFoundException(); } $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { throw new NotFoundException(); } try { $item->delete(); $wishlist->save(); } catch (\Magento\Framework\Model\Exception $e) { $this->messageManager->addError(__('An error occurred while deleting the item from wish list: %1', $e->getMessage())); } catch (\Exception $e) { $this->messageManager->addError(__('An error occurred while deleting the item from wish list.')); } $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); $url = $this->_redirect->getRedirectUrl($this->_url->getUrl('*/*')); $this->getResponse()->setRedirect($url); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testExecuteWithoutQuantityArrayAndConfigurable() { $itemId = 2; $wishlistId = 1; $qty = []; $productId = 4; $indexUrl = 'index_url'; $configureUrl = 'configure_url'; $options = [5 => 'option']; $params = ['item' => $itemId, 'qty' => $qty]; $this->formKeyValidator->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true); $itemMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item')->disableOriginalConstructor()->setMethods(['load', 'getId', 'getWishlistId', 'setQty', 'setOptions', 'getBuyRequest', 'mergeBuyRequest', 'addToCart', 'getProduct', 'getProductId'])->getMock(); $this->requestMock->expects($this->at(0))->method('getParam')->with('item', null)->willReturn($itemId); $this->itemFactoryMock->expects($this->once())->method('create')->willReturn($itemMock); $itemMock->expects($this->once())->method('load')->with($itemId, null)->willReturnSelf(); $itemMock->expects($this->exactly(2))->method('getId')->willReturn($itemId); $itemMock->expects($this->once())->method('getWishlistId')->willReturn($wishlistId); $wishlistMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock(); $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->with($wishlistId)->willReturn($wishlistMock); $this->requestMock->expects($this->at(1))->method('getParam')->with('qty', null)->willReturn($qty); $this->quantityProcessorMock->expects($this->once())->method('process')->with(1)->willReturnArgument(0); $itemMock->expects($this->once())->method('setQty')->with(1)->willReturnSelf(); $this->urlMock->expects($this->at(0))->method('getUrl')->with('*/*', null)->willReturn($indexUrl); $itemMock->expects($this->once())->method('getProductId')->willReturn($productId); $this->urlMock->expects($this->at(1))->method('getUrl')->with('*/*/configure/', ['id' => $itemId, 'product_id' => $productId])->willReturn($configureUrl); $optionMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item\\Option')->disableOriginalConstructor()->getMock(); $this->optionFactoryMock->expects($this->once())->method('create')->willReturn($optionMock); $optionsMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\ResourceModel\\Item\\Option\\Collection')->disableOriginalConstructor()->getMock(); $optionMock->expects($this->once())->method('getCollection')->willReturn($optionsMock); $optionsMock->expects($this->once())->method('addItemFilter')->with([$itemId])->willReturnSelf(); $optionsMock->expects($this->once())->method('getOptionsByItem')->with($itemId)->willReturn($options); $itemMock->expects($this->once())->method('setOptions')->with($options)->willReturnSelf(); $this->requestMock->expects($this->once())->method('getParams')->willReturn($params); $buyRequestMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock(); $itemMock->expects($this->once())->method('getBuyRequest')->willReturn($buyRequestMock); $this->productHelperMock->expects($this->once())->method('addParamsToBuyRequest')->with($params, ['current_config' => $buyRequestMock])->willReturn($buyRequestMock); $itemMock->expects($this->once())->method('mergeBuyRequest')->with($buyRequestMock)->willReturnSelf(); $itemMock->expects($this->once())->method('addToCart')->with($this->checkoutCartMock, true)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('message'))); $this->messageManagerMock->expects($this->once())->method('addNotice')->with('message', null)->willReturnSelf(); $this->helperMock->expects($this->once())->method('calculate')->willReturnSelf(); $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($configureUrl)->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->model->execute()); }
public function testGetWishlist() { $wishlist = $this->getMock('\\Magento\\Wishlist\\Model\\Wishlist', [], [], '', false); $this->wishlistProvider->expects($this->once())->method('getWishlist')->will($this->returnValue($wishlist)); $this->assertEquals($wishlist, $this->wishlistHelper->getWishlist()); }
/** * Update wishlist item comments * * @return \Magento\Framework\Controller\Result\Redirect * @throws NotFoundException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function execute() { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$this->_formKeyValidator->validate($this->getRequest())) { $resultRedirect->setPath('*/*/'); return $resultRedirect; } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(__('Page not found.')); } $post = $this->getRequest()->getPostValue(); if ($post && isset($post['description']) && is_array($post['description'])) { $updatedItems = 0; foreach ($post['description'] as $itemId => $description) { $item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item')->load($itemId); if ($item->getWishlistId() != $wishlist->getId()) { continue; } // Extract new values $description = (string) $description; if ($description == $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->defaultCommentString()) { $description = ''; } elseif (!strlen($description)) { $description = $item->getDescription(); } $qty = null; if (isset($post['qty'][$itemId])) { $qty = $this->quantityProcessor->process($post['qty'][$itemId]); } if ($qty === null) { $qty = $item->getQty(); if (!$qty) { $qty = 1; } } elseif (0 == $qty) { try { $item->delete(); } catch (\Exception $e) { $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e); $this->messageManager->addError(__('Can\'t delete item from wishlist')); } } // Check that we need to save if ($item->getDescription() == $description && $item->getQty() == $qty) { continue; } try { $item->setDescription($description)->setQty($qty)->save(); $updatedItems++; } catch (\Exception $e) { $this->messageManager->addError(__('Can\'t save description %1', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($description))); } } // save wishlist model for setting date of last update if ($updatedItems) { try { $wishlist->save(); $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); } catch (\Exception $e) { $this->messageManager->addError(__('Can\'t update wish list')); } } if (isset($post['save_and_share'])) { $resultRedirect->setPath('*/*/share', ['wishlist_id' => $wishlist->getId()]); return $resultRedirect; } } $resultRedirect->setPath('*', ['wishlist_id' => $wishlist->getId()]); return $resultRedirect; }
/** * Share wishlist * * @return ResponseInterface|void * @throws NotFoundException */ public function execute() { if (!$this->_formKeyValidator->validate($this->getRequest())) { return $this->_redirect('*/*/'); } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(); } $sharingLimit = $this->_wishlistConfig->getSharingEmailLimit(); $textLimit = $this->_wishlistConfig->getSharingTextLimit(); $emailsLeft = $sharingLimit - $wishlist->getShared(); $emails = explode(',', $this->getRequest()->getPost('emails')); $error = false; $message = (string) $this->getRequest()->getPost('message'); if (strlen($message) > $textLimit) { $error = __('Message length must not exceed %1 symbols', $textLimit); } else { $message = nl2br(htmlspecialchars($message)); if (empty($emails)) { $error = __('Email address can\'t be empty.'); } else { if (count($emails) > $emailsLeft) { $error = __('This wishlist can be shared %1 more times.', $emailsLeft); } else { foreach ($emails as $index => $email) { $email = trim($email); if (!\Zend_Validate::is($email, 'EmailAddress')) { $error = __('Please input a valid email address.'); break; } $emails[$index] = $email; } } } } if ($error) { $this->messageManager->addError($error); $this->_objectManager->get('Magento\\Wishlist\\Model\\Session')->setSharingForm($this->getRequest()->getPost()); $this->_redirect('*/*/share'); return; } $this->inlineTranslation->suspend(); $sent = 0; try { $customer = $this->_customerSession->getCustomerDataObject(); $customerName = $this->_customerHelperView->getCustomerName($customer); /*if share rss added rss feed to email template*/ if ($this->getRequest()->getParam('rss_url')) { $rss_url = $this->_view->getLayout()->createBlock('Magento\\Wishlist\\Block\\Share\\Email\\Rss')->setWishlistId($wishlist->getId())->toHtml(); $message .= $rss_url; } $wishlistBlock = $this->_view->getLayout()->createBlock('Magento\\Wishlist\\Block\\Share\\Email\\Items')->toHtml(); $emails = array_unique($emails); $sharingCode = $wishlist->getSharingCode(); try { $scopeConfig = $this->_objectManager->get('Magento\\Framework\\App\\Config\\ScopeConfigInterface'); $storeManager = $this->_objectManager->get('Magento\\Framework\\StoreManagerInterface'); foreach ($emails as $email) { $transport = $this->_transportBuilder->setTemplateIdentifier($scopeConfig->getValue('wishlist/email/email_template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeManager->getStore()->getStoreId()))->setTemplateVars(array('customer' => $customer, 'customerName' => $customerName, 'salable' => $wishlist->isSalable() ? 'yes' : '', 'items' => $wishlistBlock, 'addAllLink' => $this->_url->getUrl('*/shared/allcart', array('code' => $sharingCode)), 'viewOnSiteLink' => $this->_url->getUrl('*/shared/index', array('code' => $sharingCode)), 'message' => $message, 'store' => $storeManager->getStore()))->setFrom($scopeConfig->getValue('wishlist/email/email_identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($email)->getTransport(); $transport->sendMessage(); $sent++; } } catch (\Exception $e) { $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); throw $e; } $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); $this->inlineTranslation->resume(); $this->_eventManager->dispatch('wishlist_share', array('wishlist' => $wishlist)); $this->messageManager->addSuccess(__('Your wish list has been shared.')); $this->_redirect('*/*', array('wishlist_id' => $wishlist->getId())); } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError($e->getMessage()); $this->_objectManager->get('Magento\\Wishlist\\Model\\Session')->setSharingForm($this->getRequest()->getPost()); $this->_redirect('*/*/share'); } }
/** * Share wishlist * * @return \Magento\Framework\Controller\Result\Redirect * @throws NotFoundException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function execute() { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); if (!$this->_formKeyValidator->validate($this->getRequest())) { $resultRedirect->setPath('*/*/'); return $resultRedirect; } $wishlist = $this->wishlistProvider->getWishlist(); if (!$wishlist) { throw new NotFoundException(__('Page not found.')); } $sharingLimit = $this->_wishlistConfig->getSharingEmailLimit(); $textLimit = $this->_wishlistConfig->getSharingTextLimit(); $emailsLeft = $sharingLimit - $wishlist->getShared(); $emails = $this->getRequest()->getPost('emails'); $emails = empty($emails) ? $emails : explode(',', $emails); $error = false; $message = (string) $this->getRequest()->getPost('message'); if (strlen($message) > $textLimit) { $error = __('Message length must not exceed %1 symbols', $textLimit); } else { $message = nl2br(htmlspecialchars($message)); if (empty($emails)) { $error = __('Please enter an email address.'); } else { if (count($emails) > $emailsLeft) { $error = __('This wish list can be shared %1 more times.', $emailsLeft); } else { foreach ($emails as $index => $email) { $email = trim($email); if (!\Zend_Validate::is($email, 'EmailAddress')) { $error = __('Please input a valid email address.'); break; } $emails[$index] = $email; } } } } if ($error) { $this->messageManager->addError($error); $this->wishlistSession->setSharingForm($this->getRequest()->getPostValue()); $resultRedirect->setPath('*/*/share'); return $resultRedirect; } /** @var \Magento\Framework\View\Result\Layout $resultLayout */ $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT); $this->addLayoutHandles($resultLayout); $this->inlineTranslation->suspend(); $sent = 0; try { $customer = $this->_customerSession->getCustomerDataObject(); $customerName = $this->_customerHelperView->getCustomerName($customer); $message .= $this->getRssLink($wishlist->getId(), $resultLayout); $emails = array_unique($emails); $sharingCode = $wishlist->getSharingCode(); try { foreach ($emails as $email) { $transport = $this->_transportBuilder->setTemplateIdentifier($this->scopeConfig->getValue('wishlist/email/email_template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->storeManager->getStore()->getStoreId()])->setTemplateVars(['customer' => $customer, 'customerName' => $customerName, 'salable' => $wishlist->isSalable() ? 'yes' : '', 'items' => $this->getWishlistItems($resultLayout), 'viewOnSiteLink' => $this->_url->getUrl('*/shared/index', ['code' => $sharingCode]), 'message' => $message, 'store' => $this->storeManager->getStore()])->setFrom($this->scopeConfig->getValue('wishlist/email/email_identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE))->addTo($email)->getTransport(); $transport->sendMessage(); $sent++; } } catch (\Exception $e) { $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); throw $e; } $wishlist->setShared($wishlist->getShared() + $sent); $wishlist->save(); $this->inlineTranslation->resume(); $this->_eventManager->dispatch('wishlist_share', ['wishlist' => $wishlist]); $this->messageManager->addSuccess(__('Your wish list has been shared.')); $resultRedirect->setPath('*/*', ['wishlist_id' => $wishlist->getId()]); return $resultRedirect; } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError($e->getMessage()); $this->wishlistSession->setSharingForm($this->getRequest()->getPostValue()); $resultRedirect->setPath('*/*/share'); return $resultRedirect; } }
/** * Retrieve wishlist by logged in customer * * @return \Magento\Wishlist\Model\Wishlist */ public function getWishlist() { if (is_null($this->_wishlist)) { if ($this->_coreRegistry->registry('shared_wishlist')) { $this->_wishlist = $this->_coreRegistry->registry('shared_wishlist'); } else { $this->_wishlist = $this->wishlistProvider->getWishlist(); if (!$this->_wishlist) { $this->_wishlist = $this->_wishlistFactory->create(); if ($this->getCustomer()) { $this->_wishlist->loadByCustomerId($this->getCustomer()->getId()); } } } } return $this->_wishlist; }
/** * Add wishlist item to shopping cart and remove from wishlist * * If Product has required options - item removed from wishlist and redirect * to product view page with message about needed defined required options * * @return ResponseInterface */ public function execute() { $itemId = (int) $this->getRequest()->getParam('item'); /* @var $item \Magento\Wishlist\Model\Item */ $item = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item')->load($itemId); if (!$item->getId()) { return $this->_redirect('*/*'); } $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId()); if (!$wishlist) { return $this->_redirect('*/*'); } // Set qty $qty = $this->getRequest()->getParam('qty'); if (is_array($qty)) { if (isset($qty[$itemId])) { $qty = $qty[$itemId]; } else { $qty = 1; } } $qty = $this->quantityProcessor->process($qty); if ($qty) { $item->setQty($qty); } /* @var $session \Magento\Framework\Session\Generic */ $session = $this->_objectManager->get('Magento\\Wishlist\\Model\\Session'); $cart = $this->_objectManager->get('Magento\\Checkout\\Model\\Cart'); $redirectUrl = $this->_url->getUrl('*/*'); try { $options = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item\\Option')->getCollection()->addItemFilter(array($itemId)); $item->setOptions($options->getOptionsByItem($itemId)); $buyRequest = $this->_objectManager->get('Magento\\Catalog\\Helper\\Product')->addParamsToBuyRequest($this->getRequest()->getParams(), array('current_config' => $item->getBuyRequest())); $item->mergeBuyRequest($buyRequest); $item->addToCart($cart, true); $cart->save()->getQuote()->collectTotals(); $wishlist->save(); if (!$cart->getQuote()->getHasError()) { $message = __('You added %1 to your shopping cart.', $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($item->getProduct()->getName())); $this->messageManager->addSuccess($message); } $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); if ($this->_objectManager->get('Magento\\Checkout\\Helper\\Cart')->getShouldRedirectToCart()) { $redirectUrl = $this->_objectManager->get('Magento\\Checkout\\Helper\\Cart')->getCartUrl(); } else { $refererUrl = $this->_redirect->getRefererUrl(); if ($refererUrl && $refererUrl != $this->_objectManager->get('Magento\\Framework\\UrlInterface')->getUrl('*/*/configure/', array('id' => $item->getId()))) { $redirectUrl = $refererUrl; } } $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); } catch (\Magento\Framework\Model\Exception $e) { if ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_NOT_SALABLE) { $this->messageManager->addError(__('This product(s) is out of stock.')); } elseif ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) { $this->messageManager->addNotice($e->getMessage()); $redirectUrl = $this->_url->getUrl('*/*/configure/', array('id' => $item->getId())); } else { $this->messageManager->addNotice($e->getMessage()); $redirectUrl = $this->_url->getUrl('*/*/configure/', array('id' => $item->getId())); } } catch (\Exception $e) { $this->messageManager->addException($e, __('Cannot add item to shopping cart')); } $this->_objectManager->get('Magento\\Wishlist\\Helper\\Data')->calculate(); return $this->getResponse()->setRedirect($redirectUrl); }