Index.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Wishlist\Controller\Shared;
  7. use Magento\Framework\App\Action\Action;
  8. use Magento\Framework\App\Action\Context;
  9. use Magento\Framework\Controller\ResultFactory;
  10. class Index extends Action
  11. {
  12. /**
  13. * Core registry
  14. *
  15. * @var \Magento\Framework\Registry
  16. */
  17. protected $registry = null;
  18. /**
  19. * @var WishlistProvider
  20. */
  21. protected $wishlistProvider;
  22. /**
  23. * @var \Magento\Customer\Model\Session
  24. */
  25. protected $customerSession;
  26. /**
  27. * @param Context $context
  28. * @param WishlistProvider $wishlistProvider
  29. * @param \Magento\Framework\Registry $registry
  30. * @param \Magento\Customer\Model\Session $customerSession
  31. */
  32. public function __construct(
  33. Context $context,
  34. WishlistProvider $wishlistProvider,
  35. \Magento\Framework\Registry $registry,
  36. \Magento\Customer\Model\Session $customerSession
  37. ) {
  38. $this->wishlistProvider = $wishlistProvider;
  39. $this->registry = $registry;
  40. $this->customerSession = $customerSession;
  41. parent::__construct($context);
  42. }
  43. /**
  44. * Shared wishlist view page
  45. *
  46. * @return \Magento\Framework\Controller\ResultInterface
  47. */
  48. public function execute()
  49. {
  50. $wishlist = $this->wishlistProvider->getWishlist();
  51. $customerId = $this->customerSession->getCustomerId();
  52. if ($wishlist && $wishlist->getCustomerId() && $wishlist->getCustomerId() == $customerId) {
  53. /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
  54. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  55. $resultRedirect->setUrl(
  56. $this->_objectManager->get(\Magento\Wishlist\Helper\Data::class)->getListUrl($wishlist->getId())
  57. );
  58. return $resultRedirect;
  59. }
  60. $this->registry->register('shared_wishlist', $wishlist);
  61. /** @var \Magento\Framework\View\Result\Page $resultPage */
  62. $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
  63. return $resultPage;
  64. }
  65. }