config = $config; $this->customerSession = $customerSession; $this->customerRepository = $customerRepository; $this->storeManager = $storeManager; $this->usersFactory = $usersFactory; $this->jsonEncoder = $jsonEncoder; } /** * Reports concurrent users to the database reporting_users table * * @param Observer $observer * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { if ($this->customerSession->isLoggedIn()) { $customer = $this->customerRepository->getById($this->customerSession->getCustomerId()); $jsonData = [ 'id' => $customer->getId(), 'name' => $customer->getFirstname() . ' ' . $customer->getLastname(), 'store' => $this->storeManager->getStore()->getName(), 'website' => $this->storeManager->getWebsite()->getName(), ]; $modelData = [ 'type' => 'user_action', 'action' => $this->jsonEncoder->encode($jsonData), ]; /** @var \Magento\NewRelicReporting\Model\Users $usersModel */ $usersModel = $this->usersFactory->create(); $usersModel->setData($modelData); $usersModel->save(); } } } }