Discounts.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SalesRule\Model\Rss;
  7. /**
  8. * Class Discounts
  9. * @package Magento\SalesRule\Model\Rss
  10. */
  11. class Discounts
  12. {
  13. /**
  14. * @var \Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory
  15. */
  16. protected $collectionFactory;
  17. /**
  18. * @var \Magento\Framework\Stdlib\DateTime
  19. */
  20. protected $dateTime;
  21. /**
  22. * @param \Magento\Framework\Stdlib\DateTime $dateTime
  23. * @param \Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory $collectionFactory
  24. */
  25. public function __construct(
  26. \Magento\Framework\Stdlib\DateTime $dateTime,
  27. \Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory $collectionFactory
  28. ) {
  29. $this->dateTime = $dateTime;
  30. $this->collectionFactory = $collectionFactory;
  31. }
  32. /**
  33. * @param int $websiteId
  34. * @param int $customerGroupId
  35. * @return \Magento\SalesRule\Model\ResourceModel\Rule\Collection
  36. */
  37. public function getDiscountCollection($websiteId, $customerGroupId)
  38. {
  39. /** @var $collection \Magento\SalesRule\Model\ResourceModel\Rule\Collection */
  40. $collection = $this->collectionFactory->create();
  41. $collection->addWebsiteGroupDateFilter(
  42. $websiteId,
  43. $customerGroupId,
  44. (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)
  45. )
  46. ->addFieldToFilter('is_rss', 1)
  47. ->setOrder('from_date', 'desc');
  48. $collection->load();
  49. return $collection;
  50. }
  51. }