config = $config; $this->ordersFactory = $ordersFactory; } /** * Reports orders placed to the database reporting_orders table * * @param Observer $observer * @return void */ public function execute(Observer $observer) { if ($this->config->isNewRelicEnabled()) { /** @var \Magento\Sales\Model\Order $order */ $order = $observer->getEvent()->getOrder(); $itemCount = $order->getTotalItemCount(); if (!is_numeric($itemCount) && empty($itemCount)) { $itemCount = $order->getTotalQtyOrdered(); } $modelData = [ 'customer_id' => $order->getCustomerId(), 'total' => $order->getGrandTotal(), 'total_base' => $order->getBaseGrandTotal(), 'item_count' => $itemCount, ]; /** @var \Magento\NewRelicReporting\Model\Orders $orderModel */ $orderModel = $this->ordersFactory->create(); $orderModel->setData($modelData); $orderModel->save(); } } }