Closed
Description
I have custom EAV attributes named "company" for customers, but this is not loaded if I use the CustomerRepository::getList()
-method. Other custom attributes seem to be loaded properly.
Preconditions
- Magento 2.2.5
Steps to reproduce
- Create customer EAV attribute named "company" (varchar)
- Populate it with some data
- Load it with
CustomerRepository::get() / getById()
- Load it with
CustomerRepository::getList()
Expected result
In both the situations, $customer->getCustomAttribute('company')->getValue()
should return the value defined for this attribute.
Actual result
The get()
/ getById()
-method loads the proper value, getList()
returns NULL
.
Possible cause
My best guess is that it has something to do with the fact that getList()
joins the customer address that also has a company
-column:
$collection->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
->joinAttribute('company', 'customer_address/company', 'default_billing', null, 'left');
Possible solution
I can think of 2 solutions:
- Throw an exception that
company
(or whatever other joined attributed) is a reserved keyword. - Allow the customer model to override the address attributes (order of loading)
Workaround
I currently have to do the following workaround (in my situation, my search criteria always returns 1 customer):
$customers = $customerSearchResult->getItems();
return $this->customerRepository->getById($customers[0]->getId());
Metadata
Metadata
Assignees
Labels
The issue has been fixed in 2.2 release lineThe issue has been fixed in 2.3 release lineGate 2 Passed. Manual verification of the issue description passedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentThe issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.3 release