I’m trying to pull a customers collection but i need to join it to their billing address details to add filters.
The only info i can find so far seems to be for Magento 1, such as this: Magento join customer collection with customer address
I have tried similar but joinAttribute() doesn’t seem to be present in Magento 2, all i get is join() which expects me to give it the table name, so for example i have this:
/** @var AbstractCollection $customers */
$customers = $this->customerCollection->getCollection()
->setCurPage($page)
->setPageSize($pageSize)
->setOrder($orderBy,$order);
I’m not sure how to now join this to their billing address since it’s across multiple tables, do i need to join all the relevant tables or is there another way in magento to do it?
I have tried the following but i can an error saying “The “billing_telephone” attribute name is invalid. Reset the name and try again.”
$customers->getSelect()->joinLeft(
['address'=>'customer_address_entity'],
'e.default_billing = address.entity_id'
);
$customers->addFilterToMap('billing_telephone','address.telephone');
$customers->addFieldToFilter('billing_telephone',[
'like'=>'%077%'
]);