92 \
Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
94 \
Magento\Customer\Helper\View $customerHelperView,
99 $this->_formKeyValidator = $formKeyValidator;
100 $this->_customerSession = $customerSession;
102 $this->_wishlistConfig = $wishlistConfig;
103 $this->_transportBuilder = $transportBuilder;
105 $this->_customerHelperView = $customerHelperView;
109 parent::__construct($context);
125 if (!$this->_formKeyValidator->validate($this->getRequest())) {
126 $resultRedirect->setPath(
'*/*/');
127 return $resultRedirect;
130 $wishlist = $this->wishlistProvider->getWishlist();
135 $sharingLimit = $this->_wishlistConfig->getSharingEmailLimit();
136 $textLimit = $this->_wishlistConfig->getSharingTextLimit();
137 $emailsLeft = $sharingLimit -
$wishlist->getShared();
139 $emails = $this->getRequest()->getPost(
'emails');
140 $emails = empty($emails) ? $emails : explode(
',', $emails);
143 $message = (string)$this->getRequest()->getPost(
'message');
144 if (strlen(
$message) > $textLimit) {
145 $error =
__(
'Message length must not exceed %1 symbols', $textLimit);
148 if (empty($emails)) {
149 $error =
__(
'Please enter an email address.');
151 if (count($emails) > $emailsLeft) {
152 $error =
__(
'This wish list can be shared %1 more times.', $emailsLeft);
157 $error =
__(
'Please enter a valid email address.');
167 $this->messageManager->addError($error);
168 $this->wishlistSession->setSharingForm($this->getRequest()->getPostValue());
169 $resultRedirect->setPath(
'*/*/share');
170 return $resultRedirect;
175 $this->inlineTranslation->suspend();
180 $customer = $this->_customerSession->getCustomerDataObject();
181 $customerName = $this->_customerHelperView->getCustomerName(
$customer);
184 $emails = array_unique($emails);
185 $sharingCode =
$wishlist->getSharingCode();
188 foreach ($emails as
$email) {
189 $transport = $this->_transportBuilder->setTemplateIdentifier(
190 $this->scopeConfig->getValue(
191 'wishlist/email/email_template',
194 )->setTemplateOptions(
196 'area' => \
Magento\Framework\
App\Area::AREA_FRONTEND,
197 'store' => $this->storeManager->getStore()->getStoreId(),
202 'customerName' => $customerName,
203 'salable' =>
$wishlist->isSalable() ?
'yes' :
'',
205 'viewOnSiteLink' => $this->_url->getUrl(
'*/shared/index', [
'code' => $sharingCode]),
207 'store' => $this->storeManager->getStore(),
210 $this->scopeConfig->getValue(
211 'wishlist/email/email_identity',
218 $transport->sendMessage();
222 }
catch (\Exception $e) {
230 $this->inlineTranslation->resume();
232 $this->_eventManager->dispatch(
'wishlist_share', [
'wishlist' =>
$wishlist]);
233 $this->messageManager->addSuccess(
__(
'Your wish list has been shared.'));
234 $resultRedirect->setPath(
'*/*', [
'wishlist_id' =>
$wishlist->getId()]);
235 return $resultRedirect;
236 }
catch (\Exception $e) {
237 $this->inlineTranslation->resume();
238 $this->messageManager->addError($e->getMessage());
239 $this->wishlistSession->setSharingForm($this->getRequest()->getPostValue());
240 $resultRedirect->setPath(
'*/*/share');
241 return $resultRedirect;
256 if ($this->getRequest()->getParam(
'rss_url')) {
257 $resultLayout->addHandle(
'wishlist_email_rss');
259 $resultLayout->addHandle(
'wishlist_email_items');
269 protected function getRssLink($wishlistId, ResultLayout $resultLayout)
271 if ($this->getRequest()->getParam(
'rss_url')) {
272 return $resultLayout->getLayout()
273 ->getBlock(
'wishlist.email.rss')
274 ->setWishlistId($wishlistId)
287 return $resultLayout->getLayout()
288 ->getBlock(
'wishlist.email.items')
__construct(Action\Context $context, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, \Magento\Customer\Model\Session $customerSession, \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider, \Magento\Wishlist\Model\Config $wishlistConfig, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, \Magento\Customer\Helper\View $customerHelperView, WishlistSession $wishlistSession, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager)
getRssLink($wishlistId, ResultLayout $resultLayout)
addLayoutHandles(ResultLayout $resultLayout)
static is($value, $classBaseName, array $args=array(), $namespaces=array())
getWishlistItems(ResultLayout $resultLayout)