1

I'm using magento 2.2.5 and i have a custom database table which contain customer_id, i want all the customer in this custom table won't be shown at magento2 admin customer grid.

my custom table example structure:

+-------------+
|hero_customer|
+-------------+
+----------------------------------------------------------+
| customer_id | skill_id | level | created_at | updated_at |
+----------------------------------------------------------+
|      7      |     2    |   7   | 2017-09-11 | 2018-10-11 |
|      12     |     8    |   13  | 2018-01-18 | 2018-09-01 |
|      18     |     11   |   1   | 2018-10-03 | 2018-10-10 |
+----------------------------------------------------------+
-1

Hey I think you can get all customer data by loading customer collection like:

 class MyClass 
    {
        protected $_customer;
        protected $_customerFactory;

        public function __construct(...
               \Magento\Customer\Model\CustomerFactory $customerFactory,
               \Magento\Customer\Model\Customer $customers
        )
        {
            ...
            $this->_customerFactory = $customerFactory;
            $this->_customer = $customers;
        }

        public function getCustomerCollection() {
            return $this->_customer->getCollection()
                   ->addAttributeToSelect("*")
                   ->load();
        }

        public function getFilteredCustomerCollection() {
            return $this->_customerFactory->create()->getCollection()
                    ->addAttributeToSelect("*")
                    ->addAttributeToFilter("id", array("eq" => "Max"))
                    -load();
        }
        }

By loading customer collection you can get the whole customer and adding the filter on that collection you can get customer specific data too.

If you find this answer helpful mark it as solution thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.