AbstractCollection.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\ResourceModel\Report\Collection;
  7. /**
  8. * Report collection abstract model
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class AbstractCollection extends \Magento\Reports\Model\ResourceModel\Report\Collection\AbstractCollection
  13. {
  14. /**
  15. * Order status
  16. *
  17. * @var string
  18. */
  19. protected $_orderStatus = null;
  20. /**
  21. * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  22. * @param \Psr\Log\LoggerInterface $logger
  23. * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  24. * @param \Magento\Framework\Event\ManagerInterface $eventManager
  25. * @param \Magento\Sales\Model\ResourceModel\Report $resource
  26. * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
  27. */
  28. public function __construct(
  29. \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
  30. \Psr\Log\LoggerInterface $logger,
  31. \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
  32. \Magento\Framework\Event\ManagerInterface $eventManager,
  33. \Magento\Sales\Model\ResourceModel\Report $resource,
  34. \Magento\Framework\DB\Adapter\AdapterInterface $connection = null
  35. ) {
  36. parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
  37. $this->setModel(\Magento\Reports\Model\Item::class);
  38. }
  39. /**
  40. * Set status filter
  41. *
  42. * @param string $orderStatus
  43. * @return $this
  44. */
  45. public function addOrderStatusFilter($orderStatus)
  46. {
  47. $this->_orderStatus = $orderStatus;
  48. return $this;
  49. }
  50. /**
  51. * Apply order status filter
  52. *
  53. * @return $this
  54. */
  55. protected function _applyOrderStatusFilter()
  56. {
  57. if ($this->_orderStatus === null) {
  58. return $this;
  59. }
  60. $orderStatus = $this->_orderStatus;
  61. if (!is_array($orderStatus)) {
  62. $orderStatus = [$orderStatus];
  63. }
  64. $this->getSelect()->where('order_status IN(?)', $orderStatus);
  65. return $this;
  66. }
  67. /**
  68. * Order status filter is custom for this collection
  69. *
  70. * @return $this
  71. */
  72. protected function _applyCustomFilter()
  73. {
  74. return $this->_applyOrderStatusFilter();
  75. }
  76. }