<?php
/**
 * Magetop Store
 *
 * @category  Magetop Extensions
 * @package   Magetop_Quotesystem
 * @author    Magetop Developer
 * @copyright Copyright (c) Magetop (https://www.magetop.com)
 * @license   https://www.magetop.com/license.html
 */

namespace Magetop\Quotesystem\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magetop\Quotesystem\Helper\Data;
use Magento\Customer\Model\Account\Redirect as AccountRedirect;

class SetRedirectCookie implements ObserverInterface
{
    /**
     * @var \Magento\Framework\App\Response\RedirectInterface
     */
    protected $redirect;

    /**
     * @var AccountRedirect
     */
    protected $accountRedirect;

    /**
     * @var \Magento\Checkout\Model\Session
     */
    protected $checkoutSession;
    
    /**
     * @param AccountRedirect                                   $accountRedirect
     * @param \Magento\Framework\App\Response\RedirectInterface $redirect
     * @param \Magento\Checkout\Model\Session                   $checkoutSession
     */
    public function __construct(
        AccountRedirect $accountRedirect,
        \Magento\Framework\App\Response\RedirectInterface $redirect,
        \Magento\Checkout\Model\Session $checkoutSession
    ) {
        $this->accountRedirect = $accountRedirect;
        $this->redirect = $redirect;
        $this->checkoutSession = $checkoutSession;
    }

    /**
     * Quote Item qty Set after
     *
     * @param \Magento\Framework\Event\Observer $observer
     */

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $refererUrl = $this->checkoutSession->getReferUrl();
        $this->accountRedirect->setRedirectCookie($refererUrl);
    }
}
