I have a observer file that I am using to be able to assign a customer to a specific customer group if a specific checkbox is clicked. all is working great.
However what I want it when this registration observer is used to have the customer redirected to a different page instead of just bringing them to the account dashboard which is where all other registered users go upon registering.
Below is the code I am using in my observer.
namespace Impressmanicure\RegistartionObeserver\Observer\Customer;
use Magento\Framework\Event\ObserverInterface;
class RegisterSuccess implements \Magento\Framework\Event\ObserverInterface
{
/**
* Execute observer
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
const CUSTOMER_GROUP_ID = 3;
protected $_customerRepositoryInterface;
public function __construct( \Magento\Framework\App\RequestInterface $request, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface)
{
$this->_customerRepositoryInterface = $customerRepositoryInterface;
$this->_request = $request;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$customer = $observer->getEvent()->getCustomer();
$postedData = $this->_request->getPost();
if ($postedData['group_id'] == 3)
{
$customer->setGroupId(self::CUSTOMER_GROUP_ID);
$this->_customerRepositoryInterface->save($customer);
$this->response->setRedirect('./././vip-success');
}
}
}
the line
$this->response->setRedirect('./././vip-success');
is what I added in hoping it would overwrite the url redirect url that is used for the customer registration function however its not working what happens is now when you register an account the customer stays on the signup page and gets an error message saying We can't save the customer. even though the account does get created. ??