Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
WishlistProvider.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
16  protected $wishlist;
17 
21  protected $wishlistFactory;
22 
26  protected $customerSession;
27 
31  protected $messageManager;
32 
36  protected $request;
37 
44  public function __construct(
45  \Magento\Wishlist\Model\WishlistFactory $wishlistFactory,
46  \Magento\Customer\Model\Session $customerSession,
47  \Magento\Framework\Message\ManagerInterface $messageManager,
49  ) {
50  $this->request = $request;
51  $this->wishlistFactory = $wishlistFactory;
52  $this->customerSession = $customerSession;
53  $this->messageManager = $messageManager;
54  }
55 
60  public function getWishlist($wishlistId = null)
61  {
62  if ($this->wishlist) {
63  return $this->wishlist;
64  }
65  try {
66  if (!$wishlistId) {
67  $wishlistId = $this->request->getParam('wishlist_id');
68  }
69  $customerId = $this->customerSession->getCustomerId();
70  $wishlist = $this->wishlistFactory->create();
71 
72  if (!$wishlistId && !$customerId) {
73  return $wishlist;
74  }
75 
76  if ($wishlistId) {
77  $wishlist->load($wishlistId);
78  } elseif ($customerId) {
79  $wishlist->loadByCustomerId($customerId, true);
80  }
81 
82  if (!$wishlist->getId() || $wishlist->getCustomerId() != $customerId) {
83  throw new \Magento\Framework\Exception\NoSuchEntityException(
84  __('The requested Wish List doesn\'t exist.')
85  );
86  }
87  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
88  $this->messageManager->addError($e->getMessage());
89  return false;
90  } catch (\Exception $e) {
91  $this->messageManager->addException($e, __('We can\'t create the Wish List right now.'));
92  return false;
93  }
94  $this->wishlist = $wishlist;
95  return $wishlist;
96  }
97 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(\Magento\Wishlist\Model\WishlistFactory $wishlistFactory, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Message\ManagerInterface $messageManager, RequestInterface $request)
__()
Definition: __.php:13