Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3780] Redirect for newsletter confirmation #28

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Controller/Subscriber/Confirm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace ScandiPWA\CustomerGraphQl\Controller\Subscriber;

class Confirm extends \Magento\Newsletter\Controller\Subscriber\Confirm
{
/**
* Subscription confirm action.
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
{
$id = (int)$this->getRequest()->getParam('id');
$code = (string)$this->getRequest()->getParam('code');

if ($id && $code) {
/** @var \Magento\Newsletter\Model\Subscriber $subscriber */
$subscriber = $this->_subscriberFactory->create()->load($id);

if ($subscriber->getId() && $subscriber->getCode()) {
if ($subscriber->confirm($code)) {
$this->messageManager->addSuccessMessage(__('Your subscription has been confirmed.'));
} else {
$this->messageManager->addErrorMessage(__('This is an invalid subscription confirmation code.'));
}
} else {
$this->messageManager->addErrorMessage(__('This is an invalid subscription ID.'));
}
}
/** @var \Magento\Framework\Controller\Result\Redirect $redirect */
$redirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
$redirectUrl = $this->_storeManager->getStore()->getBaseUrl().'newsletter/confirm/id/'.$id.'/code/'.$code;
return $redirect->setUrl($redirectUrl);
}
}
2 changes: 2 additions & 0 deletions src/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
type="ScandiPWA\CustomerGraphQl\Model\Customer\CheckCustomerPassword"/>
<preference for="Magento\CustomerGraphQl\Model\Context\AddUserInfoToContext"
type="ScandiPWA\CustomerGraphQl\Model\Context\AddUserInfoToContext"/>
<preference for="Magento\Newsletter\Controller\Subscriber\Confirm"
type="ScandiPWA\CustomerGraphQl\Controller\Subscriber\Confirm"/>
<type name="Magento\Catalog\Helper\Data">
<arguments>
<argument name="customerSession" xsi:type="object">ScandiPWA\CustomerGraphQl\Model\Session</argument>
Expand Down
1 change: 1 addition & 0 deletions src/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<module name="Magento_Integration"/>
<module name="Magento_Customer"/>
<module name="Magento_CustomerGraphQl"/>
<module name="Magento_Newsletter"/>
</sequence>
</module>
</config>