From b028d2aa4eadf9827eca4c2cb452e20bd2894e5d Mon Sep 17 00:00:00 2001 From: fryckbos Date: Mon, 1 Aug 2016 14:31:59 +0200 Subject: [PATCH] version $VERSION --- .../community/CoScale/Monitor/Helper/Data.php | 2 +- .../CoScale/Monitor/Model/Cronjob.php | 1 + .../CoScale/Monitor/Model/Metric/Order.php | 33 +++++++++++++++---- .../community/CoScale/Monitor/etc/config.xml | 2 +- .../upgrade-0.14.0-0.15.0.php | 21 ++++++++++++ 5 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.14.0-0.15.0.php diff --git a/app/code/community/CoScale/Monitor/Helper/Data.php b/app/code/community/CoScale/Monitor/Helper/Data.php index e71437f..13de009 100644 --- a/app/code/community/CoScale/Monitor/Helper/Data.php +++ b/app/code/community/CoScale/Monitor/Helper/Data.php @@ -29,7 +29,7 @@ public function isEnabled() foreach ($tables as $id => $data) { $metricTable = $resource->getTableName($data['table']); - if (! $connection->isTableExists(Mage::getConfig()->getTablePrefix().$metricTable)) { + if (! $connection->isTableExists($metricTable)) { $this->debugEndError('Module checking', new Exception('Table ' . $metricTable . ' not found!')); return false; } diff --git a/app/code/community/CoScale/Monitor/Model/Cronjob.php b/app/code/community/CoScale/Monitor/Model/Cronjob.php index 6779314..6cddc43 100644 --- a/app/code/community/CoScale/Monitor/Model/Cronjob.php +++ b/app/code/community/CoScale/Monitor/Model/Cronjob.php @@ -19,5 +19,6 @@ public function dailyCron() // Customer metric data Mage::getSingleton('coscale_monitor/metric_customer')->dailyCron(); Mage::getSingleton('coscale_monitor/metric_product')->dailyCron(); + Mage::getSingleton('coscale_monitor/metric_order')->dailyCron(); } } \ No newline at end of file diff --git a/app/code/community/CoScale/Monitor/Model/Metric/Order.php b/app/code/community/CoScale/Monitor/Model/Metric/Order.php index e21cf6b..9330ace 100644 --- a/app/code/community/CoScale/Monitor/Model/Metric/Order.php +++ b/app/code/community/CoScale/Monitor/Model/Metric/Order.php @@ -261,16 +261,21 @@ public function initDefaultMetrics($storeId) self::KEY_TIME_CURRENT_PICKPACK, ); + $amountUnit = Mage::getStoreConfig('currency/options/base', $storeId); + foreach ($initKeys as $key) { $metricData = $this->getMetric($key, $storeId); + + // 'Amount' unit of a metric should always be replaced by the store currency + $unit = ($this->_metricData[$key]['unit'] == 'Amount' ? $amountUnit : $this->_metricData[$key]['unit']); if (empty($metricData)) { $this->setMetric( self::ACTION_UPDATE, $key, $storeId, 0, - $this->_metricData[$key]['unit'] + $unit ); } } @@ -496,8 +501,7 @@ public function updateAvgOrderValues($storeId) self::ACTION_UPDATE, self::KEY_ORDER_SIZE_AVERAGE, $storeId, - ($orderItems/$orderTotal), - $amountUnit + ($orderItems/$orderTotal) ); $this->setMetric( @@ -513,8 +517,7 @@ public function updateAvgOrderValues($storeId) self::ACTION_UPDATE, self::KEY_ORDER_SIZE_AVERAGE_NEW, $storeId, - ($newOrderItems / $newOrderTotal), - $amountUnit + ($newOrderItems / $newOrderTotal) ); $this->setMetric( @@ -595,6 +598,8 @@ public function initOrderData() } foreach ($data as $storeId => $details) { + $amountUnit = Mage::getStoreConfig('currency/options/base', $storeId); + $this->setMetric( self::ACTION_UPDATE, self::KEY_ORDER_SIZE_TOTAL, @@ -606,7 +611,8 @@ public function initOrderData() self::ACTION_UPDATE, self::KEY_ORDER_AMOUNT_TOTAL, $storeId, - $details['amount'] + $details['amount'], + $amountUnit ); $this->setMetric( @@ -663,6 +669,17 @@ public function initOrderData() } } + /** + * Cronjob to update the orders metrics + */ + public function dailyCron() + { + if (!$this->_helper->isEnabled()) { + return; + } + $this->initOrderData(); + } + /** * Generate output event * @@ -722,6 +739,8 @@ public function getAbandonnedCarts() ->group('main_table.store_id'); $output = array(); foreach ($collection as $order) { + $amountUnit = Mage::getStoreConfig('currency/options/base', (int)$order->getStoreId()); + $output[] = array( 'name' => 'Abandonned carts', 'unit' => 'orders', @@ -731,7 +750,7 @@ public function getAbandonnedCarts() ); $output[] = array( 'name' => 'Total value of abandoned carts', - 'unit' => 'Amount', + 'unit' => $amountUnit, 'value' => (float)$order->getSubtotal(), 'store_id' => (int)$order->getStoreId(), 'type' => 'A' diff --git a/app/code/community/CoScale/Monitor/etc/config.xml b/app/code/community/CoScale/Monitor/etc/config.xml index 8dded39..671e67c 100644 --- a/app/code/community/CoScale/Monitor/etc/config.xml +++ b/app/code/community/CoScale/Monitor/etc/config.xml @@ -2,7 +2,7 @@ - 0.13.0 + 0.15.0 diff --git a/app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.14.0-0.15.0.php b/app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.14.0-0.15.0.php new file mode 100644 index 0000000..82392c1 --- /dev/null +++ b/app/code/community/CoScale/Monitor/sql/coscale_monitor_setup/upgrade-0.14.0-0.15.0.php @@ -0,0 +1,21 @@ + + * @created 2016-05-18 + * @version 0.15.0 + */ +$installer = $this; + +$installer->startSetup(); + +$metric = $installer->getConnection(); + +/** + * Initialize order data for further delta processing + */ +Mage::getSingleton('coscale_monitor/metric_order')->initOrderData(); +Mage::getSingleton('coscale_monitor/metric_customer')->updateTotalCount(); +Mage::getSingleton('coscale_monitor/metric_product')->updateTotalCount(); + +$installer->endSetup(); \ No newline at end of file