Rss.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Wishlist\Helper;
  7. /**
  8. * Wishlist rss helper
  9. *
  10. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  11. *
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class Rss extends \Magento\Wishlist\Helper\Data
  16. {
  17. /**
  18. * @var \Magento\Customer\Api\Data\CustomerInterface
  19. */
  20. protected $_customer;
  21. /**
  22. * @var \Magento\Customer\Api\Data\CustomerInterfaceFactory
  23. */
  24. protected $_customerFactory;
  25. /**
  26. * @var \Magento\Customer\Api\CustomerRepositoryInterface
  27. */
  28. protected $_customerRepository;
  29. /**
  30. * @param \Magento\Framework\App\Helper\Context $context
  31. * @param \Magento\Framework\Registry $coreRegistry
  32. * @param \Magento\Customer\Model\Session $customerSession
  33. * @param \Magento\Wishlist\Model\WishlistFactory $wishlistFactory
  34. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  35. * @param \Magento\Framework\Data\Helper\PostHelper $postDataHelper
  36. * @param \Magento\Customer\Helper\View $customerViewHelper
  37. * @param \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider
  38. * @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
  39. * @param \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory
  40. * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
  41. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  42. */
  43. public function __construct(
  44. \Magento\Framework\App\Helper\Context $context,
  45. \Magento\Framework\Registry $coreRegistry,
  46. \Magento\Customer\Model\Session $customerSession,
  47. \Magento\Wishlist\Model\WishlistFactory $wishlistFactory,
  48. \Magento\Store\Model\StoreManagerInterface $storeManager,
  49. \Magento\Framework\Data\Helper\PostHelper $postDataHelper,
  50. \Magento\Customer\Helper\View $customerViewHelper,
  51. \Magento\Wishlist\Controller\WishlistProviderInterface $wishlistProvider,
  52. \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
  53. \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory,
  54. \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
  55. ) {
  56. $this->_customerFactory = $customerFactory;
  57. $this->_customerRepository = $customerRepository;
  58. parent::__construct(
  59. $context,
  60. $coreRegistry,
  61. $customerSession,
  62. $wishlistFactory,
  63. $storeManager,
  64. $postDataHelper,
  65. $customerViewHelper,
  66. $wishlistProvider,
  67. $productRepository
  68. );
  69. }
  70. /**
  71. * Retrieve Wishlist model
  72. *
  73. * @return \Magento\Wishlist\Model\Wishlist
  74. */
  75. public function getWishlist()
  76. {
  77. if ($this->_wishlist === null) {
  78. $this->_wishlist = $this->_wishlistFactory->create();
  79. $wishlistId = $this->_getRequest()->getParam('wishlist_id');
  80. if ($wishlistId) {
  81. $this->_wishlist->load($wishlistId);
  82. } else {
  83. if ($this->getCustomer()->getId()) {
  84. $this->_wishlist->loadByCustomerId($this->getCustomer()->getId());
  85. }
  86. }
  87. }
  88. return $this->_wishlist;
  89. }
  90. /**
  91. * Retrieve Customer instance
  92. *
  93. * @return \Magento\Customer\Api\Data\CustomerInterface
  94. */
  95. public function getCustomer()
  96. {
  97. if ($this->_customer === null) {
  98. $params = $this->urlDecoder->decode($this->_getRequest()->getParam('data'));
  99. $data = explode(',', $params);
  100. $customerId = abs((int)$data[0]);
  101. if ($customerId && ($customerId == $this->_customerSession->getCustomerId())) {
  102. $this->_customer = $this->_customerRepository->getById($customerId);
  103. } else {
  104. $this->_customer = $this->_customerFactory->create();
  105. }
  106. }
  107. return $this->_customer;
  108. }
  109. /**
  110. * Is allow RSS
  111. *
  112. * @return bool
  113. */
  114. public function isRssAllow()
  115. {
  116. return $this->_moduleManager->isEnabled('Magento_Rss')
  117. && $this->scopeConfig->isSetFlag(
  118. 'rss/wishlist/active',
  119. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  120. );
  121. }
  122. }