Wishlist.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Wishlist block shared items
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Wishlist\Block\Share;
  12. /**
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Wishlist extends \Magento\Wishlist\Block\AbstractBlock
  17. {
  18. /**
  19. * Customer instance
  20. *
  21. * @var \Magento\Customer\Api\Data\CustomerInterface
  22. */
  23. protected $_customer = null;
  24. /**
  25. * @var \Magento\Customer\Api\CustomerRepositoryInterface
  26. */
  27. protected $customerRepository;
  28. /**
  29. * @param \Magento\Catalog\Block\Product\Context $context
  30. * @param \Magento\Framework\App\Http\Context $httpContext
  31. * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
  32. * @param array $data
  33. */
  34. public function __construct(
  35. \Magento\Catalog\Block\Product\Context $context,
  36. \Magento\Framework\App\Http\Context $httpContext,
  37. \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
  38. array $data = []
  39. ) {
  40. $this->customerRepository = $customerRepository;
  41. parent::__construct(
  42. $context,
  43. $httpContext,
  44. $data
  45. );
  46. }
  47. /**
  48. * Prepare global layout
  49. *
  50. * @return $this
  51. *
  52. */
  53. protected function _prepareLayout()
  54. {
  55. parent::_prepareLayout();
  56. $this->pageConfig->getTitle()->set($this->getHeader());
  57. return $this;
  58. }
  59. /**
  60. * Retrieve Shared Wishlist Customer instance
  61. *
  62. * @return \Magento\Customer\Api\Data\CustomerInterface
  63. */
  64. public function getWishlistCustomer()
  65. {
  66. if ($this->_customer === null) {
  67. $this->_customer = $this->customerRepository->getById($this->_getWishlist()->getCustomerId());
  68. }
  69. return $this->_customer;
  70. }
  71. /**
  72. * Retrieve Page Header
  73. *
  74. * @return \Magento\Framework\Phrase
  75. */
  76. public function getHeader()
  77. {
  78. return __("%1's Wish List", $this->escapeHtml($this->getWishlistCustomer()->getFirstname()));
  79. }
  80. }