From ad2fcddbfef23003412baea9635abcfeef69e1e2 Mon Sep 17 00:00:00 2001 From: fryckbos Date: Mon, 1 Aug 2016 14:32:34 +0200 Subject: [PATCH] version 0.16.0 --- .../CoScale/Monitor/Model/Metric/Order.php | 64 ++++++++++++++++--- .../community/CoScale/Monitor/etc/config.xml | 9 +-- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/app/code/community/CoScale/Monitor/Model/Metric/Order.php b/app/code/community/CoScale/Monitor/Model/Metric/Order.php index 9330ace..7398200 100644 --- a/app/code/community/CoScale/Monitor/Model/Metric/Order.php +++ b/app/code/community/CoScale/Monitor/Model/Metric/Order.php @@ -18,6 +18,7 @@ class CoScale_Monitor_Model_Metric_Order extends CoScale_Monitor_Model_Metric_Ab protected $stateNewKey = ''; protected $stateProcessingKey = ''; protected $stateCompletedKey = ''; + protected $stateCanceledKey = ''; protected $statusPendingPickPackKey = ''; protected $statusPickPackKey = ''; protected $statusCompletedPickPackKey = ''; @@ -51,6 +52,7 @@ class CoScale_Monitor_Model_Metric_Order extends CoScale_Monitor_Model_Metric_Ab const KEY_ORDER_STATE_NEW = 2030; const KEY_ORDER_STATE_PROCESSING = 2031; const KEY_ORDER_STATE_COMPLETED = 2032; + const KEY_ORDER_STATE_CANCELED = 2033; /** * Identifier for pick order and time calculation @@ -148,6 +150,12 @@ public function _contruct() 'unit' => 'orders' ); + $this->_metricData[self::KEY_ORDER_STATE_CANCELED] = array( + 'name' => 'Orders canceled', + 'description' => 'The total number of orders in canceled state', + 'unit' => 'orders' + ); + $this->_metricData[self::KEY_ORDER_STATE_PENDING_PICKPACK] = array( 'name' => 'Orders pending pick/pack', 'description' => 'The total number of orders in waiting for pick/pack state', @@ -219,6 +227,7 @@ public function _contruct() $this->stateNewKey = Mage::getStoreConfig('system/coscale_monitor/state_new_key'); $this->stateProcessingKey = Mage::getStoreConfig('system/coscale_monitor/state_processing_key'); $this->stateCompletedKey = Mage::getStoreConfig('system/coscale_monitor/state_completed_key'); + $this->stateCanceledKey = Mage::getStoreConfig('system/coscale_monitor/state_canceled_key'); $this->statusPendingPickPackKey = Mage::getStoreConfig('system/coscale_monitor/status_pickpack_pending_key'); $this->statusPickPackKey = Mage::getStoreConfig('system/coscale_monitor/status_pickpack_key'); $this->statusCompletedPickPackKey = Mage::getStoreConfig('system/coscale_monitor/status_pickpack_completed_key'); @@ -348,7 +357,7 @@ public function salesOrderPlaceAfter(Varien_Event_Observer $observer) * * @param Varien_Event_Observer $observer */ - public function salesOrderSaveCommitAfter(Varien_Event_Observer $observer) + public function salesOrderSaveAfter(Varien_Event_Observer $observer) { $keys = array(); if (!$this->_helper->isEnabled()) { @@ -380,6 +389,9 @@ public function salesOrderSaveCommitAfter(Varien_Event_Observer $observer) case Mage_Sales_Model_Order::STATE_COMPLETE: $keys[self::KEY_ORDER_STATE_COMPLETED] = 1; break; + case Mage_Sales_Model_Order::STATE_CANCELED: + $keys[self::KEY_ORDER_STATE_CANCELED] = 1; + break; } } @@ -547,9 +559,8 @@ public function initOrderData() 'items' => 'SUM(main_table.total_item_count)', 'store_id' => 'main_table.store_id', 'state' => 'main_table.state', - 'status' => 'main_table.status', 'count' => 'COUNT(*)')) - ->group(array('main_table.store_id','main_table.state','main_table.status')); + ->group(array('main_table.store_id','main_table.state')); $data = array(); foreach ($collection as $order) { @@ -564,26 +575,52 @@ public function initOrderData() 'new' => 0, 'processing' => 0, 'complete' => 0, - 'status_pending' => 0, - 'status_processing' => 0, - 'status_complete' => 0 ); } $data[$order->getStoreId()]['items'] += $order->getItems(); $data[$order->getStoreId()]['amount'] += $order->getAmount(); $data[$order->getStoreId()]['count'] += $order->getCount(); - if ($order->getState() == $this->stateNewKey) { + if ($order->getState() == Mage_Sales_Model_Order::STATE_NEW) { $data[$order->getStoreId()]['new'] += $order->getCount(); } - if ($order->getState() == $this->stateProcessingKey) { + if ($order->getState() == Mage_Sales_Model_Order::STATE_PROCESSING) { $data[$order->getStoreId()]['processing'] += $order->getCount(); } - if ($order->getState() == $this->statusCompletedKey) { + if ($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE) { $data[$order->getStoreId()]['complete'] += $order->getCount(); } + if ($order->getState() == Mage_Sales_Model_Order::STATE_CANCELED) { + $data[$order->getStoreId()]['canceled'] += $order->getCount(); + } + + if ($order->getState() == Mage_Sales_Model_Order::STATE_HOLDED) { + $data[$order->getStoreId()]['holded'] += $order->getCount(); + } + } + $status_collection = Mage::getResourceModel('sales/order_collection'); + if (!is_object($status_collection)) { + return; + } + $status_collection->getSelect() + ->reset('columns') + ->columns(array('store_id' => 'main_table.store_id', + 'status' => 'main_table.status', + 'count' => 'COUNT(*)')) + ->group(array('main_table.store_id','main_table.status')); + foreach ($status_collection as $order) { + if (!$order->getStoreId()) { + continue; + } + if (!isset($data[$order->getStoreId()])) { + $data[$order->getStoreId()] = array( + 'status_pending' => 0, + 'status_processing' => 0, + 'status_complete' => 0 + ); + } if ($order->getStatus() == $this->statusPendingPickPackKey) { $data[$order->getStoreId()]['status_pending'] += $order->getCount(); } @@ -643,6 +680,13 @@ public function initOrderData() $details['complete'] ); + $this->setMetric( + self::ACTION_UPDATE, + self::KEY_ORDER_STATE_CANCELED, + $storeId, + $details['canceled'] + ); + $this->setMetric( self::ACTION_UPDATE, self::KEY_ORDER_STATE_PENDING_PICKPACK, @@ -735,7 +779,7 @@ public function getAbandonnedCarts() $collection->getSelect() ->columns(array('store_id' => 'main_table.store_id', 'count' => 'COUNT(*)', - 'subtotal' => 'subtotal')) + 'subtotal' => 'SUM(subtotal)')) ->group('main_table.store_id'); $output = array(); foreach ($collection as $order) { diff --git a/app/code/community/CoScale/Monitor/etc/config.xml b/app/code/community/CoScale/Monitor/etc/config.xml index 671e67c..c8c5545 100644 --- a/app/code/community/CoScale/Monitor/etc/config.xml +++ b/app/code/community/CoScale/Monitor/etc/config.xml @@ -2,7 +2,7 @@ - 0.15.0 + 0.16.0 @@ -133,14 +133,14 @@ - + coscale_monitor/metric_order - salesOrderSaveCommitAfter + salesOrderSaveAfter - + @@ -269,6 +269,7 @@ new processing complete + canceled pending processing complete