16 use Magento\Wishlist\Model\Item\OptionFactory;
17 use Magento\Wishlist\Model\ItemFactory;
59 ActionContext $context,
71 parent::__construct($context);
84 $itemId = (int)$this->
getRequest()->getParam(
'item');
87 $item = $this->itemFactory->create()
90 $redirectUrl = $this->
_redirect->getRefererUrl();
94 $options = $this->optionFactory->create()
95 ->getCollection()->addItemFilter([$itemId]);
97 $item->addToCart($this->cart);
101 if (!$this->cart->getQuote()->getHasError()) {
103 'You added %1 to your shopping cart.',
104 $this->escaper->escapeHtml(
$item->getProduct()->getName())
106 $this->messageManager->addSuccess(
$message);
109 if ($this->cartHelper->getShouldRedirectToCart()) {
110 $redirectUrl = $this->cartHelper->getCartUrl();
112 }
catch (ProductException $e) {
113 $this->messageManager->addError(
__(
'This product(s) is out of stock.'));
114 }
catch (LocalizedException $e) {
115 $this->messageManager->addNotice($e->getMessage());
116 $redirectUrl =
$item->getProductUrl();
117 }
catch (\Exception $e) {
118 $this->messageManager->addException($e,
__(
'We can\'t add the item to the cart right now.'));
122 $resultRedirect->setUrl($redirectUrl);
123 return $resultRedirect;
_redirect($path, $arguments=[])
__construct(ActionContext $context, CustomerCart $cart, OptionFactory $optionFactory, ItemFactory $itemFactory, CartHelper $cartHelper, Escaper $escaper)