Collection.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Model\ResourceModel\Group;
  7. /**
  8. * Customer group collection
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  13. {
  14. /**
  15. * @var string
  16. */
  17. protected $_idFieldName = 'customer_group_id';
  18. /**
  19. * Resource initialization
  20. *
  21. * @return void
  22. */
  23. protected function _construct()
  24. {
  25. $this->_init(\Magento\Customer\Model\Group::class, \Magento\Customer\Model\ResourceModel\Group::class);
  26. }
  27. /**
  28. * Set ignore ID filter
  29. *
  30. * @param array $indexes
  31. * @return $this
  32. */
  33. public function setIgnoreIdFilter($indexes)
  34. {
  35. if (count($indexes)) {
  36. $this->addFieldToFilter('main_table.customer_group_id', ['nin' => $indexes]);
  37. }
  38. return $this;
  39. }
  40. /**
  41. * Set real groups filter
  42. *
  43. * @return $this
  44. */
  45. public function setRealGroupsFilter()
  46. {
  47. return $this->addFieldToFilter('customer_group_id', ['gt' => 0]);
  48. }
  49. /**
  50. * Add tax class
  51. *
  52. * @return $this
  53. */
  54. public function addTaxClass()
  55. {
  56. $this->getSelect()->joinLeft(
  57. ['tax_class_table' => $this->getTable('tax_class')],
  58. "main_table.tax_class_id = tax_class_table.class_id"
  59. );
  60. return $this;
  61. }
  62. /**
  63. * Retrieve option array
  64. *
  65. * @return array
  66. */
  67. public function toOptionArray()
  68. {
  69. return parent::_toOptionArray('customer_group_id', 'customer_group_code');
  70. }
  71. /**
  72. * Retrieve option hash
  73. *
  74. * @return array
  75. */
  76. public function toOptionHash()
  77. {
  78. return parent::_toOptionHash('customer_group_id', 'customer_group_code');
  79. }
  80. }