문제

I want to redirect customers to cart page once they login to the site from the abandoned cart email.

There is a way to set redirect after login is successful but i want redirect to happen only when cart page is accessed from abandoned cart email.

I was thinking to use variable in url that is sent over email but how to achieve that, since on success that variable gets removed from url.

Any help is appreciated,

Thanks.

도움이 되었습니까?

해결책

Just in case anyone is looking for answer to this question: There is event observer which looks for previous url and login actions. Here is the code:

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer as EventObserver;
class CustomerAuthenticated implements ObserverInterface
{

/**
 * Core store config
 *
 * @var \Magento\Framework\App\Config\ScopeConfigInterface
 */
protected $scopeConfig;
/**
 * Uri Validator
 *
 * @var \Zend\Validator\Uri
 */
protected $uri;
/**
 * @var \Magento\Framework\App\ResponseFactory
 */
protected $responseFactory;
/**
 * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
 * @param \Zend\Validator\Uri $uri
 * @param \Magento\Framework\App\ResponseFactory $responseFactory
 */
public function __construct(
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
    \Zend\Validator\Uri $uri,
    \Magento\Framework\App\ResponseFactory $responseFactory,
    \Magento\Framework\ObjectManagerInterface $objectManager,
    \Magento\Framework\App\Response\RedirectInterface $redirect,
    \Magento\Framework\UrlInterface $urlInterface
) {
    $this->scopeConfig = $scopeConfig;
    $this->uri = $uri;
    $this->responseFactory = $responseFactory;
    $this->_objectManager = $objectManager;
    $this->redirect = $redirect;
    $this->_urlInterface = $urlInterface;
}
/**
 * Handler for 'customer_login' event.
 *
 * @param \Magento\Framework\Event\Observer $observer
 * @return void
 */
public function execute(\Magento\Framework\Event\Observer $observer)
{
    $redirectDashboard = $this->scopeConfig->isSetFlag(
        'customer/startup/redirect_dashboard',
        \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES
    );

    $redirectUrl = $this->redirect->getRedirectUrl();

    // if the Redirect Customer to Account Dashboard after Logging in set to "No"
    if (!$redirectDashboard) {

        $account_url = $this->_urlInterface->getUrl('customer/account');
        $cart_url = $this->_urlInterface->getUrl('checkout/cart');

        if (strpos($redirectUrl, 'abandoned') !== false) {
            $redirect_url = $cart_url;
        }else {
            $redirect_url = $account_url;
        }

        $resultRedirect = $this->responseFactory->create();
        $resultRedirect->setRedirect($redirect_url)->sendResponse('200');
        exit();
    }
}
}`
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top