Wishlist.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace Dotdigitalgroup\Email\Block;
  3. /**
  4. * Wishlist block
  5. *
  6. * @api
  7. */
  8. class Wishlist extends \Magento\Catalog\Block\Product\AbstractProduct
  9. {
  10. /**
  11. * @var \Dotdigitalgroup\Email\Helper\Data
  12. */
  13. public $helper;
  14. /**
  15. * @var \Magento\Framework\Pricing\Helper\Data
  16. */
  17. public $priceHelper;
  18. /**
  19. * @var \Magento\Customer\Model\CustomerFactory
  20. */
  21. public $customerFactory;
  22. /**
  23. * @var \Dotdigitalgroup\Email\Model\ResourceModel\Wishlist
  24. */
  25. public $wishlist;
  26. /**
  27. * @var \Magento\Customer\Model\ResourceModel\Customer
  28. */
  29. private $customerResource;
  30. /**
  31. * Wishlist constructor.
  32. *
  33. * @param \Magento\Catalog\Block\Product\Context $context
  34. * @param \Magento\Customer\Model\ResourceModel\Customer $customerResource
  35. * @param \Dotdigitalgroup\Email\Model\ResourceModel\Wishlist $wishlist
  36. * @param \Magento\Customer\Model\CustomerFactory $customerFactory
  37. * @param \Dotdigitalgroup\Email\Helper\Data $helper
  38. * @param \Magento\Framework\Pricing\Helper\Data $priceHelper
  39. * @param array $data
  40. */
  41. public function __construct(
  42. \Magento\Catalog\Block\Product\Context $context,
  43. \Magento\Customer\Model\ResourceModel\Customer $customerResource,
  44. \Dotdigitalgroup\Email\Model\ResourceModel\Wishlist $wishlist,
  45. \Magento\Customer\Model\CustomerFactory $customerFactory,
  46. \Dotdigitalgroup\Email\Helper\Data $helper,
  47. \Magento\Framework\Pricing\Helper\Data $priceHelper,
  48. array $data = []
  49. ) {
  50. parent::__construct($context, $data);
  51. $this->wishlist = $wishlist;
  52. $this->customerFactory = $customerFactory;
  53. $this->helper = $helper;
  54. $this->priceHelper = $priceHelper;
  55. $this->customerResource = $customerResource;
  56. }
  57. /**
  58. * Get wishlist items.
  59. *
  60. * @return boolean|\Magento\Wishlist\Model\ResourceModel\Item\Collection
  61. */
  62. public function getWishlistItems()
  63. {
  64. $wishlist = $this->_getWishlist();
  65. if ($wishlist && ! empty($wishlist->getItemCollection())) {
  66. return $wishlist->getItemCollection();
  67. } else {
  68. return false;
  69. }
  70. }
  71. /**
  72. * @return bool|\Magento\Framework\DataObject
  73. */
  74. public function _getWishlist()
  75. {
  76. $params = $this->getRequest()->getParams();
  77. if (! $params['customer_id'] ||
  78. ! isset($params['code']) ||
  79. ! $this->helper->isCodeValid($params['code'])
  80. ) {
  81. $this->helper->log('Wishlist no id or valid code is set');
  82. return false;
  83. }
  84. $customerId = (int) $params['customer_id'];
  85. $customer = $this->customerFactory->create();
  86. $this->customerResource->load($customer, $customerId);
  87. if (! $customer->getId()) {
  88. return false;
  89. }
  90. return $this->wishlist->getWishlistsForCustomer($customerId);
  91. }
  92. /**
  93. * Wishlist display mode type.
  94. *
  95. * @return string|boolean
  96. */
  97. public function getMode()
  98. {
  99. return $this->helper->getWebsiteConfig(
  100. \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_WIHSLIST_DISPLAY
  101. );
  102. }
  103. /**
  104. * Product url.
  105. *
  106. * @param null|string|bool|int|\Magento\Store\Api\Data\StoreInterface $store
  107. *
  108. * @return boolean|string
  109. */
  110. public function getTextForUrl($store)
  111. {
  112. /** @var \Magento\Store\Model\Store $store */
  113. $store = $this->_storeManager->getStore($store);
  114. return $store->getConfig(
  115. \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_LINK_TEXT
  116. );
  117. }
  118. }