Push.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Dotdigitalgroup\Email\Block\Recommended;
  3. /**
  4. * Push block
  5. *
  6. * @api
  7. */
  8. class Push 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 \Dotdigitalgroup\Email\Helper\Recommended
  20. */
  21. public $recommnededHelper;
  22. /**
  23. * @var \Dotdigitalgroup\Email\Model\ResourceModel\Catalog
  24. */
  25. public $catalog;
  26. /**
  27. * Push constructor.
  28. *
  29. * @param \Magento\Catalog\Block\Product\Context $context
  30. * @param \Dotdigitalgroup\Email\Model\ResourceModel\Catalog $catalog
  31. * @param \Dotdigitalgroup\Email\Helper\Data $helper
  32. * @param \Magento\Framework\Pricing\Helper\Data $priceHelper
  33. * @param \Dotdigitalgroup\Email\Helper\Recommended $recommended
  34. * @param array $data
  35. */
  36. public function __construct(
  37. \Magento\Catalog\Block\Product\Context $context,
  38. \Dotdigitalgroup\Email\Model\ResourceModel\Catalog $catalog,
  39. \Dotdigitalgroup\Email\Helper\Data $helper,
  40. \Magento\Framework\Pricing\Helper\Data $priceHelper,
  41. \Dotdigitalgroup\Email\Helper\Recommended $recommended,
  42. array $data = []
  43. ) {
  44. parent::__construct($context, $data);
  45. $this->helper = $helper;
  46. $this->catalog = $catalog;
  47. $this->recommnededHelper = $recommended;
  48. $this->priceHelper = $priceHelper;
  49. }
  50. /**
  51. * Get the products to display for table.
  52. *
  53. * @return array|\Magento\Catalog\Model\ResourceModel\Product\Collection
  54. */
  55. public function getLoadedProductCollection()
  56. {
  57. $params = $this->getRequest()->getParams();
  58. if (! isset($params['code']) || ! $this->helper->isCodeValid($params['code'])) {
  59. $this->helper->log('Product push no valid code is set');
  60. return [];
  61. }
  62. $mode = $this->getRequest()->getActionName();
  63. $limit = $this->recommnededHelper->getDisplayLimitByMode($mode);
  64. $productIds = $this->recommnededHelper->getProductPushIds();
  65. $productCollection = $this->catalog->getProductCollectionFromIds($productIds, $limit);
  66. //important check the salable product in template
  67. return $productCollection;
  68. }
  69. /**
  70. * Display type mode.
  71. *
  72. * @return boolean|string
  73. */
  74. public function getMode()
  75. {
  76. return $this->recommnededHelper->getDisplayType();
  77. }
  78. /**
  79. * @param null|string|bool|int|\Magento\Store\Api\Data\StoreInterface $store
  80. *
  81. * @return string|boolean
  82. */
  83. public function getTextForUrl($store)
  84. {
  85. /** @var \Magento\Store\Model\Store $store */
  86. $store = $this->_storeManager->getStore($store);
  87. return $store->getConfig(
  88. \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_DYNAMIC_CONTENT_LINK_TEXT
  89. );
  90. }
  91. }