WishlistProvider.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Wishlist\Controller\Shared;
  8. use Magento\Wishlist\Controller\WishlistProviderInterface;
  9. class WishlistProvider implements WishlistProviderInterface
  10. {
  11. /**
  12. * @var \Magento\Framework\App\RequestInterface
  13. */
  14. protected $request;
  15. /**
  16. * @var \Magento\Wishlist\Model\WishlistFactory
  17. */
  18. protected $wishlistFactory;
  19. /**
  20. * @var \Magento\Checkout\Model\Session
  21. */
  22. protected $checkoutSession;
  23. /**
  24. * @var \Magento\Wishlist\Model\Wishlist
  25. */
  26. protected $wishlist;
  27. /**
  28. * @param \Magento\Framework\App\RequestInterface $request
  29. * @param \Magento\Wishlist\Model\WishlistFactory $wishlistFactory
  30. * @param \Magento\Checkout\Model\Session $checkoutSession
  31. */
  32. public function __construct(
  33. \Magento\Framework\App\RequestInterface $request,
  34. \Magento\Wishlist\Model\WishlistFactory $wishlistFactory,
  35. \Magento\Checkout\Model\Session $checkoutSession
  36. ) {
  37. $this->request = $request;
  38. $this->wishlistFactory = $wishlistFactory;
  39. $this->checkoutSession = $checkoutSession;
  40. }
  41. /**
  42. * Retrieve current wishlist
  43. * @param string $wishlistId
  44. * @return \Magento\Wishlist\Model\Wishlist
  45. */
  46. public function getWishlist($wishlistId = null)
  47. {
  48. if ($this->wishlist) {
  49. return $this->wishlist;
  50. }
  51. $code = (string)$this->request->getParam('code');
  52. if (empty($code)) {
  53. return false;
  54. }
  55. $wishlist = $this->wishlistFactory->create()->loadByCode($code);
  56. if (!$wishlist->getId()) {
  57. return false;
  58. }
  59. $this->checkoutSession->setSharedWishlist($code);
  60. $this->wishlist = $wishlist;
  61. return $wishlist;
  62. }
  63. }