customerSession = $customerSession; $this->baseCollectionFactory = $baseCollectionFactory; $this->labCollection = $labCollection; $this->salespersonCollection = $salespersonCollection; } public function getLabs(): Collection|ResourceModel\Lab\Collection { if ($this->customerSession->getCustomerId()) { $this->labCollection->addFieldToFilter('main_table.customer_id', $this->customerSession->getCustomerId()) ->getSelect() ->joinLeft('salesperson', 'salesperson.salesperson_id=main_table.salesperson_id', ['salesperson'=>'salesperson.name']); return $this->labCollection; } return $this->baseCollectionFactory->create()->setItemObjectClass(Lab::class); } /** * @return \Stemcell\Customer\Api\Data\LabInterface|Lab */ public function getLab() { try { if ($labId = $this->_item->getData('lab_id')) { /* @var $labRepository LabRepository */ $labRepository = \Magento\Framework\App\ObjectManager::getInstance()->get(LabRepository::class); /* @var $salespersonRepository SalespersonRepository */ $salespersonRepository = \Magento\Framework\App\ObjectManager::getInstance()->get(SalespersonRepository::class); $this->lab = $labRepository->get($labId); $salesperson = $salespersonRepository->get($this->lab->getSalespersonId()); $this->lab->setData('salesperson', $salesperson->getName()); return $this->lab; } } catch (LocalizedException $e) { } /* @var $labFactory LabFactory */ $labFactory = \Magento\Framework\App\ObjectManager::getInstance()->get(LabFactory::class); return $labFactory->create(); } public function getSalesperson() { if ($this->customerSession->getCustomerId()) { $this->salespersonCollection->addFieldToFilter('customer_id', $this->customerSession->getCustomerId()); return $this->salespersonCollection; } return $this->baseCollectionFactory->create()->setItemObjectClass(Salesperson::class); } }