1

I'm getting a strange error after filtering through customerFactory.

Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid attribute name: is_active.

private function getCustomerDetails()
{
    $collection = $this->_customerFactory->create()->getCollection()
        ->addFieldToSelect('*')
        ->addAttributeToFilter('is_active', array('eq'=>'1'));
    return $collection->getSelect();
}

If I replace is_active with something else (e.g. lastname) then it works just fine. I googled a lot, but could not find a solution to this problem.

Any ideas :?

  • I think you need addFieldToFilter(''is_active',1) I think this field don't EAV – Naumov Jul 6 '16 at 16:28
0

You get an error because the is_active attribute does not exist for customers in Magento2.
There is a column is_active on the customer_entity table, but if you don't have an attribute with the same code and type static you cannot use that attribute for filtering.

To understand better what I'm saying here is an example.
There is a column called lastname in the customer_entity tablebut there is also an attribute with type static called lastname.
That's why filtering by lastname` works.
From my point of view, you just found a bug, or at least an inconsistency and you should report it here.

0

is_active is not an attribute which available to add to select, or filter. You are still able to have a workaround for this problem by:

private function getCustomerDetails()
{
    $collection = $this->_customerFactory->create()->getCollection()
        ->addFieldToSelect('*');
    $collection->getSelect()->where('is_active = ?', 1);
    return $collection->getSelect();
}

Hope this help

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.