Add PLugin on
Magento\Wishlist\Controller\Index\Plugin
As
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Wishlist\Controller\Index\Plugin">
<plugin name="guest_wishlist_plugin" type="Vendor\Module\Plugin\GuestPlugin" sortOrder="10"/>
</type>
</config>
In your php file Add this Code
Vendor\Module\Plugin\GuestPlugin
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
class GuestPlugin
{
/**
* Name of cookie that holds private content version
*/
const COOKIE_NAME = 'guest_wishlist';
/**
* CookieManager
*
* @var CookieManagerInterface
*/
private $cookieManager;
/**
* @var CookieMetadataFactory
*/
private $cookieMetadataFactory;
/**
* @var SessionManagerInterface
*/
private $sessionManager;
/**
* @var \Magento\Customer\Model\Session
*/
protected $customerSession;
/**
* @var \Magento\Customer\Model\Session
*/
private $customSession;
private $resultFactory;
protected $registry;
public function __construct(
Context $context,
\Vendor\Module\Helper\Data $helper,
ResultFactory $resultFactory,
CookieManagerInterface $cookieManager,
CookieMetadataFactory $cookieMetadataFactory,
SessionManagerInterface $sessionManager,
CustomerSession $customerSession
) {
$this->resultRedirectFactory = $context->getResultRedirectFactory();
$this->customerSession = $customerSession;
$this->cookieManager = $cookieManager;
$this->cookieMetadataFactory = $cookieMetadataFactory;
$this->sessionManager = $sessionManager;
$this->helper = $helper;
$this->resultFactory = $resultFactory;
}
public function beforeBeforeDispatch(
\Magento\Wishlist\Controller\Index\Plugin $coreSubject,
\Magento\Framework\App\ActionInterface $subject,
RequestInterface $request) {
$obj = $request->getParams();
if (!$this->customerSession->isLoggedIn()) {
$cookieValue = explode(', ', $this->cookieManager->getCookie(self::COOKIE_NAME));
if (empty($cookieValue)) {
$cookieValue = array();
}
array_push($cookieValue, $obj['product']);
$this->set(implode(', ', $cookieValue), 100);
}
}
private function set($value, $duration = 86400)
{
$metadata = $this->cookieMetadataFactory
->createPublicCookieMetadata()
->setDuration($duration)
->setPath($this->sessionManager->getCookiePath())
->setDomain($this->sessionManager->getCookieDomain());
$this->cookieManager->setPublicCookie(
self::COOKIE_NAME,
$value,
$metadata
);
}
}
Hope this will Help You Sorry for Late Reply