Skip to content

M2.2.5 : CustomerRepository::getList() does not load custom attribute if the name is "company" #17759

Closed
@kanduvisla

Description

@kanduvisla

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

  1. Magento 2.2.5

Steps to reproduce

  1. Create customer EAV attribute named "company" (varchar)
  2. Populate it with some data
  3. Load it with CustomerRepository::get() / getById()
  4. 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

Labels

Component: CustomerEvent: mageconfEvent: mm18mxFixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseup for grabs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions