Skip to content

Commit

Permalink
version 0.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fryckbos committed Aug 1, 2016
1 parent fa679f6 commit ad2fcdd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
64 changes: 54 additions & 10 deletions app/code/community/CoScale/Monitor/Model/Metric/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions app/code/community/CoScale/Monitor/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<CoScale_Monitor>
<version>0.15.0</version>
<version>0.16.0</version>
</CoScale_Monitor>
</modules>
<global>
Expand Down Expand Up @@ -133,14 +133,14 @@
</coscale_monitor_metric_order_add>
</observers>
</sales_order_place_after>
<sales_order_save_commit_after>
<sales_order_save_after>
<observers>
<coscale_monitor_metric_order_save>
<class>coscale_monitor/metric_order</class>
<method>salesOrderSaveCommitAfter</method>
<method>salesOrderSaveAfter</method>
</coscale_monitor_metric_order_save>
</observers>
</sales_order_save_commit_after>
</sales_order_save_after>

<controller_action_predispatch_adminhtml_process_massReindex>
<observers>
Expand Down Expand Up @@ -269,6 +269,7 @@
<state_new_key>new</state_new_key>
<state_processing_key>processing</state_processing_key>
<state_completed_key>complete</state_completed_key>
<state_canceled_key>canceled</state_canceled_key>
<status_pickpack_pending_key>pending</status_pickpack_pending_key>
<status_pickpack_key>processing</status_pickpack_key>
<status_pickpack_completed_key>complete</status_pickpack_completed_key>
Expand Down

0 comments on commit ad2fcdd

Please sign in to comment.