سؤال

I am trying to join customer entity table and customer address entity table. I am getting error in below code. What could be the issue

        $agency_name=$customerData->getDefaultShippingAddress()->getAgencyName();
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();


        $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
        $customerTable = $resource->getTableName('customer_entity');

$customerObj = $objectManager->create('Magento\Customer\Model\ResourceModel\Address\Collection');
$collection = $customerObj
             ->addAttributeToSelect('agency_name', 'customer_address_entity')
              ->addAttributeToFilter('agency_name',array('eq'=>$agency_name));
              //->load();

              $collection->getSelect()->join(['ct'=>$customerTable],'main_table.parent_id=ct.entity_id',[]);

$c_data=$collection->getData();
print_r($c_data);

Giving me error.Please Help

هل كانت مفيدة؟

المحلول

The error is because the main_table does not exist. If you debug, you can see in

vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php

the line

$this->getConnection()->quoteIdentifier('e.' . $attribute),

You must use

$collection->getSelect()->join(['ct'=>$customerTable],'e.parent_id=ct.entity_id',[]);

After this, it is not advisable to use the object manager as you are using it. For that, you can use the independence injections of the classes

Magento\Framework\App\ResourceConnection

and

Magento\Customer\Model\ResourceModel\Address\Collection

directly in your construct.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top