Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Index.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class Index extends Action
13 {
19  protected $registry = null;
20 
24  protected $wishlistProvider;
25 
29  protected $customerSession;
30 
37  public function __construct(
38  Context $context,
40  \Magento\Framework\Registry $registry,
41  \Magento\Customer\Model\Session $customerSession
42  ) {
43  $this->wishlistProvider = $wishlistProvider;
44  $this->registry = $registry;
45  $this->customerSession = $customerSession;
46  parent::__construct($context);
47  }
48 
54  public function execute()
55  {
56  $wishlist = $this->wishlistProvider->getWishlist();
57  $customerId = $this->customerSession->getCustomerId();
58 
59  if ($wishlist && $wishlist->getCustomerId() && $wishlist->getCustomerId() == $customerId) {
61  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
62  $resultRedirect->setUrl(
63  $this->_objectManager->get(\Magento\Wishlist\Helper\Data::class)->getListUrl($wishlist->getId())
64  );
65  return $resultRedirect;
66  }
67 
68  $this->registry->register('shared_wishlist', $wishlist);
69 
71  $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
72  return $resultPage;
73  }
74 }
__construct(Context $context, WishlistProvider $wishlistProvider, \Magento\Framework\Registry $registry, \Magento\Customer\Model\Session $customerSession)
Definition: Index.php:37
$wishlist
Definition: wishlist.php:10