Collection.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\ResourceModel\Order\Creditmemo;
  7. use Magento\Sales\Api\Data\CreditmemoSearchResultInterface;
  8. use Magento\Sales\Model\ResourceModel\Order\Collection\AbstractCollection;
  9. /**
  10. * Flat sales order creditmemo collection
  11. *
  12. * @api
  13. * @author Magento Core Team <core@magentocommerce.com>
  14. * @since 100.0.2
  15. */
  16. class Collection extends AbstractCollection implements CreditmemoSearchResultInterface
  17. {
  18. /**
  19. * Id field name
  20. *
  21. * @var string
  22. */
  23. protected $_idFieldName = 'entity_id';
  24. /**
  25. * Event prefix
  26. *
  27. * @var string
  28. */
  29. protected $_eventPrefix = 'sales_order_creditmemo_collection';
  30. /**
  31. * Event object
  32. *
  33. * @var string
  34. */
  35. protected $_eventObject = 'order_creditmemo_collection';
  36. /**
  37. * Order field for setOrderFilter
  38. *
  39. * @var string
  40. */
  41. protected $_orderField = 'order_id';
  42. /**
  43. * Model initialization
  44. *
  45. * @return void
  46. */
  47. protected function _construct()
  48. {
  49. $this->_init(
  50. \Magento\Sales\Model\Order\Creditmemo::class,
  51. \Magento\Sales\Model\ResourceModel\Order\Creditmemo::class
  52. );
  53. }
  54. /**
  55. * Used to emulate after load functionality for each item without loading them
  56. *
  57. * @return $this
  58. */
  59. protected function _afterLoad()
  60. {
  61. $this->walk('afterLoad');
  62. return $this;
  63. }
  64. /**
  65. * Add filtration conditions
  66. *
  67. * @param array|null $filter
  68. * @return $this
  69. */
  70. public function getFiltered($filter = null)
  71. {
  72. if (is_array($filter)) {
  73. foreach ($filter as $field => $value) {
  74. $this->addFieldToFilter($field, $value);
  75. }
  76. }
  77. return $this;
  78. }
  79. }