Version Notes
Added:
- previous quarter stats on dashboard
- changed security level
- downloading and printing PDF invoice
Works only with beta release of app (2.6.0.1)
Download this release
Release Info
| Developer | eMagicOne |
| Extension | mobile_assistant_connector |
| Version | 1.2.0.1 |
| Comparing to | |
| See all releases | |
Code changes from version 1.1.2 to 1.2.0.1
- app/code/community/Emagicone/Mobassistantconnector/Helper/Access.php +126 -0
- app/code/community/Emagicone/Mobassistantconnector/Helper/Data.php +10 -7
- app/code/community/Emagicone/Mobassistantconnector/Model/Failed.php +26 -0
- app/code/community/Emagicone/Mobassistantconnector/Model/Login.php +5 -0
- app/code/community/Emagicone/Mobassistantconnector/Model/Password.php +5 -0
- app/code/community/Emagicone/Mobassistantconnector/Model/Resource/Failed.php +26 -0
- app/code/community/Emagicone/Mobassistantconnector/Model/Resource/Failed/Collection.php +25 -0
- app/code/community/Emagicone/Mobassistantconnector/Model/Resource/Sessions.php +26 -0
- app/code/community/Emagicone/Mobassistantconnector/Model/Resource/Sessions/Collection.php +25 -0
- app/code/community/Emagicone/Mobassistantconnector/Model/Sessions.php +26 -0
- app/code/community/Emagicone/Mobassistantconnector/controllers/IndexController.php +843 -599
- app/code/community/Emagicone/Mobassistantconnector/etc/adminhtml.xml +25 -25
- app/code/community/Emagicone/Mobassistantconnector/etc/config.xml +143 -119
- app/code/community/Emagicone/Mobassistantconnector/sql/emagicone_mobassistantconnector_setup/install-1.0.0.php +60 -0
- package.xml +11 -6
app/code/community/Emagicone/Mobassistantconnector/Helper/Access.php
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* This file is part of Mobile Assistant Connector.
|
| 4 |
+
*
|
| 5 |
+
* Mobile Assistant Connector is free software: you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* Mobile Assistant Connector is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with Mobile Assistant Connector. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
class Emagicone_Mobassistantconnector_Helper_Access extends Mage_Core_Helper_Abstract
|
| 20 |
+
{
|
| 21 |
+
const HASH_ALGORITHM = 'sha256';
|
| 22 |
+
const MAX_LIFETIME = 86400; /* 24 hours */
|
| 23 |
+
// const TABLE_SESSION_KEYS = 'emagicone_mobassistantconnector_sessions';
|
| 24 |
+
// const TABLE_FAILED_ATTEMPTS = 'emagicone_mobassistantconnector_failed_login';
|
| 25 |
+
|
| 26 |
+
public static function clearOldData()
|
| 27 |
+
{
|
| 28 |
+
$timestamp = time();
|
| 29 |
+
$date = Mage::getStoreConfig('mobassistantconnectorinfosec/access/cl_date');
|
| 30 |
+
|
| 31 |
+
if ($date === false || ($timestamp - (int)$date) > self::MAX_LIFETIME)
|
| 32 |
+
{
|
| 33 |
+
$sessions = Mage::getModel("emagicone_mobassistantconnector/sessions")->getCollection();
|
| 34 |
+
$sessions->addFieldToFilter('`date_added`', array('lt' => ($timestamp - self::MAX_LIFETIME)));
|
| 35 |
+
foreach ($sessions as $session) {
|
| 36 |
+
$session->delete();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
$attempts = Mage::getModel("emagicone_mobassistantconnector/failed")->getCollection();
|
| 40 |
+
$attempts->addFieldToFilter('`date_added`', array('lt' => ($timestamp - self::MAX_LIFETIME)));
|
| 41 |
+
foreach ($attempts as $attempt) {
|
| 42 |
+
$attempt->delete();
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
Mage::getModel('core/config')->saveConfig('mobassistantconnectorinfosec/access/cl_date', $timestamp );
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
public static function getSessionKey($hash)
|
| 50 |
+
{
|
| 51 |
+
$login = Mage::getStoreConfig('mobassistantconnectorinfosec/emoaccess/login');
|
| 52 |
+
$password = Mage::getStoreConfig('mobassistantconnectorinfosec/emoaccess/password');
|
| 53 |
+
|
| 54 |
+
if (hash(self::HASH_ALGORITHM, $login.$password) == $hash)
|
| 55 |
+
return self::generateSessionKey($login);
|
| 56 |
+
else
|
| 57 |
+
self::addFailedAttempt();
|
| 58 |
+
|
| 59 |
+
return false;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
public static function checkSessionKey($key)
|
| 63 |
+
{
|
| 64 |
+
if(!empty($key)) {
|
| 65 |
+
|
| 66 |
+
$timestamp = time();
|
| 67 |
+
|
| 68 |
+
$sessions = Mage::getModel("emagicone_mobassistantconnector/sessions")->getCollection();
|
| 69 |
+
$sessions->addFieldToFilter('`date_added`', array('gt' => ($timestamp - self::MAX_LIFETIME)));
|
| 70 |
+
$sessions->addFieldToFilter('`session_key`', array('eq' => $key));
|
| 71 |
+
|
| 72 |
+
if($sessions->getSize() > 0) {
|
| 73 |
+
return true;
|
| 74 |
+
} else {
|
| 75 |
+
self::addFailedAttempt();
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
return false;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
public static function generateSessionKey($username)
|
| 83 |
+
{
|
| 84 |
+
$timestamp = time();
|
| 85 |
+
|
| 86 |
+
$enc_key = (string)Mage::getConfig()->getNode('global/crypt/key');
|
| 87 |
+
|
| 88 |
+
$key = hash(self::HASH_ALGORITHM, $enc_key.$username.$timestamp);
|
| 89 |
+
|
| 90 |
+
$sessions = Mage::getModel("emagicone_mobassistantconnector/sessions");
|
| 91 |
+
$sessions->setData(array('session_key' => $key, 'date_added' => $timestamp));
|
| 92 |
+
$sessions->save();
|
| 93 |
+
|
| 94 |
+
return $key;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
public static function addFailedAttempt()
|
| 98 |
+
{
|
| 99 |
+
$timestamp = time();
|
| 100 |
+
|
| 101 |
+
$attempts = Mage::getModel("emagicone_mobassistantconnector/failed");
|
| 102 |
+
$attempts->setData(array('ip' => $_SERVER['REMOTE_ADDR'], 'date_added' => $timestamp));
|
| 103 |
+
$attempts->save();
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
$attempts = Mage::getModel("emagicone_mobassistantconnector/failed")->getCollection();
|
| 107 |
+
$attempts->addFieldToFilter('`date_added`', array('gt' => ($timestamp - self::MAX_LIFETIME)));
|
| 108 |
+
$attempts->addFieldToFilter('`ip`', array('eq' => $_SERVER['REMOTE_ADDR']));
|
| 109 |
+
$count_failed_attempts = $attempts->getSize();
|
| 110 |
+
|
| 111 |
+
self::setDelay((int)$count_failed_attempts);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
private static function setDelay($count_attempts)
|
| 115 |
+
{
|
| 116 |
+
if ($count_attempts <= 10)
|
| 117 |
+
sleep(2);
|
| 118 |
+
elseif ($count_attempts <= 20)
|
| 119 |
+
sleep(5);
|
| 120 |
+
elseif ($count_attempts <= 50)
|
| 121 |
+
sleep(10);
|
| 122 |
+
else
|
| 123 |
+
sleep(20);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
}
|
app/code/community/Emagicone/Mobassistantconnector/Helper/Data.php
CHANGED
|
@@ -34,16 +34,16 @@ class Emagicone_Mobassistantconnector_Helper_Data extends Mage_Core_Helper_Abstr
|
|
| 34 |
$result = curl_exec( $ch );
|
| 35 |
|
| 36 |
if(curl_errno($ch)) {
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
}
|
| 43 |
|
| 44 |
curl_close($ch);
|
| 45 |
-
|
| 46 |
-
|
| 47 |
}
|
| 48 |
|
| 49 |
public function pushSettingsUpgrade() {
|
|
@@ -110,6 +110,9 @@ class Emagicone_Mobassistantconnector_Helper_Data extends Mage_Core_Helper_Abstr
|
|
| 110 |
$error = isset($result['error']) ? $result['error'] : null;
|
| 111 |
if ($newRegId) {
|
| 112 |
// It's duplicated deviceId
|
|
|
|
|
|
|
|
|
|
| 113 |
if(in_array($newRegId, $deviceIds) && $newRegId != $deviceIds[$id]) {
|
| 114 |
// Loop through the devices and delete old
|
| 115 |
foreach ($deviceIdActions as $settingNum => $deviceId) {
|
| 34 |
$result = curl_exec( $ch );
|
| 35 |
|
| 36 |
if(curl_errno($ch)) {
|
| 37 |
+
Mage::log(
|
| 38 |
+
"Push message error while sending CURL request: {$result}",
|
| 39 |
+
null,
|
| 40 |
+
'emagicone_mobassistantconnector.log'
|
| 41 |
+
);
|
| 42 |
}
|
| 43 |
|
| 44 |
curl_close($ch);
|
| 45 |
+
|
| 46 |
+
return $result;
|
| 47 |
}
|
| 48 |
|
| 49 |
public function pushSettingsUpgrade() {
|
| 110 |
$error = isset($result['error']) ? $result['error'] : null;
|
| 111 |
if ($newRegId) {
|
| 112 |
// It's duplicated deviceId
|
| 113 |
+
if(!is_array($deviceIds)) {
|
| 114 |
+
$deviceIds = array($deviceIds);
|
| 115 |
+
}
|
| 116 |
if(in_array($newRegId, $deviceIds) && $newRegId != $deviceIds[$id]) {
|
| 117 |
// Loop through the devices and delete old
|
| 118 |
foreach ($deviceIdActions as $settingNum => $deviceId) {
|
app/code/community/Emagicone/Mobassistantconnector/Model/Failed.php
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* This file is part of Mobile Assistant Connector.
|
| 4 |
+
*
|
| 5 |
+
* Mobile Assistant Connector is free software: you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* Mobile Assistant Connector is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with Mobile Assistant Connector. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
class Emagicone_Mobassistantconnector_Model_Failed extends Mage_Core_Model_Abstract
|
| 20 |
+
{
|
| 21 |
+
public function _construct()
|
| 22 |
+
{
|
| 23 |
+
// parent::_construct();
|
| 24 |
+
$this->_init('emagicone_mobassistantconnector/failed');
|
| 25 |
+
}
|
| 26 |
+
}
|
app/code/community/Emagicone/Mobassistantconnector/Model/Login.php
CHANGED
|
@@ -30,6 +30,11 @@ class Emagicone_Mobassistantconnector_Model_Login extends Mage_Core_Model_Config
|
|
| 30 |
$this->setValue($old_login);
|
| 31 |
}
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
return parent::save();
|
| 34 |
}
|
| 35 |
}
|
| 30 |
$this->setValue($old_login);
|
| 31 |
}
|
| 32 |
|
| 33 |
+
$sessions = Mage::getModel("emagicone_mobassistantconnector/sessions")->getCollection();
|
| 34 |
+
foreach ($sessions as $session) {
|
| 35 |
+
$session->delete();
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
return parent::save();
|
| 39 |
}
|
| 40 |
}
|
app/code/community/Emagicone/Mobassistantconnector/Model/Password.php
CHANGED
|
@@ -33,6 +33,11 @@ class Emagicone_Mobassistantconnector_Model_Password extends Mage_Core_Model_Con
|
|
| 33 |
$this->setValue($old_password);
|
| 34 |
}
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
return parent::save();
|
| 37 |
}
|
| 38 |
}
|
| 33 |
$this->setValue($old_password);
|
| 34 |
}
|
| 35 |
|
| 36 |
+
$sessions = Mage::getModel("emagicone_mobassistantconnector/sessions")->getCollection();
|
| 37 |
+
foreach ($sessions as $session) {
|
| 38 |
+
$session->delete();
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
return parent::save();
|
| 42 |
}
|
| 43 |
}
|
app/code/community/Emagicone/Mobassistantconnector/Model/Resource/Failed.php
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* This file is part of Mobile Assistant Connector.
|
| 4 |
+
*
|
| 5 |
+
* Mobile Assistant Connector is free software: you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* Mobile Assistant Connector is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with Mobile Assistant Connector. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
class Emagicone_Mobassistantconnector_Model_Resource_Failed extends Mage_Core_Model_Resource_Db_Abstract
|
| 20 |
+
{
|
| 21 |
+
public function _construct()
|
| 22 |
+
{
|
| 23 |
+
// parent::_construct();
|
| 24 |
+
$this->_init('emagicone_mobassistantconnector/failed', 'attempt_id');
|
| 25 |
+
}
|
| 26 |
+
}
|
app/code/community/Emagicone/Mobassistantconnector/Model/Resource/Failed/Collection.php
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* This file is part of Mobile Assistant Connector.
|
| 4 |
+
*
|
| 5 |
+
* Mobile Assistant Connector is free software: you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* Mobile Assistant Connector is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with Mobile Assistant Connector. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
class Emagicone_Mobassistantconnector_Model_Resource_Failed_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
|
| 20 |
+
{
|
| 21 |
+
public function _construct()
|
| 22 |
+
{
|
| 23 |
+
$this->_init('emagicone_mobassistantconnector/failed');
|
| 24 |
+
}
|
| 25 |
+
}
|
app/code/community/Emagicone/Mobassistantconnector/Model/Resource/Sessions.php
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* This file is part of Mobile Assistant Connector.
|
| 4 |
+
*
|
| 5 |
+
* Mobile Assistant Connector is free software: you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* Mobile Assistant Connector is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with Mobile Assistant Connector. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
class Emagicone_Mobassistantconnector_Model_Resource_Sessions extends Mage_Core_Model_Resource_Db_Abstract
|
| 20 |
+
{
|
| 21 |
+
public function _construct()
|
| 22 |
+
{
|
| 23 |
+
// parent::_construct();
|
| 24 |
+
$this->_init('emagicone_mobassistantconnector/sessions', 'session_id');
|
| 25 |
+
}
|
| 26 |
+
}
|
app/code/community/Emagicone/Mobassistantconnector/Model/Resource/Sessions/Collection.php
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* This file is part of Mobile Assistant Connector.
|
| 4 |
+
*
|
| 5 |
+
* Mobile Assistant Connector is free software: you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* Mobile Assistant Connector is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with Mobile Assistant Connector. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
class Emagicone_Mobassistantconnector_Model_Resource_Sessions_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
|
| 20 |
+
{
|
| 21 |
+
public function _construct()
|
| 22 |
+
{
|
| 23 |
+
$this->_init('emagicone_mobassistantconnector/sessions');
|
| 24 |
+
}
|
| 25 |
+
}
|
app/code/community/Emagicone/Mobassistantconnector/Model/Sessions.php
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* This file is part of Mobile Assistant Connector.
|
| 4 |
+
*
|
| 5 |
+
* Mobile Assistant Connector is free software: you can redistribute it and/or modify
|
| 6 |
+
* it under the terms of the GNU General Public License as published by
|
| 7 |
+
* the Free Software Foundation, either version 3 of the License, or
|
| 8 |
+
* (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* Mobile Assistant Connector is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
+
* GNU General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU General Public License
|
| 16 |
+
* along with Mobile Assistant Connector. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
class Emagicone_Mobassistantconnector_Model_Sessions extends Mage_Core_Model_Abstract
|
| 20 |
+
{
|
| 21 |
+
public function _construct()
|
| 22 |
+
{
|
| 23 |
+
// parent::_construct();
|
| 24 |
+
$this->_init('emagicone_mobassistantconnector/sessions');
|
| 25 |
+
}
|
| 26 |
+
}
|
app/code/community/Emagicone/Mobassistantconnector/controllers/IndexController.php
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
<?php
|
|
|
|
| 2 |
/**
|
| 3 |
* This file is part of Mobile Assistant Connector.
|
| 4 |
*
|
|
@@ -15,42 +16,84 @@
|
|
| 15 |
* You should have received a copy of the GNU General Public License
|
| 16 |
* along with Mobile Assistant Connector. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
*/
|
| 18 |
-
|
| 19 |
-
|
| 20 |
class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controller_Front_Action
|
| 21 |
{
|
| 22 |
public $CartClass = "";
|
| 23 |
public $call_function;
|
| 24 |
public $callback;
|
| 25 |
-
public $hash;
|
| 26 |
public $def_currency;
|
| 27 |
public $currency_code;
|
|
|
|
|
|
|
| 28 |
const GSM_URL = 'https://android.googleapis.com/gcm/send';
|
| 29 |
-
const MB_VERSION = '
|
| 30 |
|
| 31 |
-
public function indexAction()
|
|
|
|
| 32 |
Mage::app()->cleanCache();
|
| 33 |
-
if(intval(Mage::getStoreConfig('mobassistantconnectorinfosec/emogeneral/status')) != 1) $this->generate_output('module_disabled');
|
| 34 |
|
| 35 |
$this->loadLayout()->renderLayout();
|
| 36 |
|
| 37 |
$def_currency = $this->_get_default_currency();
|
| 38 |
$this->def_currency = $def_currency['currency'];
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
$this->callback = $value;
|
| 43 |
-
if(isset($key) && $key == 'call_function' && isset($value) && strlen($value) > 0)
|
| 44 |
$this->call_function = $value;
|
| 45 |
-
if(isset($key) && $key == 'hash' && isset($value) && strlen($value) > 0)
|
| 46 |
$this->hash = $value;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
|
| 49 |
-
if(!$this->check_auth()) {
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
$request_params = Mage::app()->getRequest()->getParams();
|
|
|
|
| 54 |
$params = $this->validate_types($request_params, array(
|
| 55 |
'show' => 'INT',
|
| 56 |
'page' => 'INT',
|
|
@@ -103,31 +146,33 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 103 |
'carts_to' => 'STR',
|
| 104 |
'cart_id' => 'STR',
|
| 105 |
'search_carts' => 'STR',
|
|
|
|
|
|
|
| 106 |
'show_unregistered_customers' => 'INT',
|
| 107 |
));
|
| 108 |
|
| 109 |
-
foreach($params as $k => $value) {
|
| 110 |
$this->{$k} = $value;
|
| 111 |
}
|
| 112 |
|
| 113 |
-
if(empty($this->currency_code) || strval($this->currency_code) == 'base_currency' || strval($this->currency_code) == 'not_set') {
|
| 114 |
$this->currency_code = $this->def_currency;
|
| 115 |
}
|
| 116 |
|
| 117 |
-
if($this->call_function == 'test_config') {
|
| 118 |
$this->generate_output(array('test' => 1));
|
| 119 |
}
|
| 120 |
|
| 121 |
$locale = Mage::app()->getLocale()->getLocaleCode();
|
| 122 |
Mage::app()->getTranslator()->setLocale($locale);
|
| 123 |
|
| 124 |
-
if(!method_exists($this, $this->call_function)) {
|
| 125 |
Mage::log(
|
| 126 |
"Unknown method call ({$this->call_function})",
|
| 127 |
null,
|
| 128 |
'emagicone_mobassistantconnector.log'
|
| 129 |
);
|
| 130 |
-
$this->generate_output('
|
| 131 |
}
|
| 132 |
|
| 133 |
$result = call_user_func(array($this, $this->call_function));
|
|
@@ -135,44 +180,93 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 135 |
$this->generate_output($result);
|
| 136 |
}
|
| 137 |
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
$add_bridge_version = false;
|
| 141 |
-
if(in_array($this->call_function, array("test_config", "get_store_title", "get_store_stats", "get_data_graphs"))) {
|
| 142 |
-
if(is_array($data) && $data != 'auth_error' && $data != 'connection_error' && $data != 'old_bridge') {
|
| 143 |
-
$add_bridge_version = true;
|
| 144 |
}
|
| 145 |
-
}
|
| 146 |
|
| 147 |
-
|
| 148 |
-
$data = array($data);
|
| 149 |
}
|
| 150 |
|
| 151 |
-
|
| 152 |
-
array_walk_recursive($data, array($this, 'reset_null'));
|
| 153 |
-
}
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
|
| 160 |
-
$data = Mage::helper('core')->jsonEncode($data);
|
| 161 |
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
}
|
|
|
|
|
|
|
| 169 |
}
|
| 170 |
|
| 171 |
-
protected function check_auth()
|
|
|
|
| 172 |
$login = Mage::getStoreConfig('mobassistantconnectorinfosec/emoaccess/login');
|
| 173 |
$password = Mage::getStoreConfig('mobassistantconnectorinfosec/emoaccess/password');
|
| 174 |
|
| 175 |
-
if(
|
| 176 |
return true;
|
| 177 |
} else {
|
| 178 |
Mage::log(
|
|
@@ -184,27 +278,28 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 184 |
}
|
| 185 |
}
|
| 186 |
|
| 187 |
-
protected function push_notification_settings()
|
|
|
|
| 188 |
$result = array();
|
| 189 |
$statuses = array();
|
| 190 |
$matched = false;
|
| 191 |
$deviceActions = array('push_device_id' => '',
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
|
| 199 |
$deviceIds = Mage::getStoreConfig('mobassistantconnectorinfosec/access/google_ids');
|
| 200 |
-
if(strlen($deviceIds) > 0) {
|
| 201 |
$deviceIds = unserialize($deviceIds);
|
| 202 |
} else $deviceIds = array();
|
| 203 |
|
| 204 |
-
foreach(array_keys($deviceIds) as $key) {
|
| 205 |
if (!is_int($key)) {
|
| 206 |
$deviceIds[$key]['push_device_id'] = $key;
|
| 207 |
-
if(empty($deviceIds[$key]['push_store_group_id'])) {
|
| 208 |
$deviceIds[$key]['push_store_group_id'] = -1;
|
| 209 |
}
|
| 210 |
array_push($deviceIds, $deviceIds[$key]);
|
|
@@ -212,88 +307,88 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 212 |
}
|
| 213 |
}
|
| 214 |
|
| 215 |
-
if(strlen($this->registration_id) > 0 && strlen($this->api_key) > 0) {
|
| 216 |
|
| 217 |
-
if(strlen($this->registration_id
|
| 218 |
$deviceActions['push_device_id'] = $this->registration_id;
|
| 219 |
}
|
| 220 |
|
| 221 |
-
if(strlen($this->push_new_order
|
| 222 |
$deviceActions['push_new_order'] = $this->push_new_order;
|
| 223 |
-
}
|
| 224 |
$deviceActions['push_new_order'] = 0;
|
| 225 |
}
|
| 226 |
|
| 227 |
-
if(strlen($this->push_order_statuses) > 0) {
|
| 228 |
$deviceActions['push_order_statuses'] = $this->push_order_statuses;
|
| 229 |
-
}
|
| 230 |
$deviceActions['push_order_statuses'] = '';
|
| 231 |
}
|
| 232 |
|
| 233 |
-
if(strlen($this->push_new_customer
|
| 234 |
$deviceActions['push_new_customer'] = $this->push_new_customer;
|
| 235 |
-
}
|
| 236 |
$deviceActions['push_new_customer'] = 0;
|
| 237 |
}
|
| 238 |
|
| 239 |
-
if(!empty($this->store_group_id)) {
|
| 240 |
$deviceActions['push_store_group_id'] = $this->store_group_id;
|
| 241 |
-
}
|
| 242 |
$deviceActions['push_store_group_id'] = -1;
|
| 243 |
}
|
| 244 |
|
| 245 |
-
if(!empty($this->app_connection_id)) {
|
| 246 |
$deviceActions['app_connection_id'] = $this->app_connection_id;
|
| 247 |
-
}
|
| 248 |
$deviceActions['app_connection_id'] = -1;
|
| 249 |
}
|
| 250 |
|
| 251 |
-
if(strlen($this->push_currency_code) > 0) {
|
| 252 |
$deviceActions['push_currency_code'] = $this->push_currency_code;
|
| 253 |
-
} else if(strlen($this->currency_code) > 0) {
|
| 254 |
$deviceActions['push_currency_code'] = $this->currency_code;
|
| 255 |
} else {
|
| 256 |
$deviceActions['push_currency_code'] = 'base_currency';
|
| 257 |
}
|
| 258 |
|
| 259 |
// Delete empty record
|
| 260 |
-
if((intval($this->push_new_order
|
| 261 |
foreach ($deviceIds as $settingNum => $deviceId) {
|
| 262 |
-
if($deviceId['push_device_id'] == $this->registration_id && (isset($deviceId['app_connection_id']) && $deviceId['app_connection_id'] == $deviceActions['app_connection_id'])) {
|
| 263 |
unset($deviceIds[$settingNum]);
|
| 264 |
-
} else if($deviceId['push_device_id'] == $this->registration_id && $deviceId['push_store_group_id'] == $this->store_group_id && !isset($deviceId['app_connection_id'])) {
|
| 265 |
unset($deviceIds[$settingNum]);
|
| 266 |
}
|
| 267 |
}
|
| 268 |
} else {
|
| 269 |
// renew old record
|
| 270 |
foreach ($deviceIds as $settingNum => $deviceId) {
|
| 271 |
-
if($deviceId['push_device_id'] == $this->registration_id && (isset($deviceId['app_connection_id']) && $deviceId['app_connection_id'] == $deviceActions['app_connection_id'])) {
|
| 272 |
$deviceIds[$settingNum] = $deviceActions;
|
| 273 |
$matched = true;
|
| 274 |
-
} else if($deviceId['push_device_id'] == $this->registration_id && $deviceId['push_store_group_id'] == $deviceActions['push_store_group_id'] && !isset($deviceId['app_connection_id'])) {
|
| 275 |
$deviceIds[$settingNum] = $deviceActions;
|
| 276 |
$matched = true;
|
| 277 |
}
|
| 278 |
}
|
| 279 |
-
if(!$matched) {
|
| 280 |
// add new record
|
| 281 |
array_push($deviceIds, $deviceActions);
|
| 282 |
}
|
| 283 |
}
|
| 284 |
|
| 285 |
// Delete old registration id
|
| 286 |
-
if(isset($this->registration_id_old) && strlen($this->registration_id_old) > 0) {
|
| 287 |
foreach ($deviceIds as $settingNum => $deviceId) {
|
| 288 |
-
if($deviceId['push_device_id'] == $this->registration_id_old) {
|
| 289 |
unset($deviceIds[$settingNum]);
|
| 290 |
}
|
| 291 |
}
|
| 292 |
}
|
| 293 |
|
| 294 |
-
Mage::getModel('core/config')->saveConfig('mobassistantconnectorinfosec/access/google_ids', serialize($deviceIds)
|
| 295 |
|
| 296 |
-
Mage::getModel('core/config')->saveConfig('mobassistantconnectorinfosec/access/api_key', $this->api_key
|
| 297 |
|
| 298 |
$result = array('success' => 'true');
|
| 299 |
} else
|
|
@@ -302,49 +397,52 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 302 |
return $result;
|
| 303 |
}
|
| 304 |
|
| 305 |
-
protected function get_store_title()
|
| 306 |
-
|
|
|
|
| 307 |
try {
|
| 308 |
$name = Mage::app()->getGroup($this->group_id)->getName();
|
| 309 |
-
} catch(Exception $e) {
|
| 310 |
$name = Mage::app()->getStore()->getFrontendName();
|
| 311 |
}
|
| 312 |
} else $name = Mage::app()->getStore()->getFrontendName();
|
| 313 |
return array('test' => 1, 'title' => $name);
|
| 314 |
}
|
| 315 |
|
| 316 |
-
protected function is_group_exists($groupId)
|
|
|
|
| 317 |
$exists = false;
|
| 318 |
-
if(isset($groupId)) {
|
| 319 |
try {
|
| 320 |
$name = Mage::app()->getGroup($groupId)->getName();
|
| 321 |
$exists = true;
|
| 322 |
-
} catch(Exception $e) {
|
| 323 |
$exists = false;
|
| 324 |
}
|
| 325 |
}
|
| 326 |
return $exists;
|
| 327 |
}
|
| 328 |
|
| 329 |
-
protected function get_stores()
|
|
|
|
| 330 |
$arr_result = array();
|
| 331 |
|
| 332 |
foreach (Mage::app()->getWebsites() as $website) {
|
| 333 |
foreach ($website->getGroups() as $group) {
|
| 334 |
// foreach ($group->getStores() as $store) {
|
| 335 |
-
|
| 336 |
// 'store_id' => $store->getStoreID(),
|
| 337 |
// 'store_name' => $store->getName(),
|
| 338 |
// 'is_store_active' => $store->getIsActive(),
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
// 'group_currencies' => $this->get_group_currencies($group->getId())
|
| 347 |
-
|
| 348 |
// }
|
| 349 |
}
|
| 350 |
}
|
|
@@ -352,52 +450,53 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 352 |
return $arr_result;
|
| 353 |
}
|
| 354 |
|
| 355 |
-
protected function get_currencies()
|
|
|
|
| 356 |
$currencies = array();
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
}
|
| 376 |
-
|
| 377 |
-
foreach ($currencies_array as $curCode) {
|
| 378 |
-
foreach ($currencies as $currency) {
|
| 379 |
-
if($curCode == $currency['code']){
|
| 380 |
-
continue 2;
|
| 381 |
-
}
|
| 382 |
-
}
|
| 383 |
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
}
|
| 389 |
-
} catch(Exception $e) {
|
| 390 |
-
Mage::log(
|
| 391 |
-
"Error while getting group currencies (". var_export($e->getMessage(), true). ")",
|
| 392 |
-
null,
|
| 393 |
-
'emagicone_mobassistantconnector.log'
|
| 394 |
-
);
|
| 395 |
}
|
| 396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
return $currencies;
|
| 398 |
}
|
| 399 |
|
| 400 |
-
protected function get_store_stats()
|
|
|
|
| 401 |
$data_graphs = '';
|
| 402 |
$order_status_stats = array();
|
| 403 |
|
|
@@ -407,25 +506,25 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 407 |
$today = date("Y-m-d", time());
|
| 408 |
$date_from = $date_to = $today;
|
| 409 |
|
| 410 |
-
if(!empty($this->stats_from)) {
|
| 411 |
$date_from = $this->stats_from;
|
| 412 |
}
|
| 413 |
|
| 414 |
-
if(!empty($this->stats_to)) {
|
| 415 |
$date_to = $this->stats_to;
|
| 416 |
}
|
| 417 |
|
| 418 |
-
if(isset($this->custom_period) && strlen($this->custom_period) > 0) {
|
| 419 |
$custom_period = $this->get_custom_period($this->custom_period);
|
| 420 |
|
| 421 |
$date_from = $custom_period['start_date'];
|
| 422 |
$date_to = $custom_period['end_date'];
|
| 423 |
}
|
| 424 |
|
| 425 |
-
if(!empty($date_from)) {
|
| 426 |
$date_from .= " 00:00:00";
|
| 427 |
}
|
| 428 |
-
if(!empty($date_to)) {
|
| 429 |
$date_to .= " 23:59:59";
|
| 430 |
}
|
| 431 |
|
|
@@ -434,13 +533,13 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 434 |
$ordersCollection->addAttributeToSelect('entity_id');
|
| 435 |
$storeTableName = Mage::getSingleton('core/resource')->getTableName('core/store');
|
| 436 |
|
| 437 |
-
if(strlen($this->statuses) > 0) {
|
| 438 |
$this->statuses = '\'' . str_replace('|', '\',\'', $this->statuses) . '\'';
|
| 439 |
$ordersCollection->getSelect()->where(new Zend_Db_Expr("main_table.status IN ({$this->statuses})"));
|
| 440 |
}
|
| 441 |
|
| 442 |
if (!empty($this->group_id)) {
|
| 443 |
-
if($this->is_group_exists($this->group_id)) {
|
| 444 |
$ordersCollection->getSelect()
|
| 445 |
->joinLeft(
|
| 446 |
array('cs' => $storeTableName),
|
|
@@ -449,11 +548,11 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 449 |
}
|
| 450 |
}
|
| 451 |
|
| 452 |
-
if(!empty($date_from)) {
|
| 453 |
-
$ordersCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '"
|
| 454 |
}
|
| 455 |
-
if(!empty($date_to)) {
|
| 456 |
-
$ordersCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '"
|
| 457 |
}
|
| 458 |
|
| 459 |
$ordersCollection->getSelect()->columns('SUM(base_grand_total) as sum_base_grand_total,COUNT(*) AS count_orders');
|
|
@@ -463,7 +562,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 463 |
$first = $ordersCollection->getFirstItem();
|
| 464 |
|
| 465 |
/*
|
| 466 |
-
|
| 467 |
$ordersCollection->addFieldToFilter('main_table.created_at',
|
| 468 |
array('from' => $date_from,
|
| 469 |
'to' => $date_to,
|
|
@@ -495,7 +594,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 495 |
array());
|
| 496 |
|
| 497 |
if (!empty($this->group_id)) {
|
| 498 |
-
if($this->is_group_exists($this->group_id)) {
|
| 499 |
$salesCollection->getSelect()
|
| 500 |
->joinLeft(
|
| 501 |
array('cs' => $storeTableName),
|
|
@@ -504,32 +603,32 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 504 |
}
|
| 505 |
}
|
| 506 |
|
| 507 |
-
if(!empty($date_from)) {
|
| 508 |
-
$salesCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(order.created_at, '+00:00', '"
|
| 509 |
}
|
| 510 |
-
if(!empty($date_to)) {
|
| 511 |
-
$salesCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(order.created_at, '+00:00', '"
|
| 512 |
}
|
| 513 |
|
| 514 |
-
if(strlen($this->statuses) > 0) {
|
| 515 |
$salesCollection->getSelect()->where(new Zend_Db_Expr("order.status IN ({$this->statuses})"));
|
| 516 |
}
|
| 517 |
$store_stats['count_products'] = $this->bd_nice_number($salesCollection->getSize(), true);
|
| 518 |
|
| 519 |
-
$salesCollection->setOrder('item_id','DESC');
|
| 520 |
|
| 521 |
-
if($this->last_order_id != "") {
|
| 522 |
$ordersCollection = Mage::getModel('sales/order')->getCollection();
|
| 523 |
|
| 524 |
$ordersCollection->addAttributeToFilter('entity_id', array('gt' => intval($this->last_order_id)));
|
| 525 |
|
| 526 |
-
$ordersCollection->setOrder('entity_id','DESC');
|
| 527 |
$ordersCollection->getSelect()->limit(1);
|
| 528 |
|
| 529 |
$lastOrder = $ordersCollection->getFirstItem();
|
| 530 |
|
| 531 |
$store_stats['last_order_id'] = $this->last_order_id;
|
| 532 |
-
if(intval($lastOrder['entity_id']) > intval($this->last_order_id)) {
|
| 533 |
$store_stats['last_order_id'] = intval($lastOrder['entity_id']);
|
| 534 |
}
|
| 535 |
|
|
@@ -538,15 +637,15 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 538 |
|
| 539 |
$customerCollection = Mage::getModel('customer/customer')->getCollection();
|
| 540 |
|
| 541 |
-
if(!empty($date_from)) {
|
| 542 |
-
$customerCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(created_at, '+00:00', '"
|
| 543 |
}
|
| 544 |
-
if(!empty($date_to)) {
|
| 545 |
-
$customerCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(created_at, '+00:00', '"
|
| 546 |
}
|
| 547 |
|
| 548 |
if (!empty($this->group_id)) {
|
| 549 |
-
if($this->is_group_exists($this->group_id)) {
|
| 550 |
$customerCollection->getSelect()
|
| 551 |
->joinLeft(
|
| 552 |
array('cs' => $storeTableName),
|
|
@@ -558,7 +657,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 558 |
$row['count_customers'] = $customerCollection->count();
|
| 559 |
$store_stats = array_merge($store_stats, $row);
|
| 560 |
|
| 561 |
-
if(!isset($this->data_for_widget) || empty($this->data_for_widget) || $this->data_for_widget != 1) {
|
| 562 |
$data_graphs = $this->get_data_graphs();
|
| 563 |
}
|
| 564 |
|
|
@@ -581,7 +680,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 581 |
|
| 582 |
}
|
| 583 |
|
| 584 |
-
protected function get_status_stats()
|
|
|
|
| 585 |
|
| 586 |
$offset = $this->_get_timezone_offset();
|
| 587 |
$store_stats = array('count_orders' => "0", 'total_sales' => "0", 'count_customers' => "0", 'count_products' => "0", "last_order_id" => "0", "new_orders" => "0");
|
|
@@ -589,25 +689,25 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 589 |
$today = date("Y-m-d", time());
|
| 590 |
$date_from = $date_to = $today;
|
| 591 |
|
| 592 |
-
if(!empty($this->stats_from)) {
|
| 593 |
$date_from = $this->stats_from;
|
| 594 |
}
|
| 595 |
|
| 596 |
-
if(!empty($this->stats_to)) {
|
| 597 |
$date_to = $this->stats_to;
|
| 598 |
}
|
| 599 |
|
| 600 |
-
if(isset($this->custom_period) && strlen($this->custom_period) > 0) {
|
| 601 |
$custom_period = $this->get_custom_period($this->custom_period);
|
| 602 |
|
| 603 |
$date_from = $custom_period['start_date'];
|
| 604 |
$date_to = $custom_period['end_date'];
|
| 605 |
}
|
| 606 |
|
| 607 |
-
if(!empty($date_from)) {
|
| 608 |
$date_from .= " 00:00:00";
|
| 609 |
}
|
| 610 |
-
if(!empty($date_to)) {
|
| 611 |
$date_to .= " 23:59:59";
|
| 612 |
}
|
| 613 |
|
|
@@ -615,12 +715,12 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 615 |
$orderStatusTableName = Mage::getSingleton('core/resource')->getTableName('sales/order_status');
|
| 616 |
|
| 617 |
$salesCollection = Mage::getModel("sales/order")->getCollection()
|
| 618 |
-
->addFieldToSelect(array('state', 'status',
|
| 619 |
|
| 620 |
$salesCollection->clear();
|
| 621 |
|
| 622 |
if (!empty($this->group_id)) {
|
| 623 |
-
if($this->is_group_exists($this->group_id)) {
|
| 624 |
$salesCollection->getSelect()
|
| 625 |
->joinLeft(
|
| 626 |
array('cs' => $storeTableName),
|
|
@@ -636,15 +736,15 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 636 |
array('name' => 'sos.label'));
|
| 637 |
|
| 638 |
$salesCollection->getSelect()->columns(array('code' => new Zend_Db_Expr ('main_table.status')));
|
| 639 |
-
|
| 640 |
$salesCollection->getSelect()->columns(array('total' => new Zend_Db_Expr ('SUM(main_table.base_grand_total)')));
|
| 641 |
|
| 642 |
|
| 643 |
-
if(!empty($date_from)) {
|
| 644 |
-
$salesCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '"
|
| 645 |
}
|
| 646 |
-
if(!empty($date_to)) {
|
| 647 |
-
$salesCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '"
|
| 648 |
}
|
| 649 |
|
| 650 |
// if(strlen($this->statuses) > 0) {
|
|
@@ -653,7 +753,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 653 |
|
| 654 |
$salesCollection->getSelect()->group(new Zend_Db_Expr("main_table.status"));
|
| 655 |
|
| 656 |
-
$salesCollection->getSelect()->order(
|
| 657 |
|
| 658 |
$orders = array();
|
| 659 |
foreach ($salesCollection as $sale) {
|
|
@@ -681,18 +781,19 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 681 |
|
| 682 |
}
|
| 683 |
|
| 684 |
-
protected function get_data_graphs()
|
|
|
|
| 685 |
$orders = array();
|
| 686 |
$customers = array();
|
| 687 |
$offset = $this->_get_timezone_offset();
|
| 688 |
$average = array('avg_sum_orders' => 0, 'avg_orders' => 0, 'avg_customers' => 0, 'avg_cust_order' => '0.00', 'tot_customers' => 0, 'sum_orders' => 0, 'tot_orders' => 0);
|
| 689 |
|
| 690 |
-
if(empty($this->graph_from)) {
|
| 691 |
-
$this->graph_from = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d")-7, date("Y")));
|
| 692 |
}
|
| 693 |
|
| 694 |
-
if(empty($this->graph_to)) {
|
| 695 |
-
if(!empty($this->stats_to)) {
|
| 696 |
$this->graph_to = $this->stats_to;
|
| 697 |
} else {
|
| 698 |
$this->graph_to = date("Y-m-d", time());
|
|
@@ -702,18 +803,18 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 702 |
$endDate = $this->graph_to . " 23:59:59";
|
| 703 |
|
| 704 |
$plus_date = "+1 day";
|
| 705 |
-
if(isset($this->custom_period) && strlen($this->custom_period) > 0) {
|
| 706 |
$custom_period = $this->get_custom_period($this->custom_period);
|
| 707 |
|
| 708 |
-
if($this->custom_period == 3) {
|
| 709 |
$plus_date = "+3 day";
|
| 710 |
-
} else if($this->custom_period == 4) {
|
| 711 |
$plus_date = "+1 week";
|
| 712 |
-
} else if($this->custom_period == 5 || $this->custom_period == 6 || $this->custom_period == 7) {
|
| 713 |
$plus_date = "+1 month";
|
| 714 |
}
|
| 715 |
|
| 716 |
-
if($this->custom_period == 6) {
|
| 717 |
$ordersCollection = Mage::getModel('sales/order')->getCollection();
|
| 718 |
$ordersCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
|
| 719 |
$ordersCollection->getSelect()->columns(array('min_date_add' => new Zend_Db_Expr ("MIN(`created_at`)")));
|
|
@@ -725,8 +826,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 725 |
$endDate = $orders_info['max_date_add'];
|
| 726 |
}
|
| 727 |
} else {
|
| 728 |
-
$startDate = $custom_period['start_date']." 00:00:00";
|
| 729 |
-
$endDate = $custom_period['end_date']." 23:59:59";
|
| 730 |
}
|
| 731 |
}
|
| 732 |
|
|
@@ -745,7 +846,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 745 |
$ordersCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
|
| 746 |
|
| 747 |
if (!empty($this->group_id)) {
|
| 748 |
-
if($this->is_group_exists($this->group_id)) {
|
| 749 |
$ordersCollection->getSelect()
|
| 750 |
->joinLeft(
|
| 751 |
array('cs' => $storeTableName),
|
|
@@ -760,10 +861,10 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 760 |
$ordersCollection->getSelect()->columns(array('tot_orders' => new Zend_Db_Expr ("COUNT(main_table.entity_id)")));
|
| 761 |
|
| 762 |
$ordersCollection->getSelect()->where(new Zend_Db_Expr("((CONVERT_TZ(main_table.created_at, '+00:00', '{$offset}' )) >= '{$dateStr}'
|
| 763 |
-
AND (CONVERT_TZ(main_table.created_at, '+00:00', '{$offset}')) < '".date('Y-m-d H:i:s', (strtotime($plus_date, $date)))."')"));
|
| 764 |
|
| 765 |
|
| 766 |
-
if(strlen($this->statuses) > 0) {
|
| 767 |
$this->statuses = str_replace('|', '\',\'', $this->statuses);
|
| 768 |
$ordersCollection->getSelect()->where(new Zend_Db_Expr("main_table.status IN ({$this->statuses})"));
|
| 769 |
}
|
|
@@ -783,13 +884,13 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 783 |
}
|
| 784 |
|
| 785 |
$total_order_per_day = number_format($total_order_per_day, 2, '.', '');
|
| 786 |
-
$orders[] = array($date*1000, $total_order_per_day);
|
| 787 |
|
| 788 |
$customersCollection = Mage::getResourceModel('customer/customer_collection');
|
| 789 |
$customersCollection->addAttributeToSelect('name');
|
| 790 |
|
| 791 |
if (!empty($this->group_id)) {
|
| 792 |
-
if($this->is_group_exists($this->group_id)) {
|
| 793 |
$customersCollection->getSelect()
|
| 794 |
->joinLeft(
|
| 795 |
array('cs' => $storeTableName),
|
|
@@ -806,26 +907,26 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 806 |
|
| 807 |
$customersCollection->getSelect()->columns(array('date_add' => new Zend_Db_Expr ("CONVERT_TZ((created_at, '+00:00', {$offset}))")));
|
| 808 |
$customersCollection->getSelect()->where(new Zend_Db_Expr("((CONVERT_TZ(created_at, '+00:00', '{$offset}')) >= '{$dateStr}'
|
| 809 |
-
AND (CONVERT_TZ(created_at, '+00:00', '{$offset}')) < '".date('Y-m-d H:i:s', (strtotime($plus_date, $date)))."')"));
|
| 810 |
|
| 811 |
$total_customer_per_day = $customersCollection->getSize();
|
| 812 |
$average['tot_customers'] += $total_customer_per_day;
|
| 813 |
$customers_count = $customersCollection->getSize();
|
| 814 |
|
| 815 |
-
$customers[] = array($date*1000, $total_customer_per_day);
|
| 816 |
$date = strtotime($plus_date, $date);
|
| 817 |
}
|
| 818 |
|
| 819 |
$sum = '0';
|
| 820 |
$default_currency_sign = $this->_price_format($this->def_currency, 1, $sum, $this->currency_code, true);
|
| 821 |
|
| 822 |
-
if($d <= 0) $d = 1;
|
| 823 |
-
$average['avg_sum_orders'] = number_format($average['sum_orders']
|
| 824 |
-
$average['avg_orders'] = number_format($average['tot_orders']
|
| 825 |
-
$average['avg_customers'] = number_format($average['tot_customers']
|
| 826 |
|
| 827 |
-
if($average['tot_customers'] > 0) {
|
| 828 |
-
$average['avg_cust_order'] = number_format($average['sum_orders']
|
| 829 |
}
|
| 830 |
$average['sum_orders'] = number_format($average['sum_orders'], 2, '.', ' ');
|
| 831 |
$average['tot_customers'] = number_format($average['tot_customers'], 1, '.', ' ');
|
|
@@ -834,7 +935,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 834 |
return array('orders' => $orders, 'customers' => $customers, 'currency_sign' => $default_currency_sign, 'average' => $average);
|
| 835 |
}
|
| 836 |
|
| 837 |
-
protected function get_orders()
|
|
|
|
| 838 |
$offset = $this->_get_timezone_offset();
|
| 839 |
$max_date = null;
|
| 840 |
$min_date = null;
|
|
@@ -859,7 +961,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 859 |
array());
|
| 860 |
|
| 861 |
if (!empty($this->group_id)) {
|
| 862 |
-
if($this->is_group_exists($this->group_id)) {
|
| 863 |
$ordersCollection->getSelect()
|
| 864 |
->joinLeft(
|
| 865 |
array('cs' => $storeTableName),
|
|
@@ -875,8 +977,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 875 |
}
|
| 876 |
|
| 877 |
$ordersStatsCollection->getSelect()->columns(array('count_ords' => new Zend_Db_Expr ('COUNT(main_table.entity_id)')));
|
| 878 |
-
$ordersStatsCollection->getSelect()->columns(array('max_date' => new Zend_Db_Expr ('MAX(CONVERT_TZ(main_table.created_at, "+00:00", "'
|
| 879 |
-
$ordersStatsCollection->getSelect()->columns(array('min_date' => new Zend_Db_Expr ('MIN(CONVERT_TZ(main_table.created_at, "+00:00", "'
|
| 880 |
$ordersStatsCollection->getSelect()->columns(array('orders_total' => new Zend_Db_Expr ('SUM(main_table.base_grand_total)')));
|
| 881 |
|
| 882 |
$ordersCollection->getSelect()->columns(array('store_id' => new Zend_Db_Expr ('main_table.store_id')));
|
|
@@ -892,58 +994,58 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 892 |
$ordersCollection->getSelect()->columns(array('lastname' => new Zend_Db_Expr ('main_table.customer_lastname')));
|
| 893 |
$ordersCollection->getSelect()->columns(array('full_name' => new Zend_Db_Expr ('CONCAT(main_table.customer_firstname, " ", main_table.customer_lastname)')));
|
| 894 |
$ordersCollection->getSelect()->columns(array('iso_code' => new Zend_Db_Expr ('main_table.global_currency_code')));
|
| 895 |
-
$ordersCollection->getSelect()->columns(array('date_add' => new Zend_Db_Expr ('CONVERT_TZ(main_table.created_at, "+00:00", "'
|
| 896 |
$ordersCollection->getSelect()->columns(array('count_prods' => new Zend_Db_Expr ('main_table.total_item_count')));
|
| 897 |
|
| 898 |
-
if(empty($this->sort_by)) {
|
| 899 |
$this->sort_by = "id";
|
| 900 |
}
|
| 901 |
|
| 902 |
switch ($this->sort_by) {
|
| 903 |
case 'name':
|
| 904 |
-
$ordersCollection->getSelect()->order(
|
| 905 |
-
$ordersCollection->getSelect()->order(
|
| 906 |
-
$ordersStatsCollection->getSelect()->order(
|
| 907 |
-
$ordersStatsCollection->getSelect()->order(
|
| 908 |
break;
|
| 909 |
case 'date':
|
| 910 |
-
$ordersCollection->getSelect()->order(
|
| 911 |
-
$ordersStatsCollection->getSelect()->order(
|
| 912 |
break;
|
| 913 |
case 'id':
|
| 914 |
-
$ordersCollection->getSelect()->order(
|
| 915 |
-
$ordersStatsCollection->getSelect()->order(
|
| 916 |
break;
|
| 917 |
}
|
| 918 |
|
| 919 |
-
if(strlen($this->statuses) > 0){
|
| 920 |
$this->statuses = '\'' . str_replace('|', '\',\'', $this->statuses) . '\'';
|
| 921 |
$ordersCollection->getSelect()->where(new Zend_Db_Expr("main_table.status IN ({$this->statuses})"));
|
| 922 |
$ordersStatsCollection->getSelect()->where(new Zend_Db_Expr("main_table.status IN ({$this->statuses})"));
|
| 923 |
}
|
| 924 |
|
| 925 |
-
if(!empty($this->orders_from)) {
|
| 926 |
-
$ordersCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '"
|
| 927 |
-
$ordersStatsCollection->getSelect()->where(new Zend_Db_Expr(" (CONVERT_TZ(main_table.created_at, '+00:00', '"
|
| 928 |
}
|
| 929 |
|
| 930 |
-
if(!empty($this->orders_to)) {
|
| 931 |
-
$ordersCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '"
|
| 932 |
-
$ordersStatsCollection->getSelect()->where(new Zend_Db_Expr(" (CONVERT_TZ(main_table.created_at, '+00:00', '"
|
| 933 |
}
|
| 934 |
|
| 935 |
$query = '';
|
| 936 |
-
if(!empty($this->search_order_id)) {
|
| 937 |
-
$query_where_parts[] = "(main_table.customer_firstname LIKE ('%"
|
| 938 |
-
OR main_table.customer_lastname LIKE ('%"
|
| 939 |
-
OR CONCAT(main_table.customer_firstname, ' ', main_table.customer_lastname) LIKE ('%"
|
| 940 |
}
|
| 941 |
-
if(!empty($this->search_order_id) && preg_match('/^\d+(?:,\d+)*$/', $this->search_order_id)) {
|
| 942 |
-
$query_where_parts[] = "(main_table.entity_id IN ("
|
| 943 |
}
|
| 944 |
|
| 945 |
if (!empty($query_where_parts)) {
|
| 946 |
-
$query .=
|
| 947 |
$ordersCollection->getSelect()->where($query);
|
| 948 |
$ordersStatsCollection->getSelect()->where($query);
|
| 949 |
}
|
|
@@ -960,19 +1062,19 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 960 |
|
| 961 |
// echo($ordersCollection->getSelect()->__toString());die();
|
| 962 |
|
| 963 |
-
if(!empty($this->page) && !empty($this->show)) {
|
| 964 |
// $ordersCollection->setPage(($this->page), $this->show);
|
| 965 |
-
$ordersCollection->getSelect()->limit($this->show, ($this->page-1)
|
| 966 |
}
|
| 967 |
|
| 968 |
-
$orders= array();
|
| 969 |
foreach ($ordersCollection as $order) {
|
| 970 |
$orderArray = $order->toArray();
|
| 971 |
$price = $this->_price_format($orderArray['iso_code'], 1, $order['total_paid'], $this->currency_code);
|
| 972 |
$orderArray['customer'] = $orderArray['firstname'] . ' ' . $orderArray['lastname'];
|
| 973 |
$orderArray['total_paid'] = $price;
|
| 974 |
|
| 975 |
-
if($this->currency_code != false){
|
| 976 |
$orderArray['iso_code'] = $this->currency_code;
|
| 977 |
}
|
| 978 |
|
|
@@ -984,14 +1086,14 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 984 |
$orders[] = $orderArray;
|
| 985 |
}
|
| 986 |
|
| 987 |
-
if($this->page > 1 && intval($this->search_order_id) > 0) {
|
| 988 |
$orders = array();
|
| 989 |
}
|
| 990 |
|
| 991 |
foreach ($ordersStatsCollection as $orderStats) {
|
| 992 |
$orderStats = $orderStats->toArray();
|
| 993 |
|
| 994 |
-
if($orderStats['count_ords'] > 0) {
|
| 995 |
$max_date = date("n/j/Y", strtotime($orderStats['max_date']));
|
| 996 |
$min_date = date("n/j/Y", strtotime($orderStats['min_date']));
|
| 997 |
}
|
|
@@ -999,7 +1101,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 999 |
}
|
| 1000 |
|
| 1001 |
$orders_status = null;
|
| 1002 |
-
if(isset($this->get_statuses) && $this->get_statuses == 1) {
|
| 1003 |
$orders_status = $this->get_orders_statuses();
|
| 1004 |
}
|
| 1005 |
|
|
@@ -1013,9 +1115,11 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1013 |
"orders_status" => $orders_status);
|
| 1014 |
}
|
| 1015 |
|
| 1016 |
-
protected function get_orders_info()
|
|
|
|
| 1017 |
$offset = $this->_get_timezone_offset();
|
| 1018 |
$order_products = array();
|
|
|
|
| 1019 |
$order_info = array('iso_code' => '', 's_country_id' => '', 'b_country_id' => '', 'telephone' => '', 'shipping_method_mag' => '', 'payment_method_mag' => '');
|
| 1020 |
|
| 1021 |
$ordersInfoCollection = Mage::getModel('sales/order')->getCollection()->addAttributeToSelect('entity_id');
|
|
@@ -1046,7 +1150,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1046 |
$ordersInfoCollection->getSelect()->columns(array('total_paid' => new Zend_Db_Expr ('main_table.base_grand_total')));
|
| 1047 |
$ordersInfoCollection->getSelect()->columns(array('customer' => new Zend_Db_Expr ('CONCAT(main_table.customer_firstname, " ", main_table.customer_lastname)')));
|
| 1048 |
$ordersInfoCollection->getSelect()->columns(array('iso_code' => new Zend_Db_Expr ('main_table.global_currency_code')));
|
| 1049 |
-
$ordersInfoCollection->getSelect()->columns(array('date_add' => new Zend_Db_Expr ('CONVERT_TZ(main_table.created_at, "+00:00", "'
|
| 1050 |
$ordersInfoCollection->getSelect()->columns(array('email' => new Zend_Db_Expr ('main_table.customer_email')));
|
| 1051 |
$ordersInfoCollection->getSelect()->columns(array('id_customer' => new Zend_Db_Expr ('main_table.customer_id')));
|
| 1052 |
$ordersInfoCollection->getSelect()->columns(array('subtotal' => new Zend_Db_Expr ('main_table.base_subtotal')));
|
|
@@ -1081,7 +1185,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1081 |
'eq' => intval($this->order_id),
|
| 1082 |
));
|
| 1083 |
|
| 1084 |
-
foreach($ordersInfoCollection as $orderInfo) {
|
| 1085 |
$order_info_array = $orderInfo->toArray();
|
| 1086 |
$order_info_array['store_id'] = $orderInfo->getStore()->getId();
|
| 1087 |
$order_info_array['store_name'] = $orderInfo->getStore()->getName();
|
|
@@ -1093,12 +1197,12 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1093 |
|
| 1094 |
$iso_code = $order_info['iso_code'];
|
| 1095 |
$elements = array('total_paid', 'subtotal', 'sh_amount', 'tax_amount', 'd_amount', 'g_total', 't_paid', 't_refunded', 't_due');
|
| 1096 |
-
foreach($elements as $element) {
|
| 1097 |
$price = $this->_price_format($iso_code, 1, $order_info[$element], $this->currency_code);
|
| 1098 |
$order_info[$element] = $price;
|
| 1099 |
}
|
| 1100 |
|
| 1101 |
-
if($this->currency_code != false){
|
| 1102 |
$order_info['iso_code'] = $this->currency_code;
|
| 1103 |
}
|
| 1104 |
|
|
@@ -1138,29 +1242,29 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1138 |
|
| 1139 |
$ordersItemsCollection->addAttributeToFilter('main_table.parent_item_id', $allowedParentId);
|
| 1140 |
|
| 1141 |
-
if(empty($this->sort_by)) {
|
| 1142 |
$this->sort_by = "id";
|
| 1143 |
}
|
| 1144 |
|
| 1145 |
switch ($this->sort_by) {
|
| 1146 |
case 'name':
|
| 1147 |
-
$ordersItemsCollection->getSelect()->order(
|
| 1148 |
break;
|
| 1149 |
case 'date':
|
| 1150 |
-
$ordersItemsCollection->getSelect()->order(
|
| 1151 |
break;
|
| 1152 |
case 'id':
|
| 1153 |
-
$ordersItemsCollection->getSelect()->order(
|
| 1154 |
break;
|
| 1155 |
}
|
| 1156 |
|
| 1157 |
-
if(!empty($this->page) && !empty($this->show)) {
|
| 1158 |
$ordersItemsCollection->setPage($this->page, $this->show);
|
| 1159 |
}
|
| 1160 |
|
| 1161 |
$block = Mage::app()->getLayout()->createBlock('sales/order_item_renderer_default');
|
| 1162 |
|
| 1163 |
-
foreach($ordersItemsCollection as $orderItem) {
|
| 1164 |
$block->setItem($orderItem);
|
| 1165 |
$_options = $block->getItemOptions();
|
| 1166 |
|
|
@@ -1173,36 +1277,34 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1173 |
// $thumbnail_path = $orderItem->getProduct()->getThumbnail();
|
| 1174 |
// $thumbnail = $orderItem->getProduct()->getMediaConfig()->getMediaUrl($thumbnail_path);
|
| 1175 |
|
| 1176 |
-
if(($thumbnail == 'no_selection') || (!isset($thumbnail))) {
|
| 1177 |
$thumbnail = '';
|
| 1178 |
}
|
| 1179 |
|
| 1180 |
$orderItem = $orderItem->toArray();
|
| 1181 |
|
| 1182 |
$orderItem['options'] = array();
|
| 1183 |
-
if(isset($_options) && count($_options) > 0){
|
| 1184 |
foreach ($_options as $option) {
|
| 1185 |
$orderItem['options'][$option['label']] = $option['value'];
|
| 1186 |
}
|
| 1187 |
}
|
| 1188 |
|
| 1189 |
$orderItem['product_options'] = unserialize($orderItem['product_options']);
|
| 1190 |
-
if(isset($orderItem['product_options']['bundle_options'])){
|
| 1191 |
foreach ($orderItem['product_options']['bundle_options'] as $option) {
|
| 1192 |
-
$orderItem['options'][$option['label']] = $option['value'][0]['qty'].'x '
|
| 1193 |
}
|
| 1194 |
}
|
| 1195 |
|
| 1196 |
unset($orderItem['product_options']);
|
| 1197 |
|
| 1198 |
-
|
| 1199 |
-
|
| 1200 |
-
if($module_version[1] > 80 && !empty($orderItem['options'])){
|
| 1201 |
$orderItem['prod_options'] = $orderItem['options'];
|
| 1202 |
unset($orderItem['options']);
|
| 1203 |
}
|
| 1204 |
|
| 1205 |
-
if(empty($orderItem['options'])) {
|
| 1206 |
unset($orderItem['options']);
|
| 1207 |
}
|
| 1208 |
|
|
@@ -1210,7 +1312,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1210 |
$orderItem['product_price'] = $this->_price_format($order_info['iso_code'], 1, $orderItem['product_price'], $this->currency_code);
|
| 1211 |
$orderItem['product_quantity'] = intval($orderItem['product_quantity']);
|
| 1212 |
$orderItem['type_id'] = ucfirst($orderItem['type_id']);
|
| 1213 |
-
if($this->currency_code != false){
|
| 1214 |
$orderItem['iso_code'] = $this->currency_code;
|
| 1215 |
}
|
| 1216 |
unset($orderItem['product']);
|
|
@@ -1228,45 +1330,49 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1228 |
|
| 1229 |
$count_prods = $orderCountItemsCollection->getSize();
|
| 1230 |
|
| 1231 |
-
if(!empty($this->order_id)) {
|
| 1232 |
|
| 1233 |
$cur_order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1234 |
|
| 1235 |
$actions = array();
|
| 1236 |
|
| 1237 |
-
if($cur_order->canCancel()) {
|
| 1238 |
$actions[] = 'cancel';
|
| 1239 |
}
|
| 1240 |
|
| 1241 |
-
if($cur_order->canHold()) {
|
| 1242 |
$actions[] = 'hold';
|
| 1243 |
}
|
| 1244 |
|
| 1245 |
-
if($cur_order->canUnhold()) {
|
| 1246 |
$actions[] = 'unhold';
|
| 1247 |
}
|
| 1248 |
|
| 1249 |
-
if($cur_order->canShip()) {
|
| 1250 |
$actions[] = 'ship';
|
| 1251 |
}
|
| 1252 |
|
| 1253 |
-
if($cur_order->canInvoice()) {
|
| 1254 |
$actions[] = 'invoice';
|
| 1255 |
}
|
| 1256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1257 |
$cus_id = $cur_order->getCustomerId();
|
| 1258 |
|
| 1259 |
$customer_data = Mage::getModel('customer/customer')->load($cus_id);
|
| 1260 |
|
| 1261 |
$customerAddressId = $customer_data->getDefaultBilling();
|
| 1262 |
-
if($customerAddressId) {
|
| 1263 |
$address = Mage::getModel('customer/address')->load($customerAddressId)->toArray();
|
| 1264 |
-
if(count($address) > 1) {
|
| 1265 |
$order_info['telephone'] = $address['telephone'];
|
| 1266 |
}
|
| 1267 |
}
|
| 1268 |
|
| 1269 |
-
if(empty($order_info['telephone'])) {
|
| 1270 |
$order_info['telephone'] = '';
|
| 1271 |
}
|
| 1272 |
$order_info['shipping_method_mag'] = $cur_order->getShippingDescription();
|
|
@@ -1278,45 +1384,83 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1278 |
->load();
|
| 1279 |
$tracks = array();
|
| 1280 |
foreach ($shipmentCollection as $shipment) {
|
| 1281 |
-
foreach($shipment->getAllTracks() as $tracknum)
|
| 1282 |
-
{
|
| 1283 |
$track['track_number'] = $tracknum->getTrackNumber();
|
| 1284 |
$track['title'] = $tracknum->getTitle();
|
| 1285 |
$track['carrier_code'] = $tracknum->getCarrierCode();
|
| 1286 |
$track['created_at'] = $tracknum->getCreatedAt();
|
| 1287 |
|
| 1288 |
-
$tracks[]
|
| 1289 |
}
|
| 1290 |
|
| 1291 |
}
|
| 1292 |
|
| 1293 |
-
$order_full_info = array(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1294 |
|
| 1295 |
return $order_full_info;
|
| 1296 |
} else return false;
|
| 1297 |
}
|
| 1298 |
|
| 1299 |
-
protected function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1300 |
return array(
|
| 1301 |
'st_id' => $status['status'],
|
| 1302 |
'st_name' => $status['label']
|
| 1303 |
);
|
| 1304 |
}
|
| 1305 |
|
| 1306 |
-
protected function get_orders_statuses()
|
|
|
|
| 1307 |
$statuses = Mage::getModel('sales/order_status')->getResourceCollection()->getData();
|
| 1308 |
|
| 1309 |
-
$final_statuses = array_map(
|
| 1310 |
|
| 1311 |
return $final_statuses;
|
| 1312 |
}
|
| 1313 |
|
| 1314 |
-
private function invoice_order()
|
|
|
|
| 1315 |
$order = Mage::getModel("sales/order")->load($this->order_id);
|
| 1316 |
$result = array('error' => $this->__('An error occurred!'));
|
| 1317 |
try {
|
| 1318 |
-
if($order->canInvoice())
|
| 1319 |
-
{
|
| 1320 |
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
| 1321 |
if ($invoice->getTotalQty()) {
|
| 1322 |
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
|
|
@@ -1338,37 +1482,36 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1338 |
$order->save();
|
| 1339 |
$result = array('error' => $this->__('Cannot create an invoice!'));
|
| 1340 |
}
|
| 1341 |
-
}
|
| 1342 |
-
catch (Mage_Core_Exception $e) {
|
| 1343 |
}
|
| 1344 |
|
| 1345 |
return $result;
|
| 1346 |
}
|
| 1347 |
|
| 1348 |
|
| 1349 |
-
private function ship_order()
|
|
|
|
| 1350 |
$result = array('error' => $this->__('An error occurred!'));
|
| 1351 |
$title = '';
|
| 1352 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1353 |
|
| 1354 |
-
if(isset($this->tracking_title) && strlen($this->tracking_title) > 0) {
|
| 1355 |
$title = $this->tracking_title;
|
| 1356 |
} else {
|
| 1357 |
$carriers = $this->get_carriers();
|
| 1358 |
|
| 1359 |
-
foreach($carriers as $carrier) {
|
| 1360 |
-
if($carrier['code'] == $this->carrier_code) {
|
| 1361 |
$title = $carrier['label'];
|
| 1362 |
}
|
| 1363 |
}
|
| 1364 |
}
|
| 1365 |
|
| 1366 |
-
if($order->hasShipments()) {
|
| 1367 |
-
foreach($order->getShipmentsCollection() as $shipment)
|
| 1368 |
-
{
|
| 1369 |
$shipmentIncrementId = $shipment->getIncrementId();
|
| 1370 |
-
if($shipmentIncrementId) {
|
| 1371 |
-
if(isset($this->tracking_number) && strlen($this->tracking_number) > 0 && isset($this->carrier_code) && strlen($this->carrier_code) > 0) {
|
| 1372 |
try {
|
| 1373 |
Mage::getModel('sales/order_shipment_api')->addTrack($shipmentIncrementId, $this->carrier_code, $title, $this->tracking_number);
|
| 1374 |
|
|
@@ -1378,26 +1521,24 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1378 |
}
|
| 1379 |
|
| 1380 |
$result = array('success' => 'true');
|
| 1381 |
-
}
|
| 1382 |
-
catch(Exception $e) {
|
| 1383 |
Mage::log(
|
| 1384 |
"error: Adding track number: {$e->getMessage()} ({$e->getCustomMessage()})",
|
| 1385 |
null,
|
| 1386 |
'emagicone_mobassistantconnector.log'
|
| 1387 |
);
|
| 1388 |
|
| 1389 |
-
$result = array('error' => $e->getMessage() . ' ('. $e->getCustomMessage() .')');
|
| 1390 |
}
|
| 1391 |
} else $result = array('error' => $this->__('Empty tracking number!'));
|
| 1392 |
}
|
| 1393 |
}
|
| 1394 |
-
}
|
| 1395 |
-
else if ($order->canShip()) {
|
| 1396 |
|
| 1397 |
$shipment = new Mage_Sales_Model_Order_Shipment_Api();
|
| 1398 |
$shipmentId = $shipment->create($order->getIncrementId());
|
| 1399 |
|
| 1400 |
-
if(isset($this->tracking_number) && strlen($this->tracking_number) > 0 && isset($this->carrier_code) && strlen($this->carrier_code) > 0) {
|
| 1401 |
$shipment->addTrack($shipmentId, $this->carrier_code, $title, $this->tracking_number);
|
| 1402 |
}
|
| 1403 |
|
|
@@ -1413,9 +1554,10 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1413 |
return $result;
|
| 1414 |
}
|
| 1415 |
|
| 1416 |
-
private function cancel_order()
|
|
|
|
| 1417 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1418 |
-
if($order->canCancel()) {
|
| 1419 |
$order->cancel();
|
| 1420 |
$order->addStatusHistoryComment('Order was canceled by MA', false);
|
| 1421 |
$order->save();
|
|
@@ -1429,9 +1571,10 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1429 |
return $result;
|
| 1430 |
}
|
| 1431 |
|
| 1432 |
-
private function hold_order()
|
|
|
|
| 1433 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1434 |
-
if($order->canHold()) {
|
| 1435 |
$order->hold();
|
| 1436 |
$order->addStatusHistoryComment('Order was holded by MA', false);
|
| 1437 |
$order->save();
|
|
@@ -1445,9 +1588,10 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1445 |
return $result;
|
| 1446 |
}
|
| 1447 |
|
| 1448 |
-
private function unhold_order()
|
|
|
|
| 1449 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1450 |
-
if($order->canUnhold()) {
|
| 1451 |
$order->unhold();
|
| 1452 |
$order->addStatusHistoryComment('Order was unholded by MA', false);
|
| 1453 |
$order->save();
|
|
@@ -1461,16 +1605,17 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1461 |
return $result;
|
| 1462 |
}
|
| 1463 |
|
| 1464 |
-
private function delete_track_number()
|
|
|
|
| 1465 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1466 |
$matches = 0;
|
| 1467 |
|
| 1468 |
$shipCollection = $order->getShipmentsCollection();
|
| 1469 |
-
if($shipCollection) {
|
| 1470 |
|
| 1471 |
-
foreach($shipCollection as $_ship) {
|
| 1472 |
$trackingNums = $_ship->getAllTracks();
|
| 1473 |
-
$matches
|
| 1474 |
if (count($trackingNums) >= 1) {
|
| 1475 |
foreach ($trackingNums as $track) {
|
| 1476 |
if ($track->getNumber() == $this->tracking_number) {
|
|
@@ -1480,7 +1625,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1480 |
}
|
| 1481 |
}
|
| 1482 |
}
|
| 1483 |
-
if($matches > 0) {
|
| 1484 |
$result = array('success' => 'true');
|
| 1485 |
} else $result = array('error' => $this->__('Current tracking number was not found'));
|
| 1486 |
|
|
@@ -1490,10 +1635,11 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1490 |
return $result;
|
| 1491 |
}
|
| 1492 |
|
| 1493 |
-
protected function set_order_action()
|
|
|
|
| 1494 |
$result = array('error' => $this->__('An error occurred!'));
|
| 1495 |
-
if(isset($this->order_id) && (intval($this->order_id) > 0)) {
|
| 1496 |
-
if(isset($this->action) && strlen($this->action) > 0) {
|
| 1497 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1498 |
if ($order->getId()) {
|
| 1499 |
switch ($this->action) {
|
|
@@ -1525,7 +1671,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1525 |
|
| 1526 |
protected function setOrder($attribute, $dir = self::SORT_ORDER_DESC)
|
| 1527 |
{
|
| 1528 |
-
if (in_array($attribute, array('carts', 'orders','ordered_qty'))) {
|
| 1529 |
$this->getSelect()->order($attribute . ' ' . $dir);
|
| 1530 |
} else {
|
| 1531 |
parent::setOrder($attribute, $dir);
|
|
@@ -1534,48 +1680,48 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1534 |
return $this;
|
| 1535 |
}
|
| 1536 |
|
| 1537 |
-
protected function get_carriers()
|
|
|
|
| 1538 |
$options = array();
|
| 1539 |
$originalCarriers = Mage::getSingleton('shipping/config')->getAllCarriers();
|
| 1540 |
|
| 1541 |
-
if(!$this->group_id) {
|
| 1542 |
$this->group_id = null;
|
| 1543 |
}
|
| 1544 |
$carriers = array();
|
| 1545 |
|
| 1546 |
-
|
| 1547 |
-
|
| 1548 |
-
|
| 1549 |
-
|
| 1550 |
-
|
| 1551 |
-
}
|
| 1552 |
}
|
|
|
|
| 1553 |
|
| 1554 |
-
|
| 1555 |
-
|
| 1556 |
-
|
| 1557 |
-
|
| 1558 |
-
|
| 1559 |
-
|
| 1560 |
-
|
| 1561 |
-
|
| 1562 |
-
|
| 1563 |
-
|
| 1564 |
-
|
| 1565 |
-
}
|
| 1566 |
}
|
| 1567 |
}
|
| 1568 |
-
}
|
| 1569 |
-
|
| 1570 |
-
|
| 1571 |
-
|
| 1572 |
-
|
| 1573 |
-
|
| 1574 |
-
|
| 1575 |
-
|
| 1576 |
-
|
| 1577 |
-
|
| 1578 |
-
|
| 1579 |
}
|
| 1580 |
}
|
| 1581 |
}
|
|
@@ -1583,20 +1729,20 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1583 |
}
|
| 1584 |
}
|
| 1585 |
}
|
|
|
|
| 1586 |
|
| 1587 |
|
| 1588 |
-
foreach($originalCarriers as $_code => $_method)
|
| 1589 |
-
|
| 1590 |
-
|
| 1591 |
-
if(!$_title = Mage::getStoreConfig("carriers/$_code/title"))
|
| 1592 |
$_title = $_code;
|
| 1593 |
-
$options[] = array('code' => $_code, 'label' => (strlen($_title)>0) ? $_title : $_title . " ($_code)");
|
| 1594 |
}
|
| 1595 |
}
|
| 1596 |
|
| 1597 |
|
| 1598 |
foreach ($options as $id => $option) {
|
| 1599 |
-
if(in_array($option['code'], array_keys($carriers))) {
|
| 1600 |
$options[$id]['label'] = $carriers[$option['code']];
|
| 1601 |
}
|
| 1602 |
}
|
|
@@ -1604,7 +1750,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1604 |
return $options;
|
| 1605 |
}
|
| 1606 |
|
| 1607 |
-
protected function get_customers()
|
|
|
|
| 1608 |
$offset = $this->_get_timezone_offset();
|
| 1609 |
|
| 1610 |
$customerCollection = Mage::getModel('customer/customer')->getCollection();
|
|
@@ -1613,7 +1760,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1613 |
$cust_attr_ids = $this->_get_customers_attr();
|
| 1614 |
|
| 1615 |
if (!empty($this->group_id)) {
|
| 1616 |
-
if($this->is_group_exists($this->group_id)) {
|
| 1617 |
$customerCollection->getSelect()
|
| 1618 |
->joinLeft(
|
| 1619 |
array('cs' => $storeTableName),
|
|
@@ -1622,20 +1769,20 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1622 |
}
|
| 1623 |
}
|
| 1624 |
|
| 1625 |
-
$customerCollection->getSelect()->joinLeft(array('firstname' => Mage::getConfig()->getTablePrefix().'customer_entity_varchar'),
|
| 1626 |
-
'e.entity_id = firstname.entity_id AND firstname.attribute_id = "'
|
| 1627 |
array('firstname' => 'value'));
|
| 1628 |
|
| 1629 |
-
$customerCollection->getSelect()->joinLeft(array('middlename' => Mage::getConfig()->getTablePrefix().'customer_entity_varchar'),
|
| 1630 |
-
'e.entity_id = middlename.entity_id AND middlename.attribute_id = "'
|
| 1631 |
array('middlename' => 'value'));
|
| 1632 |
|
| 1633 |
-
$customerCollection->getSelect()->joinLeft(array('lastname' => Mage::getConfig()->getTablePrefix().'customer_entity_varchar'),
|
| 1634 |
-
'e.entity_id = lastname.entity_id AND lastname.attribute_id = "'
|
| 1635 |
array('lastname' => 'value'));
|
| 1636 |
|
| 1637 |
$orderTableName = Mage::getSingleton('core/resource')->getTableName('sales/order');
|
| 1638 |
-
$customerCollection->getSelect()->joinLeft(
|
| 1639 |
|
| 1640 |
$customerCollection->getSelect()->columns(array('count_ords' => new Zend_Db_Expr ('COUNT(sfo.entity_id)')));
|
| 1641 |
|
|
@@ -1643,56 +1790,55 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1643 |
$customerCollection->getSelect()->columns(array('c_id' => new Zend_Db_Expr ('e.entity_id')));
|
| 1644 |
|
| 1645 |
$query = '';
|
| 1646 |
-
if(!empty($this->customers_from)) {
|
| 1647 |
-
$query_where_parts[] = sprintf(" (CONVERT_TZ(e.created_at, '+00:00', '"
|
| 1648 |
}
|
| 1649 |
-
if(!empty($this->customers_to)) {
|
| 1650 |
-
$query_where_parts[] = sprintf(" (CONVERT_TZ(e.created_at, '+00:00', '"
|
| 1651 |
}
|
| 1652 |
if (!empty($query_where_parts)) {
|
| 1653 |
-
$query .=
|
| 1654 |
$customerCollection->getSelect()->where($query);
|
| 1655 |
}
|
| 1656 |
|
| 1657 |
|
| 1658 |
-
if(!empty($this->search_val)) {
|
| 1659 |
-
$customerCollection->getSelect()->where("e.`email` LIKE '%"
|
| 1660 |
}
|
| 1661 |
|
| 1662 |
-
if(!empty($this->cust_with_orders)) {
|
| 1663 |
$customerCollection->getSelect()->having('count_ords > 0');
|
| 1664 |
}
|
| 1665 |
|
| 1666 |
-
if(empty($this->sort_by)) {
|
| 1667 |
$this->sort_by = "id";
|
| 1668 |
}
|
| 1669 |
|
| 1670 |
switch ($this->sort_by) {
|
| 1671 |
case 'name':
|
| 1672 |
-
$customerCollection->getSelect()->order(
|
| 1673 |
-
$customerCollection->getSelect()->order(
|
| 1674 |
break;
|
| 1675 |
case 'date':
|
| 1676 |
-
$customerCollection->getSelect()->order(
|
| 1677 |
break;
|
| 1678 |
case 'id':
|
| 1679 |
-
$customerCollection->getSelect()->order(
|
| 1680 |
break;
|
| 1681 |
}
|
| 1682 |
|
| 1683 |
|
| 1684 |
-
|
| 1685 |
$customers_count = count($customerCollection);
|
| 1686 |
-
if(!empty($this->page) && !empty($this->show)) {
|
| 1687 |
$customerCollection->clear();
|
| 1688 |
-
$customerCollection->getSelect()->limit($this->show, ($this->page-1)
|
| 1689 |
}
|
| 1690 |
|
| 1691 |
// echo($customerCollection->getSelect()->__toString());die();
|
| 1692 |
|
| 1693 |
-
$customers= array();
|
| 1694 |
|
| 1695 |
-
if($customers_count > ($this->page-1)
|
| 1696 |
foreach ($customerCollection as $customer) {
|
| 1697 |
|
| 1698 |
$reg_date = explode(' ', $customer->getCreatedAt());
|
|
@@ -1718,7 +1864,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1718 |
'customers' => $customers);
|
| 1719 |
}
|
| 1720 |
|
| 1721 |
-
protected function get_customers_info()
|
|
|
|
| 1722 |
$user_info = array('city' => '', 'postcode' => '', 'phone' => '', 'region' => '', 'country' => '', 'street' => '', 'country_name' => '');
|
| 1723 |
|
| 1724 |
$cust_attr_ids = $this->_get_customers_attr($this->user_id);
|
|
@@ -1736,9 +1883,9 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1736 |
|
| 1737 |
$customerAddressId = $customer->getDefaultBilling();
|
| 1738 |
|
| 1739 |
-
if($customerAddressId) {
|
| 1740 |
$address = Mage::getModel('customer/address')->load($customerAddressId)->toArray();
|
| 1741 |
-
if(count($address) > 1) {
|
| 1742 |
$user_info['city'] = $address['city'];
|
| 1743 |
$user_info['postcode'] = $address['postcode'];
|
| 1744 |
$user_info['phone'] = $address['telephone'];
|
|
@@ -1752,7 +1899,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1752 |
$user_info['address'] = $this->split_values($user_info, array('street', 'city', 'region', 'postcode', 'country_name'));
|
| 1753 |
unset($user_info['country_name']);
|
| 1754 |
|
| 1755 |
-
$ordersCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id'
|
| 1756 |
$ordersCollection->addAttributeToSelect('base_grand_total');
|
| 1757 |
$ordersCollection->addAttributeToSelect('entity_id');
|
| 1758 |
$ordersCollection->addAttributeToSelect('status');
|
|
@@ -1768,13 +1915,13 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1768 |
$ordersSum = $this->bd_nice_number($ordersSum);
|
| 1769 |
$row_page['sum_ords'] = $this->_price_format($this->def_currency, 1, $ordersSum, $this->currency_code, 0);
|
| 1770 |
|
| 1771 |
-
if(!empty($this->page) && !empty($this->show)) {
|
| 1772 |
$ordersCollection->clear();
|
| 1773 |
-
$ordersCollection->getSelect()->limit($this->show, ($this->page-1)
|
| 1774 |
}
|
| 1775 |
|
| 1776 |
$customer_orders = null;
|
| 1777 |
-
foreach($ordersCollection as $order) {
|
| 1778 |
$o_status_label = $order->getStatusLabel();
|
| 1779 |
$c_order['store_id'] = $order->getStore()->getId();
|
| 1780 |
$c_order['store_name'] = $order->getStore()->getName();
|
|
@@ -1801,7 +1948,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1801 |
return array('user_info' => $user_info, 'customer_orders' => $customer_orders, "c_orders_count" => intval($row_page['count_ords']), "sum_ords" => $row_page['sum_ords']);
|
| 1802 |
}
|
| 1803 |
|
| 1804 |
-
protected function _get_customers_attr($user_id = false)
|
|
|
|
| 1805 |
$customer_attrs = array('default_billing' => false, 'default_shipping' => false);
|
| 1806 |
$attributes = Mage::getResourceModel('customer/attribute_collection')->getItems();
|
| 1807 |
|
|
@@ -1817,7 +1965,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1817 |
}
|
| 1818 |
|
| 1819 |
|
| 1820 |
-
protected function search_products()
|
|
|
|
| 1821 |
$products = array();
|
| 1822 |
|
| 1823 |
$flatHelper = Mage::helper('catalog/product_flat');
|
|
@@ -1841,79 +1990,76 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1841 |
);
|
| 1842 |
|
| 1843 |
$filters = array();
|
| 1844 |
-
if(strlen($this->params) > 0){
|
| 1845 |
$this->params = explode("|", $this->params);
|
| 1846 |
|
| 1847 |
-
foreach($this->params as $param) {
|
| 1848 |
switch ($param) {
|
| 1849 |
case 'pr_id':
|
| 1850 |
-
if(isset($this->val) && strlen($this->val) > 0) {
|
| 1851 |
-
$filters[] = array('attribute' => 'entity_id', 'eq' => $this->val
|
| 1852 |
}
|
| 1853 |
break;
|
| 1854 |
case 'pr_sku':
|
| 1855 |
-
if(isset($this->val) && strlen($this->val) > 0) {
|
| 1856 |
-
$filters[] = array('attribute' => 'sku', 'like' => '%'
|
| 1857 |
}
|
| 1858 |
break;
|
| 1859 |
case 'pr_name':
|
| 1860 |
-
if(isset($this->val) && strlen($this->val) > 0) {
|
| 1861 |
-
$filters[] = array('attribute' => 'name', 'like' => '%'
|
| 1862 |
}
|
| 1863 |
break;
|
| 1864 |
case 'pr_desc':
|
| 1865 |
-
if(isset($this->val) && strlen($this->val) > 0) {
|
| 1866 |
-
$filters[] = array('attribute' => 'description', 'like' => '%'
|
| 1867 |
}
|
| 1868 |
break;
|
| 1869 |
case 'pr_short_desc':
|
| 1870 |
-
if(isset($this->val) && strlen($this->val) > 0) {
|
| 1871 |
-
$filters[] = array('attribute' => 'description', 'like' => '%'
|
| 1872 |
}
|
| 1873 |
break;
|
| 1874 |
}
|
| 1875 |
}
|
| 1876 |
|
| 1877 |
-
if(count($filters) > 0) {
|
| 1878 |
$collection->addFieldToFilter($filters);
|
| 1879 |
}
|
| 1880 |
}
|
| 1881 |
|
| 1882 |
|
| 1883 |
-
if($this->sort_by == 'name') {
|
| 1884 |
$filters[] = array('attribute' => 'name', 'like' => '%%');
|
| 1885 |
$collection->addFieldToFilter($filters);
|
| 1886 |
}
|
| 1887 |
|
| 1888 |
-
if(empty($this->sort_by)) {
|
| 1889 |
$this->sort_by = "id";
|
| 1890 |
}
|
| 1891 |
|
| 1892 |
switch ($this->sort_by) {
|
| 1893 |
case 'name':
|
| 1894 |
-
$collection->getSelect()->order(
|
| 1895 |
break;
|
| 1896 |
case 'id':
|
| 1897 |
-
$collection->getSelect()->order(
|
| 1898 |
break;
|
| 1899 |
}
|
| 1900 |
|
| 1901 |
$products_count = $collection->getSize();
|
| 1902 |
|
| 1903 |
-
if(!empty($this->page) && !empty($this->show)) {
|
| 1904 |
-
$collection->getSelect()->limit($this->show, ($this->page-1)
|
| 1905 |
}
|
| 1906 |
|
| 1907 |
-
foreach($collection as $product) {
|
| 1908 |
$productFinal['main_id'] = $product->getEntityId();
|
| 1909 |
$productFinal['product_id'] = $product->getEntityId();
|
| 1910 |
$productFinal['name'] = $product->getName();
|
| 1911 |
$productFinal['type_id'] = ucfirst($product->getTypeId());
|
| 1912 |
// Mage::helper('catalog/image')->init($product, 'thumbnail');
|
| 1913 |
-
|
| 1914 |
-
// $thumbnail = $product->getThumbnail();
|
| 1915 |
-
// var_dump($product->isVisibleInCatalog());
|
| 1916 |
-
// die();
|
| 1917 |
|
| 1918 |
$thumbnail = (string)Mage::helper('catalog/image')
|
| 1919 |
->init($product, 'image')
|
|
@@ -1924,7 +2070,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1924 |
// $productFinal['thumbnail'] = $product->getMediaConfig()->getMediaUrl($thumbnail);
|
| 1925 |
$productFinal['thumbnail'] = $thumbnail;
|
| 1926 |
|
| 1927 |
-
if(($thumbnail == 'no_selection') || (!isset($thumbnail))) {
|
| 1928 |
$productFinal['thumbnail'] = '';
|
| 1929 |
}
|
| 1930 |
|
|
@@ -1935,7 +2081,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1935 |
|
| 1936 |
$productFinal['price'] = $this->_price_format($this->def_currency, 1, $pArr['price'], $this->currency_code);
|
| 1937 |
|
| 1938 |
-
if($pArr['spec_price'] > 0 && $pArr['spec_price'] != '') {
|
| 1939 |
$productFinal['spec_price'] = $this->_price_format($this->def_currency, 1, $pArr['spec_price'], $this->currency_code);
|
| 1940 |
} else {
|
| 1941 |
unset($productFinal['spec_price']);
|
|
@@ -1948,7 +2094,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1948 |
'products' => $products);
|
| 1949 |
}
|
| 1950 |
|
| 1951 |
-
protected function search_products_ordered()
|
|
|
|
| 1952 |
|
| 1953 |
$ordered_products = array();
|
| 1954 |
$max_date = "";
|
|
@@ -1975,7 +2122,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1975 |
array());
|
| 1976 |
|
| 1977 |
if (!empty($this->group_id)) {
|
| 1978 |
-
if($this->is_group_exists($this->group_id)) {
|
| 1979 |
$salesCollection->getSelect()
|
| 1980 |
->joinLeft(
|
| 1981 |
array('cs' => $storeTableName),
|
|
@@ -1987,29 +2134,29 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 1987 |
|
| 1988 |
$salesCollection->getSelect()->columns(array('iso_code' => new Zend_Db_Expr ('order.global_currency_code')));
|
| 1989 |
$salesCollection->getSelect()->columns(array('status' => new Zend_Db_Expr ('order.status')));
|
| 1990 |
-
$salesCollection->getSelect()->columns(array('created_at' => new Zend_Db_Expr ("CONVERT_TZ(order.created_at, '+00:00', '"
|
| 1991 |
|
| 1992 |
-
if(strlen($this->val) > 0) {
|
| 1993 |
$filter_cols = array();
|
| 1994 |
$filters = array();
|
| 1995 |
-
if(strlen($this->params) > 0) {
|
| 1996 |
$this->params = explode("|", $this->params);
|
| 1997 |
-
foreach($this->params as $param) {
|
| 1998 |
switch ($param) {
|
| 1999 |
case 'pr_id':
|
| 2000 |
-
$filter_cols[] = 'main_table'.'.product_id';
|
| 2001 |
$filters[] = array('eq' => $this->val);
|
| 2002 |
break;
|
| 2003 |
case 'pr_sku':
|
| 2004 |
-
$filter_cols[] = 'main_table'.'.sku';
|
| 2005 |
-
$filters[] = array('like' => '%'
|
| 2006 |
break;
|
| 2007 |
case 'pr_name':
|
| 2008 |
-
$filter_cols[] = 'main_table'.'.name';
|
| 2009 |
-
$filters[] = array('like' => '%'
|
| 2010 |
break;
|
| 2011 |
case 'order_id':
|
| 2012 |
-
$filter_cols[] = 'main_table'.'.order_id';
|
| 2013 |
$filters[] = array('eq' => $this->val);
|
| 2014 |
break;
|
| 2015 |
}
|
|
@@ -2018,12 +2165,12 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2018 |
}
|
| 2019 |
}
|
| 2020 |
|
| 2021 |
-
if(!empty($this->products_from)) {
|
| 2022 |
$this->products_from .= " 00:00:00";
|
| 2023 |
$date_filter['from'] = $this->products_from;
|
| 2024 |
}
|
| 2025 |
|
| 2026 |
-
if(!empty($this->products_to)) {
|
| 2027 |
$this->products_to .= " 23:59:59";
|
| 2028 |
$date_filter['to'] = $this->products_to;
|
| 2029 |
}
|
|
@@ -2031,34 +2178,34 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2031 |
$date_filter['date'] = true;
|
| 2032 |
|
| 2033 |
|
| 2034 |
-
if(!empty($this->products_from) || !empty($this->products_to)) {
|
| 2035 |
-
$salesCollection->addFieldToFilter('order'.'.created_at',
|
| 2036 |
-
$date_filter
|
| 2037 |
}
|
| 2038 |
|
| 2039 |
-
if(!empty($this->statuses)) {
|
| 2040 |
$this->statuses = explode('|', $this->statuses);
|
| 2041 |
-
$salesCollection->addFieldToFilter('order'.'.status',
|
| 2042 |
-
array('in' => array($this->statuses))
|
| 2043 |
}
|
| 2044 |
|
| 2045 |
switch ($this->sort_by) {
|
| 2046 |
case 'name':
|
| 2047 |
-
$salesCollection->getSelect()->order(
|
| 2048 |
break;
|
| 2049 |
case 'id':
|
| 2050 |
-
$salesCollection->getSelect()->order(
|
| 2051 |
break;
|
| 2052 |
}
|
| 2053 |
|
| 2054 |
-
if(!empty($this->page) && !empty($this->show)) {
|
| 2055 |
-
$salesCollection->getSelect()->limit($this->show, ($this->page-1)
|
| 2056 |
}
|
| 2057 |
|
| 2058 |
-
$ordersDates = $salesCollection->getColumnValues('order'.'.created_at');
|
| 2059 |
$ordersDates = array_map("strtotime", $ordersDates);
|
| 2060 |
|
| 2061 |
-
if($salesCollection->count() > 0) {
|
| 2062 |
$max_date = date("n/j/Y", max(array_values($ordersDates)));
|
| 2063 |
$min_date = date("n/j/Y", min(array_values($ordersDates)));
|
| 2064 |
}
|
|
@@ -2071,18 +2218,18 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2071 |
->keepAspectRatio(TRUE)
|
| 2072 |
->resize(150, null);
|
| 2073 |
|
| 2074 |
-
|
| 2075 |
-
|
| 2076 |
|
| 2077 |
-
if(($thumbnail == 'no_selection') || (!isset($thumbnail))) {
|
| 2078 |
$thumbnail = '';
|
| 2079 |
}
|
| 2080 |
|
| 2081 |
$ord_prodArr = $order->toArray();
|
| 2082 |
-
$ord_prodArr['thumbnail'] = $thumbnail;
|
| 2083 |
|
|
|
|
| 2084 |
$ord_prodArr['price'] = $this->_price_format($ord_prodArr['iso_code'], 1, $ord_prodArr['price'], $this->currency_code);
|
| 2085 |
-
if($ord_prodArr['orig_price'] > 0) {
|
| 2086 |
$ord_prodArr['orig_price'] = $this->_price_format($ord_prodArr['iso_code'], 1, $ord_prodArr['orig_price'], $this->currency_code);
|
| 2087 |
} else {
|
| 2088 |
unset($ord_prodArr['orig_price']);
|
|
@@ -2106,85 +2253,82 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2106 |
}
|
| 2107 |
|
| 2108 |
|
| 2109 |
-
protected function get_products_info()
|
| 2110 |
-
|
| 2111 |
-
if ($flatHelper->isEnabled()) {
|
| 2112 |
-
$emulationModel = Mage::getModel('core/app_emulation');
|
| 2113 |
-
$initialEnvironmentInfo = $emulationModel->startEnvironmentEmulation(0, Mage_Core_Model_App_Area::AREA_ADMINHTML);
|
| 2114 |
-
}
|
| 2115 |
-
$prods_attr_ids = $this->_get_products_attr();
|
| 2116 |
$row = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2117 |
|
| 2118 |
-
|
| 2119 |
-
|
| 2120 |
-
|
| 2121 |
-
|
| 2122 |
-
|
| 2123 |
-
|
| 2124 |
-
$productsCollection->getSelect()->columns(array('name' => new Zend_Db_Expr ('name.value')));
|
| 2125 |
-
$productsCollection->getSelect()->columns(array('price' => new Zend_Db_Expr ('price.value')));
|
| 2126 |
-
$productsCollection->getSelect()->columns(array('spec_price' => new Zend_Db_Expr ('sp_price.value')));
|
| 2127 |
-
$productsCollection->getSelect()->columns(array('quantity' => new Zend_Db_Expr ('qty.qty')));
|
| 2128 |
-
$productsCollection->getSelect()->columns(array('sku' => new Zend_Db_Expr ('e.sku')));
|
| 2129 |
-
$productsCollection->getSelect()->columns(array('active' => new Zend_Db_Expr ("IF(status.value = 1, 'Enabled', 'Disabled')")));
|
| 2130 |
-
|
| 2131 |
-
$productsCollection->getSelect()->columns(array('total_ordered' => new Zend_Db_Expr ("(SELECT SUM(qty_ordered) FROM ".Mage::getConfig()->getTablePrefix()."sales_flat_order_item WHERE product_id = e.entity_id)")));
|
| 2132 |
-
$productsCollection->getSelect()->columns(array('image' => new Zend_Db_Expr ("(SELECT value FROM ".Mage::getConfig()->getTablePrefix()."catalog_product_entity_media_gallery WHERE entity_id = e.entity_id ORDER BY value_id LIMIT 1)")));
|
| 2133 |
-
|
| 2134 |
-
|
| 2135 |
-
$productsCollection->getSelect()->joinLeft(array('name' => Mage::getConfig()->getTablePrefix().'catalog_product_entity_varchar'),
|
| 2136 |
-
'e.entity_id = name.entity_id AND name.attribute_id = "'.$prods_attr_ids['name'].'"',
|
| 2137 |
-
array(''));
|
| 2138 |
-
|
| 2139 |
-
$productsCollection->getSelect()->joinLeft(array('price' => Mage::getConfig()->getTablePrefix().'catalog_product_entity_decimal'),
|
| 2140 |
-
'e.entity_id = price.entity_id AND price.attribute_id = "'.$prods_attr_ids['price'].'"',
|
| 2141 |
-
array('value'));
|
| 2142 |
-
|
| 2143 |
-
$productsCollection->getSelect()->joinLeft(array('sp_price' => Mage::getConfig()->getTablePrefix().'catalog_product_entity_decimal'),
|
| 2144 |
-
'e.entity_id = sp_price.entity_id AND sp_price.attribute_id = "'.$prods_attr_ids['special_price'].'"',
|
| 2145 |
-
array('value'));
|
| 2146 |
-
|
| 2147 |
-
$productsCollection->getSelect()->joinLeft(array('qty' => Mage::getConfig()->getTablePrefix().'cataloginventory_stock_item'),
|
| 2148 |
-
'e.entity_id = qty.product_id',
|
| 2149 |
-
array('qty'));
|
| 2150 |
-
|
| 2151 |
-
$productsCollection->getSelect()->joinLeft(array('descr' => Mage::getConfig()->getTablePrefix().'catalog_product_entity_varchar'),
|
| 2152 |
-
'e.entity_id = descr.entity_id AND descr.attribute_id = "'.$prods_attr_ids['description'].'"',
|
| 2153 |
-
array('value'));
|
| 2154 |
-
|
| 2155 |
-
$productsCollection->getSelect()->joinLeft(array('short_desc' => Mage::getConfig()->getTablePrefix().'catalog_product_entity_text'),
|
| 2156 |
-
'e.entity_id = short_desc.entity_id AND short_desc.attribute_id = "'.$prods_attr_ids['short_description'].'"',
|
| 2157 |
-
array('value'));
|
| 2158 |
-
|
| 2159 |
-
$productsCollection->getSelect()->joinLeft(array('status' => Mage::getConfig()->getTablePrefix().'catalog_product_entity_int'),
|
| 2160 |
-
'e.entity_id = status.entity_id AND status.attribute_id = "'.$prods_attr_ids['status'].'"',
|
| 2161 |
-
array('value'));
|
| 2162 |
-
|
| 2163 |
-
$productsCollection->addFieldToFilter('entity_id', array(
|
| 2164 |
-
'eq' => $this->product_id,
|
| 2165 |
-
));
|
| 2166 |
-
|
| 2167 |
-
if($productsCollection->getSize() > 0) {
|
| 2168 |
-
// echo($productsCollection->getSelect()->__toString());die();
|
| 2169 |
-
foreach ($productsCollection as $product) {
|
| 2170 |
-
$row = $product->toArray();
|
| 2171 |
-
unset($row['stock_item']);
|
| 2172 |
-
unset($row['value']);
|
| 2173 |
-
unset($row['qty']);
|
| 2174 |
|
| 2175 |
-
$row['id_image'] = (string)Mage::helper('catalog/image')->init($product, 'image')->resize(256);
|
| 2176 |
-
$row['id_image_large'] = (string)Mage::helper('catalog/image')->init($product, 'image')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(800);
|
| 2177 |
|
| 2178 |
-
$row['
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2179 |
$row['price'] = $this->_price_format($this->def_currency, 1, $row['price'], $this->currency_code);
|
| 2180 |
-
if($row['spec_price'] > 0 && $row['spec_price'] != '') {
|
|
|
|
| 2181 |
$row['spec_price'] = $this->_price_format($this->def_currency, 1, $row['spec_price'], $this->currency_code);
|
| 2182 |
} else {
|
| 2183 |
unset($row['spec_price']);
|
| 2184 |
}
|
| 2185 |
-
$row['quantity'] = intval($row['quantity']);
|
| 2186 |
-
$row['total_ordered'] = intval($row['total_ordered']);
|
| 2187 |
|
|
|
|
|
|
|
| 2188 |
}
|
| 2189 |
|
| 2190 |
return $row;
|
|
@@ -2193,12 +2337,13 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2193 |
return false;
|
| 2194 |
}
|
| 2195 |
|
| 2196 |
-
protected function _get_products_attr()
|
|
|
|
| 2197 |
$products_attrs = array();
|
| 2198 |
$productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');
|
| 2199 |
foreach ($productAttrs as $productAttr) {
|
| 2200 |
$attr_code = $productAttr->getAttributeCode();
|
| 2201 |
-
if(in_array($attr_code, array('name', 'price', 'special_price', 'description', 'short_description', 'status'))){
|
| 2202 |
$products_attrs[$attr_code] = $productAttr->getId();
|
| 2203 |
}
|
| 2204 |
}
|
|
@@ -2206,13 +2351,15 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2206 |
return $products_attrs;
|
| 2207 |
}
|
| 2208 |
|
| 2209 |
-
protected function get_products_descr()
|
|
|
|
| 2210 |
$product = Mage::getModel('catalog/product')->load($this->product_id);
|
| 2211 |
|
| 2212 |
return array('descr' => $product->getDescription(), 'short_descr' => $product->getShortDescription());
|
| 2213 |
}
|
| 2214 |
|
| 2215 |
-
protected function isEnabledFlat()
|
|
|
|
| 2216 |
if (Mage::app()->getStore()->isAdmin()) {
|
| 2217 |
return false;
|
| 2218 |
}
|
|
@@ -2223,7 +2370,68 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2223 |
return $this->_flatEnabled[$this->getStoreId()];
|
| 2224 |
}
|
| 2225 |
|
| 2226 |
-
protected function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2227 |
$abandoned_carts = array();
|
| 2228 |
$offset = $this->_get_timezone_offset();
|
| 2229 |
|
|
@@ -2234,7 +2442,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2234 |
$quotes = Mage::getResourceModel('sales/quote_collection');
|
| 2235 |
|
| 2236 |
if (!isset($this->group_id)) {
|
| 2237 |
-
if($this->is_group_exists($this->group_id)) {
|
| 2238 |
$quotes->getSelect()
|
| 2239 |
->joinLeft(
|
| 2240 |
array('cs' => $storeTableName),
|
|
@@ -2249,8 +2457,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2249 |
}
|
| 2250 |
if (!empty($this->search_val) && preg_match('/^\d+(?:,\d+)*$/', $this->search_val)) {
|
| 2251 |
$quotes->addAttributeToFilter('main_table.entity_id', array('eq' => intval($this->search_val)));
|
| 2252 |
-
} else if(!empty($this->search_val)) {
|
| 2253 |
-
$quotes->getSelect()->where("main_table.`customer_email` LIKE '%"
|
| 2254 |
}
|
| 2255 |
|
| 2256 |
if (!empty($this->carts_from)) {
|
|
@@ -2290,23 +2498,23 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2290 |
|
| 2291 |
// $quotes->clear();
|
| 2292 |
|
| 2293 |
-
if(!empty($this->page) && !empty($this->show)) {
|
| 2294 |
$quotes->clear();
|
| 2295 |
-
$quotes->getSelect()->limit($this->show, ($this->page-1)
|
| 2296 |
}
|
| 2297 |
|
| 2298 |
switch ($this->sort_by) {
|
| 2299 |
case 'id':
|
| 2300 |
-
$quotes->getSelect()->order(
|
| 2301 |
break;
|
| 2302 |
case 'date':
|
| 2303 |
-
$quotes->getSelect()->order(
|
| 2304 |
break;
|
| 2305 |
case 'name':
|
| 2306 |
-
$quotes->getSelect()->order(
|
| 2307 |
break;
|
| 2308 |
default:
|
| 2309 |
-
$quotes->getSelect()->order(
|
| 2310 |
break;
|
| 2311 |
}
|
| 2312 |
$carts = array();
|
|
@@ -2315,7 +2523,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2315 |
if (empty($this->show_unregistered_customers)) {
|
| 2316 |
// Show only real customers
|
| 2317 |
$customer_id = $quote->getCustomer()->getId();
|
| 2318 |
-
if(empty($customer_id)) {
|
| 2319 |
continue;
|
| 2320 |
}
|
| 2321 |
}
|
|
@@ -2330,11 +2538,11 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2330 |
$cart['id_customer'] = $quote->getCustomerId();
|
| 2331 |
|
| 2332 |
$cart['email'] = $quote->getCustomerEmail();
|
| 2333 |
-
$cart['customer'] = $quote->getCustomerFirstname() . ' '
|
| 2334 |
|
| 2335 |
-
if(!is_null($quote->getCustomer()->getId())){
|
| 2336 |
$cart['email'] = $quote->getCustomer()->getEmail();
|
| 2337 |
-
$cart['customer'] = $quote->getCustomer()->getFirstname() . ' '
|
| 2338 |
}
|
| 2339 |
|
| 2340 |
if ($storeName = Mage::getModel('core/store')->load($quote->getStoreId())->getName())
|
|
@@ -2354,10 +2562,10 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2354 |
}
|
| 2355 |
|
| 2356 |
// Sort by name
|
| 2357 |
-
if($this->sort_by == 'name') {
|
| 2358 |
-
foreach($carts as $cart){
|
| 2359 |
-
foreach($cart as $key
|
| 2360 |
-
if(!isset($sortArray[$key])){
|
| 2361 |
$sortArray[$key] = array();
|
| 2362 |
}
|
| 2363 |
$sortArray[$key][] = $value;
|
|
@@ -2366,7 +2574,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2366 |
|
| 2367 |
$orderby = "customer"; //change this to whatever key you want from the array
|
| 2368 |
|
| 2369 |
-
array_multisort($sortArray[$orderby],SORT_ASC
|
| 2370 |
}
|
| 2371 |
|
| 2372 |
return array('abandoned_carts' => $carts,
|
|
@@ -2377,7 +2585,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2377 |
return $quote;
|
| 2378 |
}
|
| 2379 |
|
| 2380 |
-
protected function get_abandoned_cart_details()
|
|
|
|
| 2381 |
$cart_info = array();
|
| 2382 |
$cart_products = array();
|
| 2383 |
|
|
@@ -2391,7 +2600,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2391 |
$quotes = Mage::getResourceModel('reports/quote_collection');
|
| 2392 |
|
| 2393 |
if (!isset($this->group_id)) {
|
| 2394 |
-
if($this->is_group_exists($this->group_id)) {
|
| 2395 |
$quotes->getSelect()
|
| 2396 |
->joinLeft(
|
| 2397 |
array('cs' => $storeTableName),
|
|
@@ -2408,8 +2617,8 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2408 |
// $quotes->addFieldToFilter('is_active', array('eq' => 1));
|
| 2409 |
// $quotes->addFieldToFilter('items_count', array('qt' => 1));
|
| 2410 |
|
| 2411 |
-
if(!empty($this->page) && !empty($this->show)) {
|
| 2412 |
-
$quotes->getSelect()->limit($this->show, ($this->page-1)
|
| 2413 |
}
|
| 2414 |
|
| 2415 |
foreach ($quotes as $quote) {
|
|
@@ -2427,19 +2636,19 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2427 |
|
| 2428 |
$cart_info['id_customer'] = $quote->getCustomerId();
|
| 2429 |
$cart_info['email'] = $quote->getCustomerEmail();
|
| 2430 |
-
$cart_info['customer'] = $quote->getCustomerFirstname() . ' '
|
| 2431 |
|
| 2432 |
$cart_info['phone'] = '';
|
| 2433 |
|
| 2434 |
-
if(!is_null($quote->getCustomer()->getId())){
|
| 2435 |
$cart_info['email'] = $quote->getCustomer()->getEmail();
|
| 2436 |
-
$cart_info['customer'] = $quote->getCustomer()->getFirstname() . ' '
|
| 2437 |
$cart_info['account_registered'] = $quote->getCustomer()->getCreatedAt();
|
| 2438 |
$customer = Mage::getModel('customer/customer')->load($quote->getCustomer()->getId());
|
| 2439 |
$customerAddressId = $customer->getDefaultBilling();
|
| 2440 |
-
if($customerAddressId) {
|
| 2441 |
$address = Mage::getModel('customer/address')->load($customerAddressId)->toArray();
|
| 2442 |
-
if(count($address) > 1) {
|
| 2443 |
$cart_info['phone'] = $address['telephone'];
|
| 2444 |
}
|
| 2445 |
}
|
|
@@ -2462,7 +2671,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2462 |
|
| 2463 |
$itemsCollection = $quote->getItemsCollection();
|
| 2464 |
foreach ($itemsCollection as $item) {
|
| 2465 |
-
if(!is_null($item->getParentItem())){
|
| 2466 |
continue;
|
| 2467 |
}
|
| 2468 |
$product = array();
|
|
@@ -2481,21 +2690,20 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2481 |
->keepAspectRatio(TRUE)
|
| 2482 |
->resize(150, null);
|
| 2483 |
|
| 2484 |
-
if(($thumbnail == 'no_selection') || (!isset($thumbnail))) {
|
| 2485 |
$thumbnail = '';
|
| 2486 |
}
|
| 2487 |
-
|
| 2488 |
$product['product_image'] = $thumbnail;
|
| 2489 |
|
| 2490 |
$buy_request = $item->getBuyRequest()->getData();
|
| 2491 |
|
| 2492 |
|
| 2493 |
-
if(isset($buy_request['super_attribute'])){
|
| 2494 |
$attribute_ids = $buy_request['super_attribute'];
|
| 2495 |
foreach ($attribute_ids as $att_id => $opt_id) {
|
| 2496 |
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($att_id);
|
| 2497 |
-
foreach($attribute->getSource()->getAllOptions() as $option) {
|
| 2498 |
-
if($option['value'] == $opt_id){
|
| 2499 |
$att[$attribute->getName()] = $option['label'];
|
| 2500 |
}
|
| 2501 |
}
|
|
@@ -2508,10 +2716,10 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2508 |
// Get option ids
|
| 2509 |
$item_options = $item->getOptions();
|
| 2510 |
|
| 2511 |
-
foreach($item_options as $option){
|
| 2512 |
$options[$option->getLabel] = $option->getValue();
|
| 2513 |
$code = $option->getCode();
|
| 2514 |
-
if($code == 'option_ids'){
|
| 2515 |
$dropdown_option_ids = explode(',', $option->getValue());
|
| 2516 |
|
| 2517 |
foreach ($dropdown_option_ids as $id) {
|
|
@@ -2523,7 +2731,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2523 |
// Get option values ids
|
| 2524 |
foreach ($item_options as $option) {
|
| 2525 |
foreach ($product['option_ids'] as $option_id => $value) {
|
| 2526 |
-
if($option->getCode() == 'option_'
|
| 2527 |
$product['option_ids'][$option_id] = $option->getValue();
|
| 2528 |
}
|
| 2529 |
}
|
|
@@ -2536,11 +2744,11 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2536 |
$product_options = $item->getProduct()->getOptions();
|
| 2537 |
foreach ($product_options as $option) {
|
| 2538 |
foreach ($product['option_ids'] as $option_id => $option_value) {
|
| 2539 |
-
if($option->getOptionId() == $option_id){
|
| 2540 |
$product['prod_options'][$option->getTitle()] = '';
|
| 2541 |
$option_values = $option->getValues();
|
| 2542 |
foreach ($option_values as $value) {
|
| 2543 |
-
if($value->getOptionTypeId() == $option_value){
|
| 2544 |
$product['prod_options'][$option->getTitle()] = $value->getTitle();
|
| 2545 |
// $product['prod_options'][$option->getTitle()]['price'] = $value->getPrice();
|
| 2546 |
}
|
|
@@ -2563,22 +2771,23 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2563 |
);
|
| 2564 |
}
|
| 2565 |
|
| 2566 |
-
protected function _price_format($iso_code, $curr_format, $price, $convert_to, $force = false, $format = true)
|
|
|
|
| 2567 |
$currency_symbol = '';
|
| 2568 |
$price = str_replace(' ', '', $price);
|
| 2569 |
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
|
| 2570 |
|
| 2571 |
-
if(!in_array(ucwords($convert_to), Mage::getModel('directory/currency')->getConfigAllowCurrencies())) {
|
| 2572 |
$convert_to = $baseCurrencyCode;
|
| 2573 |
}
|
| 2574 |
|
| 2575 |
-
if(strlen($convert_to) == 3){
|
| 2576 |
try {
|
| 2577 |
$price = Mage::helper('directory')->currencyConvert($price, $baseCurrencyCode, $convert_to);
|
| 2578 |
$iso_code = $convert_to;
|
| 2579 |
-
} catch(Exception $e) {
|
| 2580 |
Mage::log(
|
| 2581 |
-
"Error while currency converting (". var_export($e->getMessage(), true). ")",
|
| 2582 |
null,
|
| 2583 |
'emagicone_mobassistantconnector.log'
|
| 2584 |
);
|
|
@@ -2586,25 +2795,25 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2586 |
|
| 2587 |
}
|
| 2588 |
|
| 2589 |
-
if($format) {
|
| 2590 |
$price = number_format(floatval($price), 2, '.', ' ');
|
| 2591 |
}
|
| 2592 |
|
| 2593 |
preg_match('/^[a-zA-Z]+$/', $iso_code, $matches);
|
| 2594 |
|
| 2595 |
-
if(count($matches) > 0) {
|
| 2596 |
-
if(strlen($matches[0]) == 3) {
|
| 2597 |
$currency_symbol = Mage::app()->getLocale()->currency($iso_code)->getSymbol();
|
| 2598 |
}
|
| 2599 |
} else {
|
| 2600 |
$currency_symbol = $iso_code;
|
| 2601 |
}
|
| 2602 |
|
| 2603 |
-
if($force) {
|
| 2604 |
return $currency_symbol;
|
| 2605 |
}
|
| 2606 |
$sign = '<span>' . $currency_symbol . '</span>';
|
| 2607 |
-
if($curr_format == 1) {
|
| 2608 |
$price = $sign . $price;
|
| 2609 |
} elseif ($curr_format == 2) {
|
| 2610 |
$price = $price;
|
|
@@ -2618,34 +2827,36 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2618 |
}
|
| 2619 |
|
| 2620 |
|
| 2621 |
-
protected function _get_default_currency()
|
|
|
|
| 2622 |
$symbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getBaseCurrencyCode())->getSymbol();
|
| 2623 |
$currency = Mage::app()->getStore()->getBaseCurrencyCode();
|
| 2624 |
return array('currency' => $currency, 'symbol' => $symbol);
|
| 2625 |
}
|
| 2626 |
|
| 2627 |
-
protected function _get_store_currencies($storeId)
|
|
|
|
| 2628 |
$CurrencyCode = Mage::getModel('core/config_data')
|
| 2629 |
->getCollection()
|
| 2630 |
-
->addFieldToFilter('path','currency/options/allow')
|
| 2631 |
-
->addFieldToFilter('scope_id'
|
| 2632 |
->getData();
|
| 2633 |
-
$currencies_array = explode(','
|
| 2634 |
-
if($currencies_array[0] == '')
|
| 2635 |
-
|
| 2636 |
-
$currencies_array[]= Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
|
| 2637 |
}
|
| 2638 |
|
| 2639 |
foreach ($currencies_array as $curCode) {
|
| 2640 |
-
$currencySymbol = Mage::app()->getLocale()->currency(
|
| 2641 |
-
$currencyName = Mage::app()->getLocale()->currency(
|
| 2642 |
$currencies[] = array('code' => $curCode, 'symbol' => (is_null($currencySymbol) ? $curCode : $currencySymbol), 'name' => $currencyName);
|
| 2643 |
}
|
| 2644 |
|
| 2645 |
return $currencies;
|
| 2646 |
}
|
| 2647 |
|
| 2648 |
-
protected function _get_timezone_offset()
|
|
|
|
| 2649 |
$timezone = Mage::app()->getStore()->getConfig('general/locale/timezone');
|
| 2650 |
|
| 2651 |
|
|
@@ -2656,7 +2867,6 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2656 |
// $offset2 = (($hours >= 0) ? '+'.$hours : $hours) .':'. $mins;
|
| 2657 |
|
| 2658 |
|
| 2659 |
-
|
| 2660 |
$origin_dtz = new DateTimeZone("UTC");
|
| 2661 |
$remote_dtz = new DateTimeZone($timezone);
|
| 2662 |
$origin_dt = new DateTime("now", $origin_dtz);
|
|
@@ -2665,7 +2875,7 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2665 |
|
| 2666 |
$hours = intval($offset / 60 / 60);
|
| 2667 |
$mins = $offset / 60 % 60;
|
| 2668 |
-
$offset = (($hours >= 0) ? '+'
|
| 2669 |
//
|
| 2670 |
// $offset = $offset / 60 / 60;
|
| 2671 |
|
|
@@ -2673,15 +2883,17 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2673 |
}
|
| 2674 |
|
| 2675 |
|
| 2676 |
-
protected function reset_null(&$item)
|
| 2677 |
-
|
|
|
|
| 2678 |
$item = '';
|
| 2679 |
}
|
| 2680 |
$item = trim($item);
|
| 2681 |
}
|
| 2682 |
|
| 2683 |
|
| 2684 |
-
protected function validate_types(&$array, $names)
|
|
|
|
| 2685 |
foreach ($names as $name => $type) {
|
| 2686 |
if (isset($array["$name"])) {
|
| 2687 |
switch ($type) {
|
|
@@ -2715,29 +2927,30 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2715 |
}
|
| 2716 |
|
| 2717 |
|
| 2718 |
-
protected function get_custom_period($period = 0)
|
|
|
|
| 2719 |
$custom_period = array('start_date' => "", 'end_date' => "");
|
| 2720 |
$format = "m/d/Y";
|
| 2721 |
|
| 2722 |
-
switch($period) {
|
| 2723 |
case 0: //3 days
|
| 2724 |
-
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date("m"), date("d")-2, date("Y")));
|
| 2725 |
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date("m"), date("d"), date("Y")));
|
| 2726 |
break;
|
| 2727 |
|
| 2728 |
case 1: //7 days
|
| 2729 |
-
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date("m"), date("d")-6, date("Y")));
|
| 2730 |
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date("m"), date("d"), date("Y")));
|
| 2731 |
break;
|
| 2732 |
|
| 2733 |
case 2: //Prev week
|
| 2734 |
-
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date("n"), date("j")-6, date("Y")) - ((date("N"))*3600*24));
|
| 2735 |
-
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date("n"), date("j"), date("Y")) - ((date("N"))*3600*24));
|
| 2736 |
break;
|
| 2737 |
|
| 2738 |
case 3: //Prev month
|
| 2739 |
-
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date("m")-1, 1, date("Y")));
|
| 2740 |
-
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date("m"), date("d")-date("j"), date("Y")));
|
| 2741 |
break;
|
| 2742 |
|
| 2743 |
case 4: //This quarter
|
|
@@ -2745,32 +2958,61 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2745 |
$start_m = 1;
|
| 2746 |
$end_m = 3;
|
| 2747 |
|
| 2748 |
-
if($m <= 3) {
|
| 2749 |
$start_m = 1;
|
| 2750 |
$end_m = 3;
|
| 2751 |
-
} else if($m >= 4 && $m <= 6) {
|
| 2752 |
$start_m = 4;
|
| 2753 |
$end_m = 6;
|
| 2754 |
-
} else if($m >= 7 && $m <= 9) {
|
| 2755 |
$start_m = 7;
|
| 2756 |
$end_m = 9;
|
| 2757 |
-
} else if($m >= 10) {
|
| 2758 |
$start_m = 10;
|
| 2759 |
$end_m = 12;
|
| 2760 |
}
|
| 2761 |
|
| 2762 |
-
$custom_period['start_date'] = date($format, mktime(0, 0, 0, $start_m, 1
|
| 2763 |
-
$custom_period['end_date'] = date($format, mktime(23, 59, 59, $end_m+1, date(1)-1, date("Y")));
|
| 2764 |
break;
|
| 2765 |
|
| 2766 |
case 5: //This year
|
| 2767 |
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date(1), date(1), date("Y")));
|
| 2768 |
-
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date(1), date(1)-1, date("Y")+1));
|
| 2769 |
break;
|
| 2770 |
|
| 2771 |
case 7: //Last year
|
| 2772 |
-
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date(1), date(1), date("Y")-1));
|
| 2773 |
-
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date(1), date(1)-1, date("Y")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2774 |
break;
|
| 2775 |
}
|
| 2776 |
|
|
@@ -2778,39 +3020,40 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2778 |
}
|
| 2779 |
|
| 2780 |
|
| 2781 |
-
protected function bd_nice_number($n, $is_count = false)
|
|
|
|
| 2782 |
$n = floatval($n);
|
| 2783 |
|
| 2784 |
-
if(!is_numeric($n)) return $n;
|
| 2785 |
|
| 2786 |
$final_number = $n;
|
| 2787 |
$number_suf = "";
|
| 2788 |
// now filter it;
|
| 2789 |
-
if($n > 1000000000000000) {
|
| 2790 |
//return number_format(round(($n / 1000000000000000), 1), 1, '.', ' ') . 'P';
|
| 2791 |
$final_number = round(($n / 1000000000000000), 2);
|
| 2792 |
$number_suf = "P";
|
| 2793 |
|
| 2794 |
-
} else if($n > 1000000000000) {
|
| 2795 |
//return number_format(round(($n / 1000000000000),1), 1, '.', ' ') . 'T';
|
| 2796 |
$final_number = round(($n / 1000000000000), 2);
|
| 2797 |
$number_suf = "T";
|
| 2798 |
|
| 2799 |
-
} else if($n > 1000000000) {
|
| 2800 |
//return number_format(round(($n / 1000000000),1), 1, '.', ' ') . 'G';
|
| 2801 |
$final_number = round(($n / 1000000000), 2);
|
| 2802 |
$number_suf = "G";
|
| 2803 |
|
| 2804 |
-
} else if($n > 1000000) {
|
| 2805 |
//return number_format(round(($n / 1000000),1), 1, '.', ' ') . 'M';
|
| 2806 |
$final_number = round(($n / 1000000), 2);
|
| 2807 |
$number_suf = "M";
|
| 2808 |
|
| 2809 |
-
} else if($n > 10000) {
|
| 2810 |
return number_format($n, 0, '', ' ');
|
| 2811 |
}
|
| 2812 |
|
| 2813 |
-
if($is_count) {
|
| 2814 |
$final_number = intval($final_number);
|
| 2815 |
} else {
|
| 2816 |
$final_number = number_format($final_number, 2, '.', ' ') . $number_suf;
|
|
@@ -2819,11 +3062,12 @@ class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controll
|
|
| 2819 |
return $final_number;
|
| 2820 |
}
|
| 2821 |
|
| 2822 |
-
protected function split_values($arr, $keys, $sign = ', ')
|
|
|
|
| 2823 |
$new_arr = array();
|
| 2824 |
-
foreach($keys as $key) {
|
| 2825 |
-
if(isset($arr[$key])) {
|
| 2826 |
-
if(!is_null($arr[$key]) && $arr[$key] != '') {
|
| 2827 |
$new_arr[] = $arr[$key];
|
| 2828 |
}
|
| 2829 |
}
|
| 1 |
<?php
|
| 2 |
+
|
| 3 |
/**
|
| 4 |
* This file is part of Mobile Assistant Connector.
|
| 5 |
*
|
| 16 |
* You should have received a copy of the GNU General Public License
|
| 17 |
* along with Mobile Assistant Connector. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
*/
|
|
|
|
|
|
|
| 19 |
class Emagicone_Mobassistantconnector_IndexController extends Mage_Core_Controller_Front_Action
|
| 20 |
{
|
| 21 |
public $CartClass = "";
|
| 22 |
public $call_function;
|
| 23 |
public $callback;
|
| 24 |
+
public $hash = false;
|
| 25 |
public $def_currency;
|
| 26 |
public $currency_code;
|
| 27 |
+
private $hash_only;
|
| 28 |
+
private $session_key;
|
| 29 |
const GSM_URL = 'https://android.googleapis.com/gcm/send';
|
| 30 |
+
const MB_VERSION = '85';
|
| 31 |
|
| 32 |
+
public function indexAction()
|
| 33 |
+
{
|
| 34 |
Mage::app()->cleanCache();
|
| 35 |
+
if (intval(Mage::getStoreConfig('mobassistantconnectorinfosec/emogeneral/status')) != 1) $this->generate_output('module_disabled');
|
| 36 |
|
| 37 |
$this->loadLayout()->renderLayout();
|
| 38 |
|
| 39 |
$def_currency = $this->_get_default_currency();
|
| 40 |
$this->def_currency = $def_currency['currency'];
|
| 41 |
|
| 42 |
+
Mage::helper('mobassistantconnector/access')->clearOldData();
|
| 43 |
+
|
| 44 |
+
foreach ($this->getRequest()->getParams() as $key => $value) {
|
| 45 |
+
if (isset($key) && $key == 'callback' && isset($value) && strlen($value) > 0)
|
| 46 |
$this->callback = $value;
|
| 47 |
+
if (isset($key) && $key == 'call_function' && isset($value) && strlen($value) > 0)
|
| 48 |
$this->call_function = $value;
|
| 49 |
+
if (isset($key) && $key == 'hash' && isset($value) && strlen($value) > 0)
|
| 50 |
$this->hash = $value;
|
| 51 |
+
if (isset($key) && $key == 'key')
|
| 52 |
+
$this->session_key = $value;
|
| 53 |
+
if (isset($key) && $key == 'hash_only')
|
| 54 |
+
$this->hash_only = true;
|
| 55 |
}
|
| 56 |
|
| 57 |
+
// if(!$this->check_auth()) {
|
| 58 |
+
// $this->generate_output('auth_error');
|
| 59 |
+
// }
|
| 60 |
+
|
| 61 |
+
if ($this->call_function == 'get_version')
|
| 62 |
+
$this->generate_output(array('module_version' => self::MB_VERSION));
|
| 63 |
+
|
| 64 |
+
if ($this->hash) {
|
| 65 |
+
if ($this->hash_only && in_array($this->call_function, array('get_stores','get_orders_statuses','test_config','get_store_title','get_currencies'))) {
|
| 66 |
+
// If its real token
|
| 67 |
+
if (!$this->check_auth())
|
| 68 |
+
$this->generate_output('auth_error');
|
| 69 |
+
} else {
|
| 70 |
+
// Make token based on key
|
| 71 |
+
$key = Mage::helper('mobassistantconnector/access')->getSessionKey($this->hash);
|
| 72 |
+
|
| 73 |
+
if (!$key) {
|
| 74 |
+
Mage::log(
|
| 75 |
+
"Hash accepted ({$this->hash}) is incorrect",
|
| 76 |
+
null,
|
| 77 |
+
'emagicone_mobassistantconnector.log'
|
| 78 |
+
);
|
| 79 |
+
$this->generate_output('auth_error');
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
$this->generate_output(array('session_key' => $key, 'module_version' => self::MB_VERSION));
|
| 83 |
+
}
|
| 84 |
+
} elseif ($this->session_key || $this->session_key == '') {
|
| 85 |
+
if (!Mage::helper('mobassistantconnector/access')->checkSessionKey($this->session_key)) {
|
| 86 |
+
Mage::log(
|
| 87 |
+
"Key accepted ({$this->session_key}) is incorrect",
|
| 88 |
+
null,
|
| 89 |
+
'emagicone_mobassistantconnector.log'
|
| 90 |
+
);
|
| 91 |
+
$this->generate_output(array('bad_session_key' => true));
|
| 92 |
+
}
|
| 93 |
}
|
| 94 |
|
| 95 |
$request_params = Mage::app()->getRequest()->getParams();
|
| 96 |
+
|
| 97 |
$params = $this->validate_types($request_params, array(
|
| 98 |
'show' => 'INT',
|
| 99 |
'page' => 'INT',
|
| 146 |
'carts_to' => 'STR',
|
| 147 |
'cart_id' => 'STR',
|
| 148 |
'search_carts' => 'STR',
|
| 149 |
+
'param' => 'STR',
|
| 150 |
+
'new_value' => 'STR',
|
| 151 |
'show_unregistered_customers' => 'INT',
|
| 152 |
));
|
| 153 |
|
| 154 |
+
foreach ($params as $k => $value) {
|
| 155 |
$this->{$k} = $value;
|
| 156 |
}
|
| 157 |
|
| 158 |
+
if (empty($this->currency_code) || strval($this->currency_code) == 'base_currency' || strval($this->currency_code) == 'not_set') {
|
| 159 |
$this->currency_code = $this->def_currency;
|
| 160 |
}
|
| 161 |
|
| 162 |
+
if ($this->call_function == 'test_config') {
|
| 163 |
$this->generate_output(array('test' => 1));
|
| 164 |
}
|
| 165 |
|
| 166 |
$locale = Mage::app()->getLocale()->getLocaleCode();
|
| 167 |
Mage::app()->getTranslator()->setLocale($locale);
|
| 168 |
|
| 169 |
+
if (!method_exists($this, $this->call_function)) {
|
| 170 |
Mage::log(
|
| 171 |
"Unknown method call ({$this->call_function})",
|
| 172 |
null,
|
| 173 |
'emagicone_mobassistantconnector.log'
|
| 174 |
);
|
| 175 |
+
$this->generate_output('old_module');
|
| 176 |
}
|
| 177 |
|
| 178 |
$result = call_user_func(array($this, $this->call_function));
|
| 180 |
$this->generate_output($result);
|
| 181 |
}
|
| 182 |
|
| 183 |
+
/* public function soap_loginAction() {
|
| 184 |
+
// Magento login information
|
| 185 |
+
if(intval(Mage::getStoreConfig('mobassistantconnectorinfosec/emogeneral/status')) != 1) $this->generate_output('module_disabled');
|
| 186 |
+
|
| 187 |
+
$blah = Mage::getModel('admin/user')->authenticate('yaroslav@emagicone.com', '!Q2w#E4r');
|
| 188 |
+
|
| 189 |
+
$request_params = Mage::app()->getRequest()->getParams();
|
| 190 |
+
|
| 191 |
+
$mage_url = Mage::getBaseUrl().'/api/soap?wsdl';
|
| 192 |
+
// $mage_url = 'http://MAGENTO/api/soap?wsdl';
|
| 193 |
+
$soap_user = $request_params['soap_user'];
|
| 194 |
+
$soap_api_key = $request_params['soap_api_key'];
|
| 195 |
+
|
| 196 |
+
// Initialize the SOAP client
|
| 197 |
+
$soap = new SoapClient( $mage_url );
|
| 198 |
+
|
| 199 |
+
// Login to Magento
|
| 200 |
+
try {
|
| 201 |
+
$session_id = $soap->login( $soap_user, $soap_api_key );
|
| 202 |
+
$result = array('hash' => $session_id);
|
| 203 |
+
} catch(Exception $e) {
|
| 204 |
+
$result = array('error' => $e->getMessage());
|
| 205 |
+
|
| 206 |
+
Mage::log(
|
| 207 |
+
"Incorrect login data: ({$soap_user} {$soap_api_key})",
|
| 208 |
+
null,
|
| 209 |
+
'emagicone_mobassistantconnector.log'
|
| 210 |
+
);
|
| 211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
}
|
|
|
|
| 213 |
|
| 214 |
+
$this->generate_output($result);
|
|
|
|
| 215 |
}
|
| 216 |
|
| 217 |
+
protected function soap_check_session($sessionId) {
|
|
|
|
|
|
|
| 218 |
|
| 219 |
+
if (!Mage::getSingleton('api/session')->isLoggedIn($sessionId)) {
|
| 220 |
+
return false;
|
| 221 |
+
} else {
|
| 222 |
+
return true;
|
| 223 |
+
}
|
| 224 |
|
| 225 |
+
}*/
|
|
|
|
| 226 |
|
| 227 |
+
protected function generate_output($data)
|
| 228 |
+
{
|
| 229 |
+
if (!in_array($this->call_function, array("get_order_pdf"))) {
|
| 230 |
+
$add_bridge_version = false;
|
| 231 |
+
if (in_array($this->call_function, array("test_config", "get_store_title", "get_store_stats", "get_data_graphs"))) {
|
| 232 |
+
if (is_array($data) && $data != 'auth_error' && $data != 'connection_error' && $data != 'old_bridge') {
|
| 233 |
+
$add_bridge_version = true;
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
if (!is_array($data)) {
|
| 238 |
+
$data = array($data);
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
if (is_array($data)) {
|
| 242 |
+
array_walk_recursive($data, array($this, 'reset_null'));
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
if ($add_bridge_version) {
|
| 246 |
+
$data['module_version'] = self::MB_VERSION;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
// $data = $this->to_json($data);
|
| 250 |
+
$data = Mage::helper('core')->jsonEncode($data);
|
| 251 |
+
|
| 252 |
+
if ($this->callback) {
|
| 253 |
+
header('Content-Type: text/javascript;charset=utf-8');
|
| 254 |
+
die($this->callback . '(' . $data . ');');
|
| 255 |
+
} else {
|
| 256 |
+
header('Content-Type: text/javascript;charset=utf-8');
|
| 257 |
+
die($data);
|
| 258 |
+
}
|
| 259 |
}
|
| 260 |
+
|
| 261 |
+
die($data);
|
| 262 |
}
|
| 263 |
|
| 264 |
+
protected function check_auth()
|
| 265 |
+
{
|
| 266 |
$login = Mage::getStoreConfig('mobassistantconnectorinfosec/emoaccess/login');
|
| 267 |
$password = Mage::getStoreConfig('mobassistantconnectorinfosec/emoaccess/password');
|
| 268 |
|
| 269 |
+
if (hash('sha256', $login . $password) == $this->hash) {
|
| 270 |
return true;
|
| 271 |
} else {
|
| 272 |
Mage::log(
|
| 278 |
}
|
| 279 |
}
|
| 280 |
|
| 281 |
+
protected function push_notification_settings()
|
| 282 |
+
{
|
| 283 |
$result = array();
|
| 284 |
$statuses = array();
|
| 285 |
$matched = false;
|
| 286 |
$deviceActions = array('push_device_id' => '',
|
| 287 |
+
'push_new_order' => 0,
|
| 288 |
+
'push_order_statuses' => '',
|
| 289 |
+
'push_new_customer' => 0,
|
| 290 |
+
'app_connection_id' => -1,
|
| 291 |
+
'push_store_group_id' => -1,
|
| 292 |
+
'push_currency_code' => '');
|
| 293 |
|
| 294 |
$deviceIds = Mage::getStoreConfig('mobassistantconnectorinfosec/access/google_ids');
|
| 295 |
+
if (strlen($deviceIds) > 0) {
|
| 296 |
$deviceIds = unserialize($deviceIds);
|
| 297 |
} else $deviceIds = array();
|
| 298 |
|
| 299 |
+
foreach (array_keys($deviceIds) as $key) {
|
| 300 |
if (!is_int($key)) {
|
| 301 |
$deviceIds[$key]['push_device_id'] = $key;
|
| 302 |
+
if (empty($deviceIds[$key]['push_store_group_id'])) {
|
| 303 |
$deviceIds[$key]['push_store_group_id'] = -1;
|
| 304 |
}
|
| 305 |
array_push($deviceIds, $deviceIds[$key]);
|
| 307 |
}
|
| 308 |
}
|
| 309 |
|
| 310 |
+
if (strlen($this->registration_id) > 0 && strlen($this->api_key) > 0) {
|
| 311 |
|
| 312 |
+
if (strlen($this->registration_id) > 0) {
|
| 313 |
$deviceActions['push_device_id'] = $this->registration_id;
|
| 314 |
}
|
| 315 |
|
| 316 |
+
if (strlen($this->push_new_order) > 0) {
|
| 317 |
$deviceActions['push_new_order'] = $this->push_new_order;
|
| 318 |
+
} else {
|
| 319 |
$deviceActions['push_new_order'] = 0;
|
| 320 |
}
|
| 321 |
|
| 322 |
+
if (strlen($this->push_order_statuses) > 0) {
|
| 323 |
$deviceActions['push_order_statuses'] = $this->push_order_statuses;
|
| 324 |
+
} else {
|
| 325 |
$deviceActions['push_order_statuses'] = '';
|
| 326 |
}
|
| 327 |
|
| 328 |
+
if (strlen($this->push_new_customer) > 0) {
|
| 329 |
$deviceActions['push_new_customer'] = $this->push_new_customer;
|
| 330 |
+
} else {
|
| 331 |
$deviceActions['push_new_customer'] = 0;
|
| 332 |
}
|
| 333 |
|
| 334 |
+
if (!empty($this->store_group_id)) {
|
| 335 |
$deviceActions['push_store_group_id'] = $this->store_group_id;
|
| 336 |
+
} else {
|
| 337 |
$deviceActions['push_store_group_id'] = -1;
|
| 338 |
}
|
| 339 |
|
| 340 |
+
if (!empty($this->app_connection_id)) {
|
| 341 |
$deviceActions['app_connection_id'] = $this->app_connection_id;
|
| 342 |
+
} else {
|
| 343 |
$deviceActions['app_connection_id'] = -1;
|
| 344 |
}
|
| 345 |
|
| 346 |
+
if (strlen($this->push_currency_code) > 0) {
|
| 347 |
$deviceActions['push_currency_code'] = $this->push_currency_code;
|
| 348 |
+
} else if (strlen($this->currency_code) > 0) {
|
| 349 |
$deviceActions['push_currency_code'] = $this->currency_code;
|
| 350 |
} else {
|
| 351 |
$deviceActions['push_currency_code'] = 'base_currency';
|
| 352 |
}
|
| 353 |
|
| 354 |
// Delete empty record
|
| 355 |
+
if ((intval($this->push_new_order) == 0) && (strlen($this->push_order_statuses) == 0) && (intval($this->push_new_customer) == 0)) {
|
| 356 |
foreach ($deviceIds as $settingNum => $deviceId) {
|
| 357 |
+
if ($deviceId['push_device_id'] == $this->registration_id && (isset($deviceId['app_connection_id']) && $deviceId['app_connection_id'] == $deviceActions['app_connection_id'])) {
|
| 358 |
unset($deviceIds[$settingNum]);
|
| 359 |
+
} else if ($deviceId['push_device_id'] == $this->registration_id && $deviceId['push_store_group_id'] == $this->store_group_id && !isset($deviceId['app_connection_id'])) {
|
| 360 |
unset($deviceIds[$settingNum]);
|
| 361 |
}
|
| 362 |
}
|
| 363 |
} else {
|
| 364 |
// renew old record
|
| 365 |
foreach ($deviceIds as $settingNum => $deviceId) {
|
| 366 |
+
if ($deviceId['push_device_id'] == $this->registration_id && (isset($deviceId['app_connection_id']) && $deviceId['app_connection_id'] == $deviceActions['app_connection_id'])) {
|
| 367 |
$deviceIds[$settingNum] = $deviceActions;
|
| 368 |
$matched = true;
|
| 369 |
+
} else if ($deviceId['push_device_id'] == $this->registration_id && $deviceId['push_store_group_id'] == $deviceActions['push_store_group_id'] && !isset($deviceId['app_connection_id'])) {
|
| 370 |
$deviceIds[$settingNum] = $deviceActions;
|
| 371 |
$matched = true;
|
| 372 |
}
|
| 373 |
}
|
| 374 |
+
if (!$matched) {
|
| 375 |
// add new record
|
| 376 |
array_push($deviceIds, $deviceActions);
|
| 377 |
}
|
| 378 |
}
|
| 379 |
|
| 380 |
// Delete old registration id
|
| 381 |
+
if (isset($this->registration_id_old) && strlen($this->registration_id_old) > 0) {
|
| 382 |
foreach ($deviceIds as $settingNum => $deviceId) {
|
| 383 |
+
if ($deviceId['push_device_id'] == $this->registration_id_old) {
|
| 384 |
unset($deviceIds[$settingNum]);
|
| 385 |
}
|
| 386 |
}
|
| 387 |
}
|
| 388 |
|
| 389 |
+
Mage::getModel('core/config')->saveConfig('mobassistantconnectorinfosec/access/google_ids', serialize($deviceIds));
|
| 390 |
|
| 391 |
+
Mage::getModel('core/config')->saveConfig('mobassistantconnectorinfosec/access/api_key', $this->api_key);
|
| 392 |
|
| 393 |
$result = array('success' => 'true');
|
| 394 |
} else
|
| 397 |
return $result;
|
| 398 |
}
|
| 399 |
|
| 400 |
+
protected function get_store_title()
|
| 401 |
+
{
|
| 402 |
+
if (!empty($this->group_id)) {
|
| 403 |
try {
|
| 404 |
$name = Mage::app()->getGroup($this->group_id)->getName();
|
| 405 |
+
} catch (Exception $e) {
|
| 406 |
$name = Mage::app()->getStore()->getFrontendName();
|
| 407 |
}
|
| 408 |
} else $name = Mage::app()->getStore()->getFrontendName();
|
| 409 |
return array('test' => 1, 'title' => $name);
|
| 410 |
}
|
| 411 |
|
| 412 |
+
protected function is_group_exists($groupId)
|
| 413 |
+
{
|
| 414 |
$exists = false;
|
| 415 |
+
if (isset($groupId)) {
|
| 416 |
try {
|
| 417 |
$name = Mage::app()->getGroup($groupId)->getName();
|
| 418 |
$exists = true;
|
| 419 |
+
} catch (Exception $e) {
|
| 420 |
$exists = false;
|
| 421 |
}
|
| 422 |
}
|
| 423 |
return $exists;
|
| 424 |
}
|
| 425 |
|
| 426 |
+
protected function get_stores()
|
| 427 |
+
{
|
| 428 |
$arr_result = array();
|
| 429 |
|
| 430 |
foreach (Mage::app()->getWebsites() as $website) {
|
| 431 |
foreach ($website->getGroups() as $group) {
|
| 432 |
// foreach ($group->getStores() as $store) {
|
| 433 |
+
$arr_result[] = array(
|
| 434 |
// 'store_id' => $store->getStoreID(),
|
| 435 |
// 'store_name' => $store->getName(),
|
| 436 |
// 'is_store_active' => $store->getIsActive(),
|
| 437 |
+
'group_id' => $group->getId(),
|
| 438 |
+
'name' => $group->getName(),
|
| 439 |
+
'default_store_id' => $group->getDefaultStoreId(),
|
| 440 |
+
'website' => $website->getName(),
|
| 441 |
+
'website_id' => $website->getWebsiteId(),
|
| 442 |
+
'default_group_id' => $website->getDefaultGroupId(),
|
| 443 |
+
'website_is_default' => $website->getIsDefault()
|
| 444 |
// 'group_currencies' => $this->get_group_currencies($group->getId())
|
| 445 |
+
);
|
| 446 |
// }
|
| 447 |
}
|
| 448 |
}
|
| 450 |
return $arr_result;
|
| 451 |
}
|
| 452 |
|
| 453 |
+
protected function get_currencies()
|
| 454 |
+
{
|
| 455 |
$currencies = array();
|
| 456 |
+
try {
|
| 457 |
+
$collection = Mage::getModel('core/store')->getCollection(); // ->addFieldToFilter('group_id', $storeId);
|
| 458 |
+
if (!empty($this->group_id) && $this->group_id != -1) {
|
| 459 |
+
$collection->addFieldToFilter('group_id', $this->group_id);
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
foreach ($collection as $store) {
|
| 463 |
+
$storeId = $store->getStoreId();
|
| 464 |
+
$CurrencyCode = Mage::getModel('core/config_data')
|
| 465 |
+
->getCollection()
|
| 466 |
+
->addFieldToFilter('path', 'currency/options/allow')
|
| 467 |
+
->addFieldToFilter('scope_id', $storeId)
|
| 468 |
+
->getData();
|
| 469 |
+
$currencies_array = explode(',', $CurrencyCode[0]['value']);
|
| 470 |
+
if ($currencies_array[0] == '') {
|
| 471 |
+
// $currencies_array[] = Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
|
| 472 |
+
$currencies_array = Mage::app()->getStore($storeId)->getAvailableCurrencyCodes();
|
| 473 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 474 |
|
| 475 |
+
foreach ($currencies_array as $curCode) {
|
| 476 |
+
foreach ($currencies as $currency) {
|
| 477 |
+
if ($curCode == $currency['code']) {
|
| 478 |
+
continue 2;
|
| 479 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
}
|
| 481 |
|
| 482 |
+
$currencySymbol = Mage::app()->getLocale()->currency($curCode)->getSymbol();
|
| 483 |
+
$currencyName = Mage::app()->getLocale()->currency($curCode)->getName();
|
| 484 |
+
$currencies[] = array('code' => $curCode, 'symbol' => (is_null($currencySymbol) ? $curCode : $currencySymbol), 'name' => $currencyName);
|
| 485 |
+
}
|
| 486 |
+
}
|
| 487 |
+
} catch (Exception $e) {
|
| 488 |
+
Mage::log(
|
| 489 |
+
"Error while getting group currencies (" . var_export($e->getMessage(), true) . ")",
|
| 490 |
+
null,
|
| 491 |
+
'emagicone_mobassistantconnector.log'
|
| 492 |
+
);
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
return $currencies;
|
| 496 |
}
|
| 497 |
|
| 498 |
+
protected function get_store_stats()
|
| 499 |
+
{
|
| 500 |
$data_graphs = '';
|
| 501 |
$order_status_stats = array();
|
| 502 |
|
| 506 |
$today = date("Y-m-d", time());
|
| 507 |
$date_from = $date_to = $today;
|
| 508 |
|
| 509 |
+
if (!empty($this->stats_from)) {
|
| 510 |
$date_from = $this->stats_from;
|
| 511 |
}
|
| 512 |
|
| 513 |
+
if (!empty($this->stats_to)) {
|
| 514 |
$date_to = $this->stats_to;
|
| 515 |
}
|
| 516 |
|
| 517 |
+
if (isset($this->custom_period) && strlen($this->custom_period) > 0) {
|
| 518 |
$custom_period = $this->get_custom_period($this->custom_period);
|
| 519 |
|
| 520 |
$date_from = $custom_period['start_date'];
|
| 521 |
$date_to = $custom_period['end_date'];
|
| 522 |
}
|
| 523 |
|
| 524 |
+
if (!empty($date_from)) {
|
| 525 |
$date_from .= " 00:00:00";
|
| 526 |
}
|
| 527 |
+
if (!empty($date_to)) {
|
| 528 |
$date_to .= " 23:59:59";
|
| 529 |
}
|
| 530 |
|
| 533 |
$ordersCollection->addAttributeToSelect('entity_id');
|
| 534 |
$storeTableName = Mage::getSingleton('core/resource')->getTableName('core/store');
|
| 535 |
|
| 536 |
+
if (strlen($this->statuses) > 0) {
|
| 537 |
$this->statuses = '\'' . str_replace('|', '\',\'', $this->statuses) . '\'';
|
| 538 |
$ordersCollection->getSelect()->where(new Zend_Db_Expr("main_table.status IN ({$this->statuses})"));
|
| 539 |
}
|
| 540 |
|
| 541 |
if (!empty($this->group_id)) {
|
| 542 |
+
if ($this->is_group_exists($this->group_id)) {
|
| 543 |
$ordersCollection->getSelect()
|
| 544 |
->joinLeft(
|
| 545 |
array('cs' => $storeTableName),
|
| 548 |
}
|
| 549 |
}
|
| 550 |
|
| 551 |
+
if (!empty($date_from)) {
|
| 552 |
+
$ordersCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '" . $offset . "')) >= '" . (date('Y-m-d H:i:s', (strtotime($date_from)))) . "'"));
|
| 553 |
}
|
| 554 |
+
if (!empty($date_to)) {
|
| 555 |
+
$ordersCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '" . $offset . "')) <= '" . (date('Y-m-d H:i:s', (strtotime($date_to)))) . "'"));
|
| 556 |
}
|
| 557 |
|
| 558 |
$ordersCollection->getSelect()->columns('SUM(base_grand_total) as sum_base_grand_total,COUNT(*) AS count_orders');
|
| 562 |
$first = $ordersCollection->getFirstItem();
|
| 563 |
|
| 564 |
/*
|
| 565 |
+
if(!empty($date_from) && !empty($date_to)) {
|
| 566 |
$ordersCollection->addFieldToFilter('main_table.created_at',
|
| 567 |
array('from' => $date_from,
|
| 568 |
'to' => $date_to,
|
| 594 |
array());
|
| 595 |
|
| 596 |
if (!empty($this->group_id)) {
|
| 597 |
+
if ($this->is_group_exists($this->group_id)) {
|
| 598 |
$salesCollection->getSelect()
|
| 599 |
->joinLeft(
|
| 600 |
array('cs' => $storeTableName),
|
| 603 |
}
|
| 604 |
}
|
| 605 |
|
| 606 |
+
if (!empty($date_from)) {
|
| 607 |
+
$salesCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(order.created_at, '+00:00', '" . $offset . "')) >= '" . (date('Y-m-d H:i:s', (strtotime($date_from)))) . "'"));
|
| 608 |
}
|
| 609 |
+
if (!empty($date_to)) {
|
| 610 |
+
$salesCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(order.created_at, '+00:00', '" . $offset . "')) <= '" . (date('Y-m-d H:i:s', (strtotime($date_to)))) . "'"));
|
| 611 |
}
|
| 612 |
|
| 613 |
+
if (strlen($this->statuses) > 0) {
|
| 614 |
$salesCollection->getSelect()->where(new Zend_Db_Expr("order.status IN ({$this->statuses})"));
|
| 615 |
}
|
| 616 |
$store_stats['count_products'] = $this->bd_nice_number($salesCollection->getSize(), true);
|
| 617 |
|
| 618 |
+
$salesCollection->setOrder('item_id', 'DESC');
|
| 619 |
|
| 620 |
+
if ($this->last_order_id != "") {
|
| 621 |
$ordersCollection = Mage::getModel('sales/order')->getCollection();
|
| 622 |
|
| 623 |
$ordersCollection->addAttributeToFilter('entity_id', array('gt' => intval($this->last_order_id)));
|
| 624 |
|
| 625 |
+
$ordersCollection->setOrder('entity_id', 'DESC');
|
| 626 |
$ordersCollection->getSelect()->limit(1);
|
| 627 |
|
| 628 |
$lastOrder = $ordersCollection->getFirstItem();
|
| 629 |
|
| 630 |
$store_stats['last_order_id'] = $this->last_order_id;
|
| 631 |
+
if (intval($lastOrder['entity_id']) > intval($this->last_order_id)) {
|
| 632 |
$store_stats['last_order_id'] = intval($lastOrder['entity_id']);
|
| 633 |
}
|
| 634 |
|
| 637 |
|
| 638 |
$customerCollection = Mage::getModel('customer/customer')->getCollection();
|
| 639 |
|
| 640 |
+
if (!empty($date_from)) {
|
| 641 |
+
$customerCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(created_at, '+00:00', '" . $offset . "')) >= '" . date('Y-m-d H:i:s', (strtotime($date_from))) . "'"));
|
| 642 |
}
|
| 643 |
+
if (!empty($date_to)) {
|
| 644 |
+
$customerCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(created_at, '+00:00', '" . $offset . "')) <= '" . date('Y-m-d H:i:s', (strtotime($date_to))) . "'"));
|
| 645 |
}
|
| 646 |
|
| 647 |
if (!empty($this->group_id)) {
|
| 648 |
+
if ($this->is_group_exists($this->group_id)) {
|
| 649 |
$customerCollection->getSelect()
|
| 650 |
->joinLeft(
|
| 651 |
array('cs' => $storeTableName),
|
| 657 |
$row['count_customers'] = $customerCollection->count();
|
| 658 |
$store_stats = array_merge($store_stats, $row);
|
| 659 |
|
| 660 |
+
if (!isset($this->data_for_widget) || empty($this->data_for_widget) || $this->data_for_widget != 1) {
|
| 661 |
$data_graphs = $this->get_data_graphs();
|
| 662 |
}
|
| 663 |
|
| 680 |
|
| 681 |
}
|
| 682 |
|
| 683 |
+
protected function get_status_stats()
|
| 684 |
+
{
|
| 685 |
|
| 686 |
$offset = $this->_get_timezone_offset();
|
| 687 |
$store_stats = array('count_orders' => "0", 'total_sales' => "0", 'count_customers' => "0", 'count_products' => "0", "last_order_id" => "0", "new_orders" => "0");
|
| 689 |
$today = date("Y-m-d", time());
|
| 690 |
$date_from = $date_to = $today;
|
| 691 |
|
| 692 |
+
if (!empty($this->stats_from)) {
|
| 693 |
$date_from = $this->stats_from;
|
| 694 |
}
|
| 695 |
|
| 696 |
+
if (!empty($this->stats_to)) {
|
| 697 |
$date_to = $this->stats_to;
|
| 698 |
}
|
| 699 |
|
| 700 |
+
if (isset($this->custom_period) && strlen($this->custom_period) > 0) {
|
| 701 |
$custom_period = $this->get_custom_period($this->custom_period);
|
| 702 |
|
| 703 |
$date_from = $custom_period['start_date'];
|
| 704 |
$date_to = $custom_period['end_date'];
|
| 705 |
}
|
| 706 |
|
| 707 |
+
if (!empty($date_from)) {
|
| 708 |
$date_from .= " 00:00:00";
|
| 709 |
}
|
| 710 |
+
if (!empty($date_to)) {
|
| 711 |
$date_to .= " 23:59:59";
|
| 712 |
}
|
| 713 |
|
| 715 |
$orderStatusTableName = Mage::getSingleton('core/resource')->getTableName('sales/order_status');
|
| 716 |
|
| 717 |
$salesCollection = Mage::getModel("sales/order")->getCollection()
|
| 718 |
+
->addFieldToSelect(array('state', 'status', 'store_id', 'base_grand_total', 'base_currency_code', 'order_currency_code'));
|
| 719 |
|
| 720 |
$salesCollection->clear();
|
| 721 |
|
| 722 |
if (!empty($this->group_id)) {
|
| 723 |
+
if ($this->is_group_exists($this->group_id)) {
|
| 724 |
$salesCollection->getSelect()
|
| 725 |
->joinLeft(
|
| 726 |
array('cs' => $storeTableName),
|
| 736 |
array('name' => 'sos.label'));
|
| 737 |
|
| 738 |
$salesCollection->getSelect()->columns(array('code' => new Zend_Db_Expr ('main_table.status')));
|
| 739 |
+
$salesCollection->getSelect()->columns(array('count' => new Zend_Db_Expr ('COUNT(main_table.entity_id)')));
|
| 740 |
$salesCollection->getSelect()->columns(array('total' => new Zend_Db_Expr ('SUM(main_table.base_grand_total)')));
|
| 741 |
|
| 742 |
|
| 743 |
+
if (!empty($date_from)) {
|
| 744 |
+
$salesCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '" . $offset . "')) >= '" . (date('Y-m-d H:i:s', (strtotime($date_from)))) . "'"));
|
| 745 |
}
|
| 746 |
+
if (!empty($date_to)) {
|
| 747 |
+
$salesCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '" . $offset . "')) <= '" . (date('Y-m-d H:i:s', (strtotime($date_to)))) . "'"));
|
| 748 |
}
|
| 749 |
|
| 750 |
// if(strlen($this->statuses) > 0) {
|
| 753 |
|
| 754 |
$salesCollection->getSelect()->group(new Zend_Db_Expr("main_table.status"));
|
| 755 |
|
| 756 |
+
$salesCollection->getSelect()->order(new Zend_Db_Expr('count DESC'));
|
| 757 |
|
| 758 |
$orders = array();
|
| 759 |
foreach ($salesCollection as $sale) {
|
| 781 |
|
| 782 |
}
|
| 783 |
|
| 784 |
+
protected function get_data_graphs()
|
| 785 |
+
{
|
| 786 |
$orders = array();
|
| 787 |
$customers = array();
|
| 788 |
$offset = $this->_get_timezone_offset();
|
| 789 |
$average = array('avg_sum_orders' => 0, 'avg_orders' => 0, 'avg_customers' => 0, 'avg_cust_order' => '0.00', 'tot_customers' => 0, 'sum_orders' => 0, 'tot_orders' => 0);
|
| 790 |
|
| 791 |
+
if (empty($this->graph_from)) {
|
| 792 |
+
$this->graph_from = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 7, date("Y")));
|
| 793 |
}
|
| 794 |
|
| 795 |
+
if (empty($this->graph_to)) {
|
| 796 |
+
if (!empty($this->stats_to)) {
|
| 797 |
$this->graph_to = $this->stats_to;
|
| 798 |
} else {
|
| 799 |
$this->graph_to = date("Y-m-d", time());
|
| 803 |
$endDate = $this->graph_to . " 23:59:59";
|
| 804 |
|
| 805 |
$plus_date = "+1 day";
|
| 806 |
+
if (isset($this->custom_period) && strlen($this->custom_period) > 0) {
|
| 807 |
$custom_period = $this->get_custom_period($this->custom_period);
|
| 808 |
|
| 809 |
+
if ($this->custom_period == 3) {
|
| 810 |
$plus_date = "+3 day";
|
| 811 |
+
} else if ($this->custom_period == 4 || $this->custom_period == 8) {
|
| 812 |
$plus_date = "+1 week";
|
| 813 |
+
} else if ($this->custom_period == 5 || $this->custom_period == 6 || $this->custom_period == 7) {
|
| 814 |
$plus_date = "+1 month";
|
| 815 |
}
|
| 816 |
|
| 817 |
+
if ($this->custom_period == 6) {
|
| 818 |
$ordersCollection = Mage::getModel('sales/order')->getCollection();
|
| 819 |
$ordersCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
|
| 820 |
$ordersCollection->getSelect()->columns(array('min_date_add' => new Zend_Db_Expr ("MIN(`created_at`)")));
|
| 826 |
$endDate = $orders_info['max_date_add'];
|
| 827 |
}
|
| 828 |
} else {
|
| 829 |
+
$startDate = $custom_period['start_date'] . " 00:00:00";
|
| 830 |
+
$endDate = $custom_period['end_date'] . " 23:59:59";
|
| 831 |
}
|
| 832 |
}
|
| 833 |
|
| 846 |
$ordersCollection->getSelect()->reset(Zend_Db_Select::COLUMNS);
|
| 847 |
|
| 848 |
if (!empty($this->group_id)) {
|
| 849 |
+
if ($this->is_group_exists($this->group_id)) {
|
| 850 |
$ordersCollection->getSelect()
|
| 851 |
->joinLeft(
|
| 852 |
array('cs' => $storeTableName),
|
| 861 |
$ordersCollection->getSelect()->columns(array('tot_orders' => new Zend_Db_Expr ("COUNT(main_table.entity_id)")));
|
| 862 |
|
| 863 |
$ordersCollection->getSelect()->where(new Zend_Db_Expr("((CONVERT_TZ(main_table.created_at, '+00:00', '{$offset}' )) >= '{$dateStr}'
|
| 864 |
+
AND (CONVERT_TZ(main_table.created_at, '+00:00', '{$offset}')) < '" . date('Y-m-d H:i:s', (strtotime($plus_date, $date))) . "')"));
|
| 865 |
|
| 866 |
|
| 867 |
+
if (strlen($this->statuses) > 0) {
|
| 868 |
$this->statuses = str_replace('|', '\',\'', $this->statuses);
|
| 869 |
$ordersCollection->getSelect()->where(new Zend_Db_Expr("main_table.status IN ({$this->statuses})"));
|
| 870 |
}
|
| 884 |
}
|
| 885 |
|
| 886 |
$total_order_per_day = number_format($total_order_per_day, 2, '.', '');
|
| 887 |
+
$orders[] = array($date * 1000, $total_order_per_day);
|
| 888 |
|
| 889 |
$customersCollection = Mage::getResourceModel('customer/customer_collection');
|
| 890 |
$customersCollection->addAttributeToSelect('name');
|
| 891 |
|
| 892 |
if (!empty($this->group_id)) {
|
| 893 |
+
if ($this->is_group_exists($this->group_id)) {
|
| 894 |
$customersCollection->getSelect()
|
| 895 |
->joinLeft(
|
| 896 |
array('cs' => $storeTableName),
|
| 907 |
|
| 908 |
$customersCollection->getSelect()->columns(array('date_add' => new Zend_Db_Expr ("CONVERT_TZ((created_at, '+00:00', {$offset}))")));
|
| 909 |
$customersCollection->getSelect()->where(new Zend_Db_Expr("((CONVERT_TZ(created_at, '+00:00', '{$offset}')) >= '{$dateStr}'
|
| 910 |
+
AND (CONVERT_TZ(created_at, '+00:00', '{$offset}')) < '" . date('Y-m-d H:i:s', (strtotime($plus_date, $date))) . "')"));
|
| 911 |
|
| 912 |
$total_customer_per_day = $customersCollection->getSize();
|
| 913 |
$average['tot_customers'] += $total_customer_per_day;
|
| 914 |
$customers_count = $customersCollection->getSize();
|
| 915 |
|
| 916 |
+
$customers[] = array($date * 1000, $total_customer_per_day);
|
| 917 |
$date = strtotime($plus_date, $date);
|
| 918 |
}
|
| 919 |
|
| 920 |
$sum = '0';
|
| 921 |
$default_currency_sign = $this->_price_format($this->def_currency, 1, $sum, $this->currency_code, true);
|
| 922 |
|
| 923 |
+
if ($d <= 0) $d = 1;
|
| 924 |
+
$average['avg_sum_orders'] = number_format($average['sum_orders'] / $d, 2, '.', ' ');
|
| 925 |
+
$average['avg_orders'] = number_format($average['tot_orders'] / $d, 1, '.', ' ');
|
| 926 |
+
$average['avg_customers'] = number_format($average['tot_customers'] / $d, 1, '.', ' ');
|
| 927 |
|
| 928 |
+
if ($average['tot_customers'] > 0) {
|
| 929 |
+
$average['avg_cust_order'] = number_format($average['sum_orders'] / $average['tot_customers'], 1, '.', ' ');
|
| 930 |
}
|
| 931 |
$average['sum_orders'] = number_format($average['sum_orders'], 2, '.', ' ');
|
| 932 |
$average['tot_customers'] = number_format($average['tot_customers'], 1, '.', ' ');
|
| 935 |
return array('orders' => $orders, 'customers' => $customers, 'currency_sign' => $default_currency_sign, 'average' => $average);
|
| 936 |
}
|
| 937 |
|
| 938 |
+
protected function get_orders()
|
| 939 |
+
{
|
| 940 |
$offset = $this->_get_timezone_offset();
|
| 941 |
$max_date = null;
|
| 942 |
$min_date = null;
|
| 961 |
array());
|
| 962 |
|
| 963 |
if (!empty($this->group_id)) {
|
| 964 |
+
if ($this->is_group_exists($this->group_id)) {
|
| 965 |
$ordersCollection->getSelect()
|
| 966 |
->joinLeft(
|
| 967 |
array('cs' => $storeTableName),
|
| 977 |
}
|
| 978 |
|
| 979 |
$ordersStatsCollection->getSelect()->columns(array('count_ords' => new Zend_Db_Expr ('COUNT(main_table.entity_id)')));
|
| 980 |
+
$ordersStatsCollection->getSelect()->columns(array('max_date' => new Zend_Db_Expr ('MAX(CONVERT_TZ(main_table.created_at, "+00:00", "' . $offset . '"))')));
|
| 981 |
+
$ordersStatsCollection->getSelect()->columns(array('min_date' => new Zend_Db_Expr ('MIN(CONVERT_TZ(main_table.created_at, "+00:00", "' . $offset . '"))')));
|
| 982 |
$ordersStatsCollection->getSelect()->columns(array('orders_total' => new Zend_Db_Expr ('SUM(main_table.base_grand_total)')));
|
| 983 |
|
| 984 |
$ordersCollection->getSelect()->columns(array('store_id' => new Zend_Db_Expr ('main_table.store_id')));
|
| 994 |
$ordersCollection->getSelect()->columns(array('lastname' => new Zend_Db_Expr ('main_table.customer_lastname')));
|
| 995 |
$ordersCollection->getSelect()->columns(array('full_name' => new Zend_Db_Expr ('CONCAT(main_table.customer_firstname, " ", main_table.customer_lastname)')));
|
| 996 |
$ordersCollection->getSelect()->columns(array('iso_code' => new Zend_Db_Expr ('main_table.global_currency_code')));
|
| 997 |
+
$ordersCollection->getSelect()->columns(array('date_add' => new Zend_Db_Expr ('CONVERT_TZ(main_table.created_at, "+00:00", "' . $offset . '")')));
|
| 998 |
$ordersCollection->getSelect()->columns(array('count_prods' => new Zend_Db_Expr ('main_table.total_item_count')));
|
| 999 |
|
| 1000 |
+
if (empty($this->sort_by)) {
|
| 1001 |
$this->sort_by = "id";
|
| 1002 |
}
|
| 1003 |
|
| 1004 |
switch ($this->sort_by) {
|
| 1005 |
case 'name':
|
| 1006 |
+
$ordersCollection->getSelect()->order(array('main_table.customer_firstname ASC'));
|
| 1007 |
+
$ordersCollection->getSelect()->order(array('main_table.customer_lastname ASC'));
|
| 1008 |
+
$ordersStatsCollection->getSelect()->order(array('main_table.customer_firstname ASC'));
|
| 1009 |
+
$ordersStatsCollection->getSelect()->order(array('main_table.customer_lastname ASC'));
|
| 1010 |
break;
|
| 1011 |
case 'date':
|
| 1012 |
+
$ordersCollection->getSelect()->order(array('main_table.created_at DESC'));
|
| 1013 |
+
$ordersStatsCollection->getSelect()->order(array('main_table.created_at DESC'));
|
| 1014 |
break;
|
| 1015 |
case 'id':
|
| 1016 |
+
$ordersCollection->getSelect()->order(array('main_table.entity_id DESC'));
|
| 1017 |
+
$ordersStatsCollection->getSelect()->order(array('main_table.entity_id DESC'));
|
| 1018 |
break;
|
| 1019 |
}
|
| 1020 |
|
| 1021 |
+
if (strlen($this->statuses) > 0) {
|
| 1022 |
$this->statuses = '\'' . str_replace('|', '\',\'', $this->statuses) . '\'';
|
| 1023 |
$ordersCollection->getSelect()->where(new Zend_Db_Expr("main_table.status IN ({$this->statuses})"));
|
| 1024 |
$ordersStatsCollection->getSelect()->where(new Zend_Db_Expr("main_table.status IN ({$this->statuses})"));
|
| 1025 |
}
|
| 1026 |
|
| 1027 |
+
if (!empty($this->orders_from)) {
|
| 1028 |
+
$ordersCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '" . $offset . "')) >= '" . date('Y-m-d H:i:s', (strtotime(($this->orders_from . " 00:00:00")))) . "'"));
|
| 1029 |
+
$ordersStatsCollection->getSelect()->where(new Zend_Db_Expr(" (CONVERT_TZ(main_table.created_at, '+00:00', '" . $offset . "')) >= '" . date('Y-m-d H:i:s', (strtotime(($this->orders_from . " 00:00:00")))) . "'"));
|
| 1030 |
}
|
| 1031 |
|
| 1032 |
+
if (!empty($this->orders_to)) {
|
| 1033 |
+
$ordersCollection->getSelect()->where(new Zend_Db_Expr("(CONVERT_TZ(main_table.created_at, '+00:00', '" . $offset . "')) <= '" . date('Y-m-d H:i:s', (strtotime(($this->orders_to . " 23:59:59")))) . "'"));
|
| 1034 |
+
$ordersStatsCollection->getSelect()->where(new Zend_Db_Expr(" (CONVERT_TZ(main_table.created_at, '+00:00', '" . $offset . "')) <= '" . date('Y-m-d H:i:s', (strtotime(($this->orders_to . " 23:59:59")))) . "'"));
|
| 1035 |
}
|
| 1036 |
|
| 1037 |
$query = '';
|
| 1038 |
+
if (!empty($this->search_order_id)) {
|
| 1039 |
+
$query_where_parts[] = "(main_table.customer_firstname LIKE ('%" . $this->search_order_id . "%')
|
| 1040 |
+
OR main_table.customer_lastname LIKE ('%" . $this->search_order_id . "%')
|
| 1041 |
+
OR CONCAT(main_table.customer_firstname, ' ', main_table.customer_lastname) LIKE ('%" . $this->search_order_id . "%'))";
|
| 1042 |
}
|
| 1043 |
+
if (!empty($this->search_order_id) && preg_match('/^\d+(?:,\d+)*$/', $this->search_order_id)) {
|
| 1044 |
+
$query_where_parts[] = "(main_table.entity_id IN (" . $this->search_order_id . ") OR main_table.increment_id IN (" . $this->search_order_id . "))";
|
| 1045 |
}
|
| 1046 |
|
| 1047 |
if (!empty($query_where_parts)) {
|
| 1048 |
+
$query .= "(" . implode(" OR ", $query_where_parts) . ")";
|
| 1049 |
$ordersCollection->getSelect()->where($query);
|
| 1050 |
$ordersStatsCollection->getSelect()->where($query);
|
| 1051 |
}
|
| 1062 |
|
| 1063 |
// echo($ordersCollection->getSelect()->__toString());die();
|
| 1064 |
|
| 1065 |
+
if (!empty($this->page) && !empty($this->show)) {
|
| 1066 |
// $ordersCollection->setPage(($this->page), $this->show);
|
| 1067 |
+
$ordersCollection->getSelect()->limit($this->show, ($this->page - 1) * $this->show);
|
| 1068 |
}
|
| 1069 |
|
| 1070 |
+
$orders = array();
|
| 1071 |
foreach ($ordersCollection as $order) {
|
| 1072 |
$orderArray = $order->toArray();
|
| 1073 |
$price = $this->_price_format($orderArray['iso_code'], 1, $order['total_paid'], $this->currency_code);
|
| 1074 |
$orderArray['customer'] = $orderArray['firstname'] . ' ' . $orderArray['lastname'];
|
| 1075 |
$orderArray['total_paid'] = $price;
|
| 1076 |
|
| 1077 |
+
if ($this->currency_code != false) {
|
| 1078 |
$orderArray['iso_code'] = $this->currency_code;
|
| 1079 |
}
|
| 1080 |
|
| 1086 |
$orders[] = $orderArray;
|
| 1087 |
}
|
| 1088 |
|
| 1089 |
+
if ($this->page > 1 && intval($this->search_order_id) > 0) {
|
| 1090 |
$orders = array();
|
| 1091 |
}
|
| 1092 |
|
| 1093 |
foreach ($ordersStatsCollection as $orderStats) {
|
| 1094 |
$orderStats = $orderStats->toArray();
|
| 1095 |
|
| 1096 |
+
if ($orderStats['count_ords'] > 0) {
|
| 1097 |
$max_date = date("n/j/Y", strtotime($orderStats['max_date']));
|
| 1098 |
$min_date = date("n/j/Y", strtotime($orderStats['min_date']));
|
| 1099 |
}
|
| 1101 |
}
|
| 1102 |
|
| 1103 |
$orders_status = null;
|
| 1104 |
+
if (isset($this->get_statuses) && $this->get_statuses == 1) {
|
| 1105 |
$orders_status = $this->get_orders_statuses();
|
| 1106 |
}
|
| 1107 |
|
| 1115 |
"orders_status" => $orders_status);
|
| 1116 |
}
|
| 1117 |
|
| 1118 |
+
protected function get_orders_info()
|
| 1119 |
+
{
|
| 1120 |
$offset = $this->_get_timezone_offset();
|
| 1121 |
$order_products = array();
|
| 1122 |
+
$pdf_invoice = false;
|
| 1123 |
$order_info = array('iso_code' => '', 's_country_id' => '', 'b_country_id' => '', 'telephone' => '', 'shipping_method_mag' => '', 'payment_method_mag' => '');
|
| 1124 |
|
| 1125 |
$ordersInfoCollection = Mage::getModel('sales/order')->getCollection()->addAttributeToSelect('entity_id');
|
| 1150 |
$ordersInfoCollection->getSelect()->columns(array('total_paid' => new Zend_Db_Expr ('main_table.base_grand_total')));
|
| 1151 |
$ordersInfoCollection->getSelect()->columns(array('customer' => new Zend_Db_Expr ('CONCAT(main_table.customer_firstname, " ", main_table.customer_lastname)')));
|
| 1152 |
$ordersInfoCollection->getSelect()->columns(array('iso_code' => new Zend_Db_Expr ('main_table.global_currency_code')));
|
| 1153 |
+
$ordersInfoCollection->getSelect()->columns(array('date_add' => new Zend_Db_Expr ('CONVERT_TZ(main_table.created_at, "+00:00", "' . $offset . '")')));
|
| 1154 |
$ordersInfoCollection->getSelect()->columns(array('email' => new Zend_Db_Expr ('main_table.customer_email')));
|
| 1155 |
$ordersInfoCollection->getSelect()->columns(array('id_customer' => new Zend_Db_Expr ('main_table.customer_id')));
|
| 1156 |
$ordersInfoCollection->getSelect()->columns(array('subtotal' => new Zend_Db_Expr ('main_table.base_subtotal')));
|
| 1185 |
'eq' => intval($this->order_id),
|
| 1186 |
));
|
| 1187 |
|
| 1188 |
+
foreach ($ordersInfoCollection as $orderInfo) {
|
| 1189 |
$order_info_array = $orderInfo->toArray();
|
| 1190 |
$order_info_array['store_id'] = $orderInfo->getStore()->getId();
|
| 1191 |
$order_info_array['store_name'] = $orderInfo->getStore()->getName();
|
| 1197 |
|
| 1198 |
$iso_code = $order_info['iso_code'];
|
| 1199 |
$elements = array('total_paid', 'subtotal', 'sh_amount', 'tax_amount', 'd_amount', 'g_total', 't_paid', 't_refunded', 't_due');
|
| 1200 |
+
foreach ($elements as $element) {
|
| 1201 |
$price = $this->_price_format($iso_code, 1, $order_info[$element], $this->currency_code);
|
| 1202 |
$order_info[$element] = $price;
|
| 1203 |
}
|
| 1204 |
|
| 1205 |
+
if ($this->currency_code != false) {
|
| 1206 |
$order_info['iso_code'] = $this->currency_code;
|
| 1207 |
}
|
| 1208 |
|
| 1242 |
|
| 1243 |
$ordersItemsCollection->addAttributeToFilter('main_table.parent_item_id', $allowedParentId);
|
| 1244 |
|
| 1245 |
+
if (empty($this->sort_by)) {
|
| 1246 |
$this->sort_by = "id";
|
| 1247 |
}
|
| 1248 |
|
| 1249 |
switch ($this->sort_by) {
|
| 1250 |
case 'name':
|
| 1251 |
+
$ordersItemsCollection->getSelect()->order(array('full_name ASC'));
|
| 1252 |
break;
|
| 1253 |
case 'date':
|
| 1254 |
+
$ordersItemsCollection->getSelect()->order(array('date_add DESC'));
|
| 1255 |
break;
|
| 1256 |
case 'id':
|
| 1257 |
+
$ordersItemsCollection->getSelect()->order(array('id_order DESC'));
|
| 1258 |
break;
|
| 1259 |
}
|
| 1260 |
|
| 1261 |
+
if (!empty($this->page) && !empty($this->show)) {
|
| 1262 |
$ordersItemsCollection->setPage($this->page, $this->show);
|
| 1263 |
}
|
| 1264 |
|
| 1265 |
$block = Mage::app()->getLayout()->createBlock('sales/order_item_renderer_default');
|
| 1266 |
|
| 1267 |
+
foreach ($ordersItemsCollection as $orderItem) {
|
| 1268 |
$block->setItem($orderItem);
|
| 1269 |
$_options = $block->getItemOptions();
|
| 1270 |
|
| 1277 |
// $thumbnail_path = $orderItem->getProduct()->getThumbnail();
|
| 1278 |
// $thumbnail = $orderItem->getProduct()->getMediaConfig()->getMediaUrl($thumbnail_path);
|
| 1279 |
|
| 1280 |
+
if (($thumbnail == 'no_selection') || (!isset($thumbnail))) {
|
| 1281 |
$thumbnail = '';
|
| 1282 |
}
|
| 1283 |
|
| 1284 |
$orderItem = $orderItem->toArray();
|
| 1285 |
|
| 1286 |
$orderItem['options'] = array();
|
| 1287 |
+
if (isset($_options) && count($_options) > 0) {
|
| 1288 |
foreach ($_options as $option) {
|
| 1289 |
$orderItem['options'][$option['label']] = $option['value'];
|
| 1290 |
}
|
| 1291 |
}
|
| 1292 |
|
| 1293 |
$orderItem['product_options'] = unserialize($orderItem['product_options']);
|
| 1294 |
+
if (isset($orderItem['product_options']['bundle_options'])) {
|
| 1295 |
foreach ($orderItem['product_options']['bundle_options'] as $option) {
|
| 1296 |
+
$orderItem['options'][$option['label']] = $option['value'][0]['qty'] . 'x ' . $option['value'][0]['title'];
|
| 1297 |
}
|
| 1298 |
}
|
| 1299 |
|
| 1300 |
unset($orderItem['product_options']);
|
| 1301 |
|
| 1302 |
+
if (self::MB_VERSION > 80 && !empty($orderItem['options'])) {
|
|
|
|
|
|
|
| 1303 |
$orderItem['prod_options'] = $orderItem['options'];
|
| 1304 |
unset($orderItem['options']);
|
| 1305 |
}
|
| 1306 |
|
| 1307 |
+
if (empty($orderItem['options'])) {
|
| 1308 |
unset($orderItem['options']);
|
| 1309 |
}
|
| 1310 |
|
| 1312 |
$orderItem['product_price'] = $this->_price_format($order_info['iso_code'], 1, $orderItem['product_price'], $this->currency_code);
|
| 1313 |
$orderItem['product_quantity'] = intval($orderItem['product_quantity']);
|
| 1314 |
$orderItem['type_id'] = ucfirst($orderItem['type_id']);
|
| 1315 |
+
if ($this->currency_code != false) {
|
| 1316 |
$orderItem['iso_code'] = $this->currency_code;
|
| 1317 |
}
|
| 1318 |
unset($orderItem['product']);
|
| 1330 |
|
| 1331 |
$count_prods = $orderCountItemsCollection->getSize();
|
| 1332 |
|
| 1333 |
+
if (!empty($this->order_id)) {
|
| 1334 |
|
| 1335 |
$cur_order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1336 |
|
| 1337 |
$actions = array();
|
| 1338 |
|
| 1339 |
+
if ($cur_order->canCancel()) {
|
| 1340 |
$actions[] = 'cancel';
|
| 1341 |
}
|
| 1342 |
|
| 1343 |
+
if ($cur_order->canHold()) {
|
| 1344 |
$actions[] = 'hold';
|
| 1345 |
}
|
| 1346 |
|
| 1347 |
+
if ($cur_order->canUnhold()) {
|
| 1348 |
$actions[] = 'unhold';
|
| 1349 |
}
|
| 1350 |
|
| 1351 |
+
if ($cur_order->canShip()) {
|
| 1352 |
$actions[] = 'ship';
|
| 1353 |
}
|
| 1354 |
|
| 1355 |
+
if ($cur_order->canInvoice()) {
|
| 1356 |
$actions[] = 'invoice';
|
| 1357 |
}
|
| 1358 |
|
| 1359 |
+
if ($cur_order->hasInvoices()) {
|
| 1360 |
+
$pdf_invoice = 1;
|
| 1361 |
+
}
|
| 1362 |
+
|
| 1363 |
$cus_id = $cur_order->getCustomerId();
|
| 1364 |
|
| 1365 |
$customer_data = Mage::getModel('customer/customer')->load($cus_id);
|
| 1366 |
|
| 1367 |
$customerAddressId = $customer_data->getDefaultBilling();
|
| 1368 |
+
if ($customerAddressId) {
|
| 1369 |
$address = Mage::getModel('customer/address')->load($customerAddressId)->toArray();
|
| 1370 |
+
if (count($address) > 1) {
|
| 1371 |
$order_info['telephone'] = $address['telephone'];
|
| 1372 |
}
|
| 1373 |
}
|
| 1374 |
|
| 1375 |
+
if (empty($order_info['telephone'])) {
|
| 1376 |
$order_info['telephone'] = '';
|
| 1377 |
}
|
| 1378 |
$order_info['shipping_method_mag'] = $cur_order->getShippingDescription();
|
| 1384 |
->load();
|
| 1385 |
$tracks = array();
|
| 1386 |
foreach ($shipmentCollection as $shipment) {
|
| 1387 |
+
foreach ($shipment->getAllTracks() as $tracknum) {
|
|
|
|
| 1388 |
$track['track_number'] = $tracknum->getTrackNumber();
|
| 1389 |
$track['title'] = $tracknum->getTitle();
|
| 1390 |
$track['carrier_code'] = $tracknum->getCarrierCode();
|
| 1391 |
$track['created_at'] = $tracknum->getCreatedAt();
|
| 1392 |
|
| 1393 |
+
$tracks[] = $track;
|
| 1394 |
}
|
| 1395 |
|
| 1396 |
}
|
| 1397 |
|
| 1398 |
+
$order_full_info = array('order_info' => $order_info,
|
| 1399 |
+
'order_products' => $order_products,
|
| 1400 |
+
'o_products_count' => $count_prods,
|
| 1401 |
+
'order_tracking' => $tracks,
|
| 1402 |
+
'actions' => $actions);
|
| 1403 |
+
|
| 1404 |
+
if ($pdf_invoice) {
|
| 1405 |
+
$order_full_info['pdf_invoice'] = $pdf_invoice;
|
| 1406 |
+
}
|
| 1407 |
|
| 1408 |
return $order_full_info;
|
| 1409 |
} else return false;
|
| 1410 |
}
|
| 1411 |
|
| 1412 |
+
protected function get_order_pdf()
|
| 1413 |
+
{
|
| 1414 |
+
if (!empty($this->order_id)) {
|
| 1415 |
+
// $order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1416 |
+
$invoices = Mage::getResourceModel('sales/order_invoice_collection')
|
| 1417 |
+
->setOrderFilter($this->order_id)
|
| 1418 |
+
->load();
|
| 1419 |
+
if ($invoices->getSize() > 0) {
|
| 1420 |
+
|
| 1421 |
+
try {
|
| 1422 |
+
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoices);
|
| 1423 |
+
|
| 1424 |
+
$this->_prepareDownloadResponse(
|
| 1425 |
+
'invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').'.pdf', $pdf->render(),
|
| 1426 |
+
'application/pdf'
|
| 1427 |
+
);
|
| 1428 |
+
} catch (Exception $e) {
|
| 1429 |
+
echo $e->getMessage();
|
| 1430 |
+
}
|
| 1431 |
+
} else {
|
| 1432 |
+
return false;
|
| 1433 |
+
}
|
| 1434 |
+
} else {
|
| 1435 |
+
return false;
|
| 1436 |
+
}
|
| 1437 |
+
|
| 1438 |
+
return Mage::app()->getResponse();
|
| 1439 |
+
}
|
| 1440 |
+
|
| 1441 |
+
protected function map_order_statuses($status)
|
| 1442 |
+
{
|
| 1443 |
return array(
|
| 1444 |
'st_id' => $status['status'],
|
| 1445 |
'st_name' => $status['label']
|
| 1446 |
);
|
| 1447 |
}
|
| 1448 |
|
| 1449 |
+
protected function get_orders_statuses()
|
| 1450 |
+
{
|
| 1451 |
$statuses = Mage::getModel('sales/order_status')->getResourceCollection()->getData();
|
| 1452 |
|
| 1453 |
+
$final_statuses = array_map(array($this, 'map_order_statuses'), $statuses);
|
| 1454 |
|
| 1455 |
return $final_statuses;
|
| 1456 |
}
|
| 1457 |
|
| 1458 |
+
private function invoice_order()
|
| 1459 |
+
{
|
| 1460 |
$order = Mage::getModel("sales/order")->load($this->order_id);
|
| 1461 |
$result = array('error' => $this->__('An error occurred!'));
|
| 1462 |
try {
|
| 1463 |
+
if ($order->canInvoice()) {
|
|
|
|
| 1464 |
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
| 1465 |
if ($invoice->getTotalQty()) {
|
| 1466 |
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
|
| 1482 |
$order->save();
|
| 1483 |
$result = array('error' => $this->__('Cannot create an invoice!'));
|
| 1484 |
}
|
| 1485 |
+
} catch (Mage_Core_Exception $e) {
|
|
|
|
| 1486 |
}
|
| 1487 |
|
| 1488 |
return $result;
|
| 1489 |
}
|
| 1490 |
|
| 1491 |
|
| 1492 |
+
private function ship_order()
|
| 1493 |
+
{
|
| 1494 |
$result = array('error' => $this->__('An error occurred!'));
|
| 1495 |
$title = '';
|
| 1496 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1497 |
|
| 1498 |
+
if (isset($this->tracking_title) && strlen($this->tracking_title) > 0) {
|
| 1499 |
$title = $this->tracking_title;
|
| 1500 |
} else {
|
| 1501 |
$carriers = $this->get_carriers();
|
| 1502 |
|
| 1503 |
+
foreach ($carriers as $carrier) {
|
| 1504 |
+
if ($carrier['code'] == $this->carrier_code) {
|
| 1505 |
$title = $carrier['label'];
|
| 1506 |
}
|
| 1507 |
}
|
| 1508 |
}
|
| 1509 |
|
| 1510 |
+
if ($order->hasShipments()) {
|
| 1511 |
+
foreach ($order->getShipmentsCollection() as $shipment) {
|
|
|
|
| 1512 |
$shipmentIncrementId = $shipment->getIncrementId();
|
| 1513 |
+
if ($shipmentIncrementId) {
|
| 1514 |
+
if (isset($this->tracking_number) && strlen($this->tracking_number) > 0 && isset($this->carrier_code) && strlen($this->carrier_code) > 0) {
|
| 1515 |
try {
|
| 1516 |
Mage::getModel('sales/order_shipment_api')->addTrack($shipmentIncrementId, $this->carrier_code, $title, $this->tracking_number);
|
| 1517 |
|
| 1521 |
}
|
| 1522 |
|
| 1523 |
$result = array('success' => 'true');
|
| 1524 |
+
} catch (Exception $e) {
|
|
|
|
| 1525 |
Mage::log(
|
| 1526 |
"error: Adding track number: {$e->getMessage()} ({$e->getCustomMessage()})",
|
| 1527 |
null,
|
| 1528 |
'emagicone_mobassistantconnector.log'
|
| 1529 |
);
|
| 1530 |
|
| 1531 |
+
$result = array('error' => $e->getMessage() . ' (' . $e->getCustomMessage() . ')');
|
| 1532 |
}
|
| 1533 |
} else $result = array('error' => $this->__('Empty tracking number!'));
|
| 1534 |
}
|
| 1535 |
}
|
| 1536 |
+
} else if ($order->canShip()) {
|
|
|
|
| 1537 |
|
| 1538 |
$shipment = new Mage_Sales_Model_Order_Shipment_Api();
|
| 1539 |
$shipmentId = $shipment->create($order->getIncrementId());
|
| 1540 |
|
| 1541 |
+
if (isset($this->tracking_number) && strlen($this->tracking_number) > 0 && isset($this->carrier_code) && strlen($this->carrier_code) > 0) {
|
| 1542 |
$shipment->addTrack($shipmentId, $this->carrier_code, $title, $this->tracking_number);
|
| 1543 |
}
|
| 1544 |
|
| 1554 |
return $result;
|
| 1555 |
}
|
| 1556 |
|
| 1557 |
+
private function cancel_order()
|
| 1558 |
+
{
|
| 1559 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1560 |
+
if ($order->canCancel()) {
|
| 1561 |
$order->cancel();
|
| 1562 |
$order->addStatusHistoryComment('Order was canceled by MA', false);
|
| 1563 |
$order->save();
|
| 1571 |
return $result;
|
| 1572 |
}
|
| 1573 |
|
| 1574 |
+
private function hold_order()
|
| 1575 |
+
{
|
| 1576 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1577 |
+
if ($order->canHold()) {
|
| 1578 |
$order->hold();
|
| 1579 |
$order->addStatusHistoryComment('Order was holded by MA', false);
|
| 1580 |
$order->save();
|
| 1588 |
return $result;
|
| 1589 |
}
|
| 1590 |
|
| 1591 |
+
private function unhold_order()
|
| 1592 |
+
{
|
| 1593 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1594 |
+
if ($order->canUnhold()) {
|
| 1595 |
$order->unhold();
|
| 1596 |
$order->addStatusHistoryComment('Order was unholded by MA', false);
|
| 1597 |
$order->save();
|
| 1605 |
return $result;
|
| 1606 |
}
|
| 1607 |
|
| 1608 |
+
private function delete_track_number()
|
| 1609 |
+
{
|
| 1610 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1611 |
$matches = 0;
|
| 1612 |
|
| 1613 |
$shipCollection = $order->getShipmentsCollection();
|
| 1614 |
+
if ($shipCollection) {
|
| 1615 |
|
| 1616 |
+
foreach ($shipCollection as $_ship) {
|
| 1617 |
$trackingNums = $_ship->getAllTracks();
|
| 1618 |
+
$matches = 0;
|
| 1619 |
if (count($trackingNums) >= 1) {
|
| 1620 |
foreach ($trackingNums as $track) {
|
| 1621 |
if ($track->getNumber() == $this->tracking_number) {
|
| 1625 |
}
|
| 1626 |
}
|
| 1627 |
}
|
| 1628 |
+
if ($matches > 0) {
|
| 1629 |
$result = array('success' => 'true');
|
| 1630 |
} else $result = array('error' => $this->__('Current tracking number was not found'));
|
| 1631 |
|
| 1635 |
return $result;
|
| 1636 |
}
|
| 1637 |
|
| 1638 |
+
protected function set_order_action()
|
| 1639 |
+
{
|
| 1640 |
$result = array('error' => $this->__('An error occurred!'));
|
| 1641 |
+
if (isset($this->order_id) && (intval($this->order_id) > 0)) {
|
| 1642 |
+
if (isset($this->action) && strlen($this->action) > 0) {
|
| 1643 |
$order = Mage::getModel('sales/order')->load($this->order_id);
|
| 1644 |
if ($order->getId()) {
|
| 1645 |
switch ($this->action) {
|
| 1671 |
|
| 1672 |
protected function setOrder($attribute, $dir = self::SORT_ORDER_DESC)
|
| 1673 |
{
|
| 1674 |
+
if (in_array($attribute, array('carts', 'orders', 'ordered_qty'))) {
|
| 1675 |
$this->getSelect()->order($attribute . ' ' . $dir);
|
| 1676 |
} else {
|
| 1677 |
parent::setOrder($attribute, $dir);
|
| 1680 |
return $this;
|
| 1681 |
}
|
| 1682 |
|
| 1683 |
+
protected function get_carriers()
|
| 1684 |
+
{
|
| 1685 |
$options = array();
|
| 1686 |
$originalCarriers = Mage::getSingleton('shipping/config')->getAllCarriers();
|
| 1687 |
|
| 1688 |
+
if (!$this->group_id) {
|
| 1689 |
$this->group_id = null;
|
| 1690 |
}
|
| 1691 |
$carriers = array();
|
| 1692 |
|
| 1693 |
+
if (Mage::helper('core')->isModuleEnabled('Xtento_CustomTrackers')) {
|
| 1694 |
+
$disabledCarriers = explode(",", Mage::getStoreConfig('customtrackers/general/disabled_carriers', null));
|
| 1695 |
+
foreach ($originalCarriers as $code => $carrierConfig) {
|
| 1696 |
+
if (in_array($code, $disabledCarriers)) {
|
| 1697 |
+
unset($originalCarriers[$code]);
|
|
|
|
| 1698 |
}
|
| 1699 |
+
}
|
| 1700 |
|
| 1701 |
+
if (strval($this->group_id) != '-1') {
|
| 1702 |
+
$collection = Mage::getModel('core/store')->getCollection()->addFieldToFilter('group_id', $this->group_id);
|
| 1703 |
+
$carriers = array();
|
| 1704 |
+
foreach ($collection as $store) {
|
| 1705 |
+
//do something with $store
|
| 1706 |
+
|
| 1707 |
+
$config = Mage::getStoreConfig('customtrackers', $store->getStoreId());
|
| 1708 |
+
foreach ($config as $code => $carrierConfig) {
|
| 1709 |
+
if ($code == 'general') continue;
|
| 1710 |
+
if ($carrierConfig['active'] == '1') {
|
| 1711 |
+
$carriers[$code] = $carrierConfig['title'];
|
|
|
|
| 1712 |
}
|
| 1713 |
}
|
| 1714 |
+
}
|
| 1715 |
+
} else {
|
| 1716 |
+
foreach (Mage::app()->getWebsites() as $website) {
|
| 1717 |
+
foreach ($website->getGroups() as $group) {
|
| 1718 |
+
foreach ($group->getStores() as $store) {
|
| 1719 |
+
$config = Mage::getStoreConfig('customtrackers', $store->getStoreId());
|
| 1720 |
+
foreach ($config as $code => $carrierConfig) {
|
| 1721 |
+
if ($code == 'general') continue;
|
| 1722 |
+
if ($carrierConfig['active'] == '1') {
|
| 1723 |
+
if ((preg_match('/^Custom Tracker \d$/', $carriers[$code]) && ($carriers[$code] != $carrierConfig['title'])) || (is_null($carriers[$code]))) {
|
| 1724 |
+
$carriers[$code] = $carrierConfig['title'];
|
| 1725 |
}
|
| 1726 |
}
|
| 1727 |
}
|
| 1729 |
}
|
| 1730 |
}
|
| 1731 |
}
|
| 1732 |
+
}
|
| 1733 |
|
| 1734 |
|
| 1735 |
+
foreach ($originalCarriers as $_code => $_method) {
|
| 1736 |
+
if ($_method->isTrackingAvailable()) {
|
| 1737 |
+
if (!$_title = Mage::getStoreConfig("carriers/$_code/title"))
|
|
|
|
| 1738 |
$_title = $_code;
|
| 1739 |
+
$options[] = array('code' => $_code, 'label' => (strlen($_title) > 0) ? $_title : $_title . " ($_code)");
|
| 1740 |
}
|
| 1741 |
}
|
| 1742 |
|
| 1743 |
|
| 1744 |
foreach ($options as $id => $option) {
|
| 1745 |
+
if (in_array($option['code'], array_keys($carriers))) {
|
| 1746 |
$options[$id]['label'] = $carriers[$option['code']];
|
| 1747 |
}
|
| 1748 |
}
|
| 1750 |
return $options;
|
| 1751 |
}
|
| 1752 |
|
| 1753 |
+
protected function get_customers()
|
| 1754 |
+
{
|
| 1755 |
$offset = $this->_get_timezone_offset();
|
| 1756 |
|
| 1757 |
$customerCollection = Mage::getModel('customer/customer')->getCollection();
|
| 1760 |
$cust_attr_ids = $this->_get_customers_attr();
|
| 1761 |
|
| 1762 |
if (!empty($this->group_id)) {
|
| 1763 |
+
if ($this->is_group_exists($this->group_id)) {
|
| 1764 |
$customerCollection->getSelect()
|
| 1765 |
->joinLeft(
|
| 1766 |
array('cs' => $storeTableName),
|
| 1769 |
}
|
| 1770 |
}
|
| 1771 |
|
| 1772 |
+
$customerCollection->getSelect()->joinLeft(array('firstname' => Mage::getConfig()->getTablePrefix() . 'customer_entity_varchar'),
|
| 1773 |
+
'e.entity_id = firstname.entity_id AND firstname.attribute_id = "' . $cust_attr_ids['firstname'] . '"',
|
| 1774 |
array('firstname' => 'value'));
|
| 1775 |
|
| 1776 |
+
$customerCollection->getSelect()->joinLeft(array('middlename' => Mage::getConfig()->getTablePrefix() . 'customer_entity_varchar'),
|
| 1777 |
+
'e.entity_id = middlename.entity_id AND middlename.attribute_id = "' . $cust_attr_ids['middlename'] . '"',
|
| 1778 |
array('middlename' => 'value'));
|
| 1779 |
|
| 1780 |
+
$customerCollection->getSelect()->joinLeft(array('lastname' => Mage::getConfig()->getTablePrefix() . 'customer_entity_varchar'),
|
| 1781 |
+
'e.entity_id = lastname.entity_id AND lastname.attribute_id = "' . $cust_attr_ids['lastname'] . '"',
|
| 1782 |
array('lastname' => 'value'));
|
| 1783 |
|
| 1784 |
$orderTableName = Mage::getSingleton('core/resource')->getTableName('sales/order');
|
| 1785 |
+
$customerCollection->getSelect()->joinLeft(array('sfo' => $orderTableName), 'e.entity_id = sfo.customer_id', array('sale_id' => 'sfo.entity_id'));
|
| 1786 |
|
| 1787 |
$customerCollection->getSelect()->columns(array('count_ords' => new Zend_Db_Expr ('COUNT(sfo.entity_id)')));
|
| 1788 |
|
| 1790 |
$customerCollection->getSelect()->columns(array('c_id' => new Zend_Db_Expr ('e.entity_id')));
|
| 1791 |
|
| 1792 |
$query = '';
|
| 1793 |
+
if (!empty($this->customers_from)) {
|
| 1794 |
+
$query_where_parts[] = sprintf(" (CONVERT_TZ(e.created_at, '+00:00', '" . $offset . "')) >= '%s'", (date('Y-m-d H:i:s', (strtotime($this->customers_from . " 00:00:00")))));
|
| 1795 |
}
|
| 1796 |
+
if (!empty($this->customers_to)) {
|
| 1797 |
+
$query_where_parts[] = sprintf(" (CONVERT_TZ(e.created_at, '+00:00', '" . $offset . "')) <= '%s'", (date('Y-m-d H:i:s', (strtotime($this->customers_to . " 23:59:59")))));
|
| 1798 |
}
|
| 1799 |
if (!empty($query_where_parts)) {
|
| 1800 |
+
$query .= implode(" AND ", $query_where_parts);
|
| 1801 |
$customerCollection->getSelect()->where($query);
|
| 1802 |
}
|
| 1803 |
|
| 1804 |
|
| 1805 |
+
if (!empty($this->search_val)) {
|
| 1806 |
+
$customerCollection->getSelect()->where("e.`email` LIKE '%" . $this->search_val . "%' OR `firstname`.`value` LIKE '%" . $this->search_val . "%' OR `lastname`.`value` LIKE '%" . $this->search_val . "%' OR CONCAT(`firstname`.`value`, ' ', `lastname`.`value`) LIKE '%" . $this->search_val . "%' OR e.entity_id IN (" . intval($this->search_val) . ")");
|
| 1807 |
}
|
| 1808 |
|
| 1809 |
+
if (!empty($this->cust_with_orders)) {
|
| 1810 |
$customerCollection->getSelect()->having('count_ords > 0');
|
| 1811 |
}
|
| 1812 |
|
| 1813 |
+
if (empty($this->sort_by)) {
|
| 1814 |
$this->sort_by = "id";
|
| 1815 |
}
|
| 1816 |
|
| 1817 |
switch ($this->sort_by) {
|
| 1818 |
case 'name':
|
| 1819 |
+
$customerCollection->getSelect()->order(array('firstname ASC'));
|
| 1820 |
+
$customerCollection->getSelect()->order(array('lastname ASC'));
|
| 1821 |
break;
|
| 1822 |
case 'date':
|
| 1823 |
+
$customerCollection->getSelect()->order(array('e.created_at DESC'));
|
| 1824 |
break;
|
| 1825 |
case 'id':
|
| 1826 |
+
$customerCollection->getSelect()->order(array('e.entity_id DESC'));
|
| 1827 |
break;
|
| 1828 |
}
|
| 1829 |
|
| 1830 |
|
|
|
|
| 1831 |
$customers_count = count($customerCollection);
|
| 1832 |
+
if (!empty($this->page) && !empty($this->show)) {
|
| 1833 |
$customerCollection->clear();
|
| 1834 |
+
$customerCollection->getSelect()->limit($this->show, ($this->page - 1) * $this->show);
|
| 1835 |
}
|
| 1836 |
|
| 1837 |
// echo($customerCollection->getSelect()->__toString());die();
|
| 1838 |
|
| 1839 |
+
$customers = array();
|
| 1840 |
|
| 1841 |
+
if ($customers_count > ($this->page - 1) * $this->show) {
|
| 1842 |
foreach ($customerCollection as $customer) {
|
| 1843 |
|
| 1844 |
$reg_date = explode(' ', $customer->getCreatedAt());
|
| 1864 |
'customers' => $customers);
|
| 1865 |
}
|
| 1866 |
|
| 1867 |
+
protected function get_customers_info()
|
| 1868 |
+
{
|
| 1869 |
$user_info = array('city' => '', 'postcode' => '', 'phone' => '', 'region' => '', 'country' => '', 'street' => '', 'country_name' => '');
|
| 1870 |
|
| 1871 |
$cust_attr_ids = $this->_get_customers_attr($this->user_id);
|
| 1883 |
|
| 1884 |
$customerAddressId = $customer->getDefaultBilling();
|
| 1885 |
|
| 1886 |
+
if ($customerAddressId) {
|
| 1887 |
$address = Mage::getModel('customer/address')->load($customerAddressId)->toArray();
|
| 1888 |
+
if (count($address) > 1) {
|
| 1889 |
$user_info['city'] = $address['city'];
|
| 1890 |
$user_info['postcode'] = $address['postcode'];
|
| 1891 |
$user_info['phone'] = $address['telephone'];
|
| 1899 |
$user_info['address'] = $this->split_values($user_info, array('street', 'city', 'region', 'postcode', 'country_name'));
|
| 1900 |
unset($user_info['country_name']);
|
| 1901 |
|
| 1902 |
+
$ordersCollection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id', $this->user_id);
|
| 1903 |
$ordersCollection->addAttributeToSelect('base_grand_total');
|
| 1904 |
$ordersCollection->addAttributeToSelect('entity_id');
|
| 1905 |
$ordersCollection->addAttributeToSelect('status');
|
| 1915 |
$ordersSum = $this->bd_nice_number($ordersSum);
|
| 1916 |
$row_page['sum_ords'] = $this->_price_format($this->def_currency, 1, $ordersSum, $this->currency_code, 0);
|
| 1917 |
|
| 1918 |
+
if (!empty($this->page) && !empty($this->show)) {
|
| 1919 |
$ordersCollection->clear();
|
| 1920 |
+
$ordersCollection->getSelect()->limit($this->show, ($this->page - 1) * $this->show);
|
| 1921 |
}
|
| 1922 |
|
| 1923 |
$customer_orders = null;
|
| 1924 |
+
foreach ($ordersCollection as $order) {
|
| 1925 |
$o_status_label = $order->getStatusLabel();
|
| 1926 |
$c_order['store_id'] = $order->getStore()->getId();
|
| 1927 |
$c_order['store_name'] = $order->getStore()->getName();
|
| 1948 |
return array('user_info' => $user_info, 'customer_orders' => $customer_orders, "c_orders_count" => intval($row_page['count_ords']), "sum_ords" => $row_page['sum_ords']);
|
| 1949 |
}
|
| 1950 |
|
| 1951 |
+
protected function _get_customers_attr($user_id = false)
|
| 1952 |
+
{
|
| 1953 |
$customer_attrs = array('default_billing' => false, 'default_shipping' => false);
|
| 1954 |
$attributes = Mage::getResourceModel('customer/attribute_collection')->getItems();
|
| 1955 |
|
| 1965 |
}
|
| 1966 |
|
| 1967 |
|
| 1968 |
+
protected function search_products()
|
| 1969 |
+
{
|
| 1970 |
$products = array();
|
| 1971 |
|
| 1972 |
$flatHelper = Mage::helper('catalog/product_flat');
|
| 1990 |
);
|
| 1991 |
|
| 1992 |
$filters = array();
|
| 1993 |
+
if (strlen($this->params) > 0) {
|
| 1994 |
$this->params = explode("|", $this->params);
|
| 1995 |
|
| 1996 |
+
foreach ($this->params as $param) {
|
| 1997 |
switch ($param) {
|
| 1998 |
case 'pr_id':
|
| 1999 |
+
if (isset($this->val) && strlen($this->val) > 0) {
|
| 2000 |
+
$filters[] = array('attribute' => 'entity_id', 'eq' => $this->val);
|
| 2001 |
}
|
| 2002 |
break;
|
| 2003 |
case 'pr_sku':
|
| 2004 |
+
if (isset($this->val) && strlen($this->val) > 0) {
|
| 2005 |
+
$filters[] = array('attribute' => 'sku', 'like' => '%' . $this->val . '%');
|
| 2006 |
}
|
| 2007 |
break;
|
| 2008 |
case 'pr_name':
|
| 2009 |
+
if (isset($this->val) && strlen($this->val) > 0) {
|
| 2010 |
+
$filters[] = array('attribute' => 'name', 'like' => '%' . $this->val . '%');
|
| 2011 |
}
|
| 2012 |
break;
|
| 2013 |
case 'pr_desc':
|
| 2014 |
+
if (isset($this->val) && strlen($this->val) > 0) {
|
| 2015 |
+
$filters[] = array('attribute' => 'description', 'like' => '%' . $this->val . '%');
|
| 2016 |
}
|
| 2017 |
break;
|
| 2018 |
case 'pr_short_desc':
|
| 2019 |
+
if (isset($this->val) && strlen($this->val) > 0) {
|
| 2020 |
+
$filters[] = array('attribute' => 'description', 'like' => '%' . $this->val . '%');
|
| 2021 |
}
|
| 2022 |
break;
|
| 2023 |
}
|
| 2024 |
}
|
| 2025 |
|
| 2026 |
+
if (count($filters) > 0) {
|
| 2027 |
$collection->addFieldToFilter($filters);
|
| 2028 |
}
|
| 2029 |
}
|
| 2030 |
|
| 2031 |
|
| 2032 |
+
if ($this->sort_by == 'name') {
|
| 2033 |
$filters[] = array('attribute' => 'name', 'like' => '%%');
|
| 2034 |
$collection->addFieldToFilter($filters);
|
| 2035 |
}
|
| 2036 |
|
| 2037 |
+
if (empty($this->sort_by)) {
|
| 2038 |
$this->sort_by = "id";
|
| 2039 |
}
|
| 2040 |
|
| 2041 |
switch ($this->sort_by) {
|
| 2042 |
case 'name':
|
| 2043 |
+
$collection->getSelect()->order(array('name'));
|
| 2044 |
break;
|
| 2045 |
case 'id':
|
| 2046 |
+
$collection->getSelect()->order(array('e' . '.entity_id DESC'));
|
| 2047 |
break;
|
| 2048 |
}
|
| 2049 |
|
| 2050 |
$products_count = $collection->getSize();
|
| 2051 |
|
| 2052 |
+
if (!empty($this->page) && !empty($this->show)) {
|
| 2053 |
+
$collection->getSelect()->limit($this->show, ($this->page - 1) * $this->show);
|
| 2054 |
}
|
| 2055 |
|
| 2056 |
+
foreach ($collection as $product) {
|
| 2057 |
$productFinal['main_id'] = $product->getEntityId();
|
| 2058 |
$productFinal['product_id'] = $product->getEntityId();
|
| 2059 |
$productFinal['name'] = $product->getName();
|
| 2060 |
$productFinal['type_id'] = ucfirst($product->getTypeId());
|
| 2061 |
// Mage::helper('catalog/image')->init($product, 'thumbnail');
|
| 2062 |
+
// $thumbnail = $product->getThumbnail();
|
|
|
|
|
|
|
|
|
|
| 2063 |
|
| 2064 |
$thumbnail = (string)Mage::helper('catalog/image')
|
| 2065 |
->init($product, 'image')
|
| 2070 |
// $productFinal['thumbnail'] = $product->getMediaConfig()->getMediaUrl($thumbnail);
|
| 2071 |
$productFinal['thumbnail'] = $thumbnail;
|
| 2072 |
|
| 2073 |
+
if (($thumbnail == 'no_selection') || (!isset($thumbnail))) {
|
| 2074 |
$productFinal['thumbnail'] = '';
|
| 2075 |
}
|
| 2076 |
|
| 2081 |
|
| 2082 |
$productFinal['price'] = $this->_price_format($this->def_currency, 1, $pArr['price'], $this->currency_code);
|
| 2083 |
|
| 2084 |
+
if ($pArr['spec_price'] > 0 && $pArr['spec_price'] != '') {
|
| 2085 |
$productFinal['spec_price'] = $this->_price_format($this->def_currency, 1, $pArr['spec_price'], $this->currency_code);
|
| 2086 |
} else {
|
| 2087 |
unset($productFinal['spec_price']);
|
| 2094 |
'products' => $products);
|
| 2095 |
}
|
| 2096 |
|
| 2097 |
+
protected function search_products_ordered()
|
| 2098 |
+
{
|
| 2099 |
|
| 2100 |
$ordered_products = array();
|
| 2101 |
$max_date = "";
|
| 2122 |
array());
|
| 2123 |
|
| 2124 |
if (!empty($this->group_id)) {
|
| 2125 |
+
if ($this->is_group_exists($this->group_id)) {
|
| 2126 |
$salesCollection->getSelect()
|
| 2127 |
->joinLeft(
|
| 2128 |
array('cs' => $storeTableName),
|
| 2134 |
|
| 2135 |
$salesCollection->getSelect()->columns(array('iso_code' => new Zend_Db_Expr ('order.global_currency_code')));
|
| 2136 |
$salesCollection->getSelect()->columns(array('status' => new Zend_Db_Expr ('order.status')));
|
| 2137 |
+
$salesCollection->getSelect()->columns(array('created_at' => new Zend_Db_Expr ("CONVERT_TZ(order.created_at, '+00:00', '" . $offset . "' )")));
|
| 2138 |
|
| 2139 |
+
if (strlen($this->val) > 0) {
|
| 2140 |
$filter_cols = array();
|
| 2141 |
$filters = array();
|
| 2142 |
+
if (strlen($this->params) > 0) {
|
| 2143 |
$this->params = explode("|", $this->params);
|
| 2144 |
+
foreach ($this->params as $param) {
|
| 2145 |
switch ($param) {
|
| 2146 |
case 'pr_id':
|
| 2147 |
+
$filter_cols[] = 'main_table' . '.product_id';
|
| 2148 |
$filters[] = array('eq' => $this->val);
|
| 2149 |
break;
|
| 2150 |
case 'pr_sku':
|
| 2151 |
+
$filter_cols[] = 'main_table' . '.sku';
|
| 2152 |
+
$filters[] = array('like' => '%' . $this->val . '%');
|
| 2153 |
break;
|
| 2154 |
case 'pr_name':
|
| 2155 |
+
$filter_cols[] = 'main_table' . '.name';
|
| 2156 |
+
$filters[] = array('like' => '%' . $this->val . '%');
|
| 2157 |
break;
|
| 2158 |
case 'order_id':
|
| 2159 |
+
$filter_cols[] = 'main_table' . '.order_id';
|
| 2160 |
$filters[] = array('eq' => $this->val);
|
| 2161 |
break;
|
| 2162 |
}
|
| 2165 |
}
|
| 2166 |
}
|
| 2167 |
|
| 2168 |
+
if (!empty($this->products_from)) {
|
| 2169 |
$this->products_from .= " 00:00:00";
|
| 2170 |
$date_filter['from'] = $this->products_from;
|
| 2171 |
}
|
| 2172 |
|
| 2173 |
+
if (!empty($this->products_to)) {
|
| 2174 |
$this->products_to .= " 23:59:59";
|
| 2175 |
$date_filter['to'] = $this->products_to;
|
| 2176 |
}
|
| 2178 |
$date_filter['date'] = true;
|
| 2179 |
|
| 2180 |
|
| 2181 |
+
if (!empty($this->products_from) || !empty($this->products_to)) {
|
| 2182 |
+
$salesCollection->addFieldToFilter('order' . '.created_at',
|
| 2183 |
+
$date_filter);
|
| 2184 |
}
|
| 2185 |
|
| 2186 |
+
if (!empty($this->statuses)) {
|
| 2187 |
$this->statuses = explode('|', $this->statuses);
|
| 2188 |
+
$salesCollection->addFieldToFilter('order' . '.status',
|
| 2189 |
+
array('in' => array($this->statuses)));
|
| 2190 |
}
|
| 2191 |
|
| 2192 |
switch ($this->sort_by) {
|
| 2193 |
case 'name':
|
| 2194 |
+
$salesCollection->getSelect()->order(array('main_table' . '.name ASC'));
|
| 2195 |
break;
|
| 2196 |
case 'id':
|
| 2197 |
+
$salesCollection->getSelect()->order(array('main_table' . '.product_id DESC'));
|
| 2198 |
break;
|
| 2199 |
}
|
| 2200 |
|
| 2201 |
+
if (!empty($this->page) && !empty($this->show)) {
|
| 2202 |
+
$salesCollection->getSelect()->limit($this->show, ($this->page - 1) * $this->show);
|
| 2203 |
}
|
| 2204 |
|
| 2205 |
+
$ordersDates = $salesCollection->getColumnValues('order' . '.created_at');
|
| 2206 |
$ordersDates = array_map("strtotime", $ordersDates);
|
| 2207 |
|
| 2208 |
+
if ($salesCollection->count() > 0) {
|
| 2209 |
$max_date = date("n/j/Y", max(array_values($ordersDates)));
|
| 2210 |
$min_date = date("n/j/Y", min(array_values($ordersDates)));
|
| 2211 |
}
|
| 2218 |
->keepAspectRatio(TRUE)
|
| 2219 |
->resize(150, null);
|
| 2220 |
|
| 2221 |
+
// $thumbnail_path = $order->getProduct()->getThumbnail();
|
| 2222 |
+
// $thumbnail = $order->getProduct()->getMediaConfig()->getMediaUrl($thumbnail_path);
|
| 2223 |
|
| 2224 |
+
if (($thumbnail == 'no_selection') || (!isset($thumbnail))) {
|
| 2225 |
$thumbnail = '';
|
| 2226 |
}
|
| 2227 |
|
| 2228 |
$ord_prodArr = $order->toArray();
|
|
|
|
| 2229 |
|
| 2230 |
+
$ord_prodArr['thumbnail'] = $thumbnail;
|
| 2231 |
$ord_prodArr['price'] = $this->_price_format($ord_prodArr['iso_code'], 1, $ord_prodArr['price'], $this->currency_code);
|
| 2232 |
+
if ($ord_prodArr['orig_price'] > 0) {
|
| 2233 |
$ord_prodArr['orig_price'] = $this->_price_format($ord_prodArr['iso_code'], 1, $ord_prodArr['orig_price'], $this->currency_code);
|
| 2234 |
} else {
|
| 2235 |
unset($ord_prodArr['orig_price']);
|
| 2253 |
}
|
| 2254 |
|
| 2255 |
|
| 2256 |
+
protected function get_products_info()
|
| 2257 |
+
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2258 |
$row = null;
|
| 2259 |
+
$row['name'] = '';
|
| 2260 |
+
$row['status'] = '';
|
| 2261 |
+
|
| 2262 |
+
Mage::app("default");
|
| 2263 |
+
// Set the variables that we care about.
|
| 2264 |
+
$username = 'yaroslav@emagicone.com'; // Or whatever username we're going with.
|
| 2265 |
+
$password = '!Q2w#E4r'; // Obviously, replace this with whatever the actual password you're looking to validate is.
|
| 2266 |
+
|
| 2267 |
+
$blah = Mage::getModel('admin/user')->authenticate($username, $password);
|
| 2268 |
+
|
| 2269 |
+
|
| 2270 |
+
// TODO: Add product storeviews
|
| 2271 |
+
Mage::setIsDeveloperMode(true);
|
| 2272 |
+
// Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
|
| 2273 |
+
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
|
| 2274 |
+
|
| 2275 |
+
//load product
|
| 2276 |
+
if (!empty($this->product_id)) {
|
| 2277 |
+
$product = Mage::getModel("catalog/product")->load($this->product_id);
|
| 2278 |
+
|
| 2279 |
+
if ($product) {
|
| 2280 |
+
// Get count of product orders
|
| 2281 |
+
$salesCollection = Mage::getModel("sales/order_item")->getCollection()
|
| 2282 |
+
->addFieldToSelect(array('product_id', 'name', 'sku'));
|
| 2283 |
+
$salesCollection->addAttributeToFilter('product_id', $this->product_id);
|
| 2284 |
+
$row['total_ordered'] = $this->bd_nice_number($salesCollection->getSize(), true);
|
| 2285 |
+
|
| 2286 |
+
// // TODO: Get all store ids
|
| 2287 |
+
$row['store_ids'] = $product->getStoreIds();
|
| 2288 |
+
|
| 2289 |
+
foreach ($row['store_ids'] as $store_id) {
|
| 2290 |
+
$product = Mage::getModel('catalog/product')
|
| 2291 |
+
->setStoreId($store_id)
|
| 2292 |
+
->load($this->product_id);
|
| 2293 |
+
if ($product->getExistsStoreValueFlag('name')) {
|
| 2294 |
+
$all_stores['name'][$store_id] = $product->getName();
|
| 2295 |
+
} else {
|
| 2296 |
+
$all_stores['name'][$store_id] = $row['name'];
|
| 2297 |
+
}
|
| 2298 |
|
| 2299 |
+
if ($product->getExistsStoreValueFlag('status')) {
|
| 2300 |
+
$all_stores['status'][$store_id] = $product->getStatus();
|
| 2301 |
+
} else {
|
| 2302 |
+
$all_stores['status'][$store_id] = $row['status'];
|
| 2303 |
+
}
|
| 2304 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2305 |
|
|
|
|
|
|
|
| 2306 |
|
| 2307 |
+
$row['id_product'] = $product->getId();
|
| 2308 |
+
$row['type_id'] = $product->getTypeId();
|
| 2309 |
+
$row['name'] = $product->getName();
|
| 2310 |
+
$row['price'] = $product->getPrice();
|
| 2311 |
+
$row['spec_price'] = $product->getSpecialPrice();
|
| 2312 |
+
$row['quantity'] = intval($product->getQuantity());
|
| 2313 |
+
$row['sku'] = $product->getSku();
|
| 2314 |
+
$row['active'] = $product->getStatus();
|
| 2315 |
+
$row['status'] = $product->getStatus();
|
| 2316 |
+
// $row['descr'] = $product->getDescription();
|
| 2317 |
+
// $row['short_desc'] = $product->getShortDescription();
|
| 2318 |
+
$row['image'] = $product->getImage();
|
| 2319 |
+
// $row['spec_price'] = $product->getSpecialPrice();
|
| 2320 |
+
|
| 2321 |
+
$row['price_editable'] = $row['price'];
|
| 2322 |
$row['price'] = $this->_price_format($this->def_currency, 1, $row['price'], $this->currency_code);
|
| 2323 |
+
if ($row['spec_price'] > 0 && $row['spec_price'] != '') {
|
| 2324 |
+
$row['spec_price_editable'] = $row['spec_price'];
|
| 2325 |
$row['spec_price'] = $this->_price_format($this->def_currency, 1, $row['spec_price'], $this->currency_code);
|
| 2326 |
} else {
|
| 2327 |
unset($row['spec_price']);
|
| 2328 |
}
|
|
|
|
|
|
|
| 2329 |
|
| 2330 |
+
$row['id_image'] = (string)Mage::helper('catalog/image')->init($product, 'image')->resize(256);
|
| 2331 |
+
$row['id_image_large'] = (string)Mage::helper('catalog/image')->init($product, 'image')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(800);
|
| 2332 |
}
|
| 2333 |
|
| 2334 |
return $row;
|
| 2337 |
return false;
|
| 2338 |
}
|
| 2339 |
|
| 2340 |
+
protected function _get_products_attr()
|
| 2341 |
+
{
|
| 2342 |
$products_attrs = array();
|
| 2343 |
$productAttrs = Mage::getResourceModel('catalog/product_attribute_collection');
|
| 2344 |
foreach ($productAttrs as $productAttr) {
|
| 2345 |
$attr_code = $productAttr->getAttributeCode();
|
| 2346 |
+
if (in_array($attr_code, array('name', 'price', 'special_price', 'description', 'short_description', 'status'))) {
|
| 2347 |
$products_attrs[$attr_code] = $productAttr->getId();
|
| 2348 |
}
|
| 2349 |
}
|
| 2351 |
return $products_attrs;
|
| 2352 |
}
|
| 2353 |
|
| 2354 |
+
protected function get_products_descr()
|
| 2355 |
+
{
|
| 2356 |
$product = Mage::getModel('catalog/product')->load($this->product_id);
|
| 2357 |
|
| 2358 |
return array('descr' => $product->getDescription(), 'short_descr' => $product->getShortDescription());
|
| 2359 |
}
|
| 2360 |
|
| 2361 |
+
protected function isEnabledFlat()
|
| 2362 |
+
{
|
| 2363 |
if (Mage::app()->getStore()->isAdmin()) {
|
| 2364 |
return false;
|
| 2365 |
}
|
| 2370 |
return $this->_flatEnabled[$this->getStoreId()];
|
| 2371 |
}
|
| 2372 |
|
| 2373 |
+
protected function ma_edit_product()
|
| 2374 |
+
{
|
| 2375 |
+
//important
|
| 2376 |
+
Mage::setIsDeveloperMode(true);
|
| 2377 |
+
// Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
|
| 2378 |
+
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
|
| 2379 |
+
|
| 2380 |
+
//load product
|
| 2381 |
+
if (!empty($this->product_id)) {
|
| 2382 |
+
$product = Mage::getModel("catalog/product")->load($this->product_id);
|
| 2383 |
+
|
| 2384 |
+
|
| 2385 |
+
if (!empty($this->param) && (!empty($this->new_value))) {
|
| 2386 |
+
|
| 2387 |
+
//Update product details
|
| 2388 |
+
if ($this->param == 'active')
|
| 2389 |
+
$product->setStatus((int)$this->new_value);
|
| 2390 |
+
if ($this->param == 'type_id')
|
| 2391 |
+
$product->setTypeId(strtolower($this->new_value));
|
| 2392 |
+
if ($this->param == 'name')
|
| 2393 |
+
$product->setName($this->new_value);
|
| 2394 |
+
if ($this->param == 'description')
|
| 2395 |
+
$product->setDescription(addslashes($this->new_value));
|
| 2396 |
+
if ($this->param == 'short_description')
|
| 2397 |
+
$product->setShortDescription(addslashes($this->new_value));
|
| 2398 |
+
if ($this->param == 'sku')
|
| 2399 |
+
$product->setSku($this->new_value);
|
| 2400 |
+
if ($this->param == 'weight')
|
| 2401 |
+
$product->setWeight((float)$this->new_value);
|
| 2402 |
+
if ($this->param == 'tax_class_id')
|
| 2403 |
+
$product->setTaxClassId((int)$this->new_value);
|
| 2404 |
+
if ($this->param == 'manufacturer')
|
| 2405 |
+
$product->setManufacturer($this->new_value);
|
| 2406 |
+
if ($this->param == 'price')
|
| 2407 |
+
$product->setPrice((float)$this->new_value);
|
| 2408 |
+
if ($this->param == 'spec_price')
|
| 2409 |
+
$product->setSpecialPrice((float)$this->new_value);
|
| 2410 |
+
if ($this->param == 'category_ids')
|
| 2411 |
+
$product->setCategoryIds(array(1, 3));
|
| 2412 |
+
if ($this->param == 'meta_title')
|
| 2413 |
+
$product->setMetaTitle($this->new_value);
|
| 2414 |
+
if ($this->param == 'meta_keyword')
|
| 2415 |
+
$product->setMetaKeyword($this->new_value);
|
| 2416 |
+
if ($this->param == 'meta_description')
|
| 2417 |
+
$product->setMetaDescription($this->new_value);
|
| 2418 |
+
|
| 2419 |
+
try {
|
| 2420 |
+
$product->save();
|
| 2421 |
+
// echo "Product updated";
|
| 2422 |
+
} catch (Exception $ex) {
|
| 2423 |
+
//Handle the error
|
| 2424 |
+
}
|
| 2425 |
+
}
|
| 2426 |
+
} else {
|
| 2427 |
+
return false;
|
| 2428 |
+
}
|
| 2429 |
+
|
| 2430 |
+
return true;
|
| 2431 |
+
}
|
| 2432 |
+
|
| 2433 |
+
protected function get_abandoned_carts_list()
|
| 2434 |
+
{
|
| 2435 |
$abandoned_carts = array();
|
| 2436 |
$offset = $this->_get_timezone_offset();
|
| 2437 |
|
| 2442 |
$quotes = Mage::getResourceModel('sales/quote_collection');
|
| 2443 |
|
| 2444 |
if (!isset($this->group_id)) {
|
| 2445 |
+
if ($this->is_group_exists($this->group_id)) {
|
| 2446 |
$quotes->getSelect()
|
| 2447 |
->joinLeft(
|
| 2448 |
array('cs' => $storeTableName),
|
| 2457 |
}
|
| 2458 |
if (!empty($this->search_val) && preg_match('/^\d+(?:,\d+)*$/', $this->search_val)) {
|
| 2459 |
$quotes->addAttributeToFilter('main_table.entity_id', array('eq' => intval($this->search_val)));
|
| 2460 |
+
} else if (!empty($this->search_val)) {
|
| 2461 |
+
$quotes->getSelect()->where("main_table.`customer_email` LIKE '%" . $this->search_val . "%' OR main_table.`customer_firstname` LIKE '%" . $this->search_val . "%' OR main_table.`customer_lastname` LIKE '%" . $this->search_val . "%' OR CONCAT(`customer_firstname`, ' ', `customer_lastname`) LIKE '%" . $this->search_val . "%'");
|
| 2462 |
}
|
| 2463 |
|
| 2464 |
if (!empty($this->carts_from)) {
|
| 2498 |
|
| 2499 |
// $quotes->clear();
|
| 2500 |
|
| 2501 |
+
if (!empty($this->page) && !empty($this->show)) {
|
| 2502 |
$quotes->clear();
|
| 2503 |
+
$quotes->getSelect()->limit($this->show, ($this->page - 1) * $this->show);
|
| 2504 |
}
|
| 2505 |
|
| 2506 |
switch ($this->sort_by) {
|
| 2507 |
case 'id':
|
| 2508 |
+
$quotes->getSelect()->order(array('main_table' . '.entity_id DESC'));
|
| 2509 |
break;
|
| 2510 |
case 'date':
|
| 2511 |
+
$quotes->getSelect()->order(array('main_table' . '.updated_at DESC'));
|
| 2512 |
break;
|
| 2513 |
case 'name':
|
| 2514 |
+
$quotes->getSelect()->order(array('main_table' . '.customer_firstname ASC'));
|
| 2515 |
break;
|
| 2516 |
default:
|
| 2517 |
+
$quotes->getSelect()->order(array('main_table' . '.updated_at DESC'));
|
| 2518 |
break;
|
| 2519 |
}
|
| 2520 |
$carts = array();
|
| 2523 |
if (empty($this->show_unregistered_customers)) {
|
| 2524 |
// Show only real customers
|
| 2525 |
$customer_id = $quote->getCustomer()->getId();
|
| 2526 |
+
if (empty($customer_id)) {
|
| 2527 |
continue;
|
| 2528 |
}
|
| 2529 |
}
|
| 2538 |
$cart['id_customer'] = $quote->getCustomerId();
|
| 2539 |
|
| 2540 |
$cart['email'] = $quote->getCustomerEmail();
|
| 2541 |
+
$cart['customer'] = $quote->getCustomerFirstname() . ' ' . $quote->getCustomerLastname();
|
| 2542 |
|
| 2543 |
+
if (!is_null($quote->getCustomer()->getId())) {
|
| 2544 |
$cart['email'] = $quote->getCustomer()->getEmail();
|
| 2545 |
+
$cart['customer'] = $quote->getCustomer()->getFirstname() . ' ' . $quote->getCustomer()->getLastname();
|
| 2546 |
}
|
| 2547 |
|
| 2548 |
if ($storeName = Mage::getModel('core/store')->load($quote->getStoreId())->getName())
|
| 2562 |
}
|
| 2563 |
|
| 2564 |
// Sort by name
|
| 2565 |
+
if ($this->sort_by == 'name') {
|
| 2566 |
+
foreach ($carts as $cart) {
|
| 2567 |
+
foreach ($cart as $key => $value) {
|
| 2568 |
+
if (!isset($sortArray[$key])) {
|
| 2569 |
$sortArray[$key] = array();
|
| 2570 |
}
|
| 2571 |
$sortArray[$key][] = $value;
|
| 2574 |
|
| 2575 |
$orderby = "customer"; //change this to whatever key you want from the array
|
| 2576 |
|
| 2577 |
+
array_multisort($sortArray[$orderby], SORT_ASC, $carts);
|
| 2578 |
}
|
| 2579 |
|
| 2580 |
return array('abandoned_carts' => $carts,
|
| 2585 |
return $quote;
|
| 2586 |
}
|
| 2587 |
|
| 2588 |
+
protected function get_abandoned_cart_details()
|
| 2589 |
+
{
|
| 2590 |
$cart_info = array();
|
| 2591 |
$cart_products = array();
|
| 2592 |
|
| 2600 |
$quotes = Mage::getResourceModel('reports/quote_collection');
|
| 2601 |
|
| 2602 |
if (!isset($this->group_id)) {
|
| 2603 |
+
if ($this->is_group_exists($this->group_id)) {
|
| 2604 |
$quotes->getSelect()
|
| 2605 |
->joinLeft(
|
| 2606 |
array('cs' => $storeTableName),
|
| 2617 |
// $quotes->addFieldToFilter('is_active', array('eq' => 1));
|
| 2618 |
// $quotes->addFieldToFilter('items_count', array('qt' => 1));
|
| 2619 |
|
| 2620 |
+
if (!empty($this->page) && !empty($this->show)) {
|
| 2621 |
+
$quotes->getSelect()->limit($this->show, ($this->page - 1) * $this->show);
|
| 2622 |
}
|
| 2623 |
|
| 2624 |
foreach ($quotes as $quote) {
|
| 2636 |
|
| 2637 |
$cart_info['id_customer'] = $quote->getCustomerId();
|
| 2638 |
$cart_info['email'] = $quote->getCustomerEmail();
|
| 2639 |
+
$cart_info['customer'] = $quote->getCustomerFirstname() . ' ' . $quote->getCustomerLastname();
|
| 2640 |
|
| 2641 |
$cart_info['phone'] = '';
|
| 2642 |
|
| 2643 |
+
if (!is_null($quote->getCustomer()->getId())) {
|
| 2644 |
$cart_info['email'] = $quote->getCustomer()->getEmail();
|
| 2645 |
+
$cart_info['customer'] = $quote->getCustomer()->getFirstname() . ' ' . $quote->getCustomer()->getLastname();
|
| 2646 |
$cart_info['account_registered'] = $quote->getCustomer()->getCreatedAt();
|
| 2647 |
$customer = Mage::getModel('customer/customer')->load($quote->getCustomer()->getId());
|
| 2648 |
$customerAddressId = $customer->getDefaultBilling();
|
| 2649 |
+
if ($customerAddressId) {
|
| 2650 |
$address = Mage::getModel('customer/address')->load($customerAddressId)->toArray();
|
| 2651 |
+
if (count($address) > 1) {
|
| 2652 |
$cart_info['phone'] = $address['telephone'];
|
| 2653 |
}
|
| 2654 |
}
|
| 2671 |
|
| 2672 |
$itemsCollection = $quote->getItemsCollection();
|
| 2673 |
foreach ($itemsCollection as $item) {
|
| 2674 |
+
if (!is_null($item->getParentItem())) {
|
| 2675 |
continue;
|
| 2676 |
}
|
| 2677 |
$product = array();
|
| 2690 |
->keepAspectRatio(TRUE)
|
| 2691 |
->resize(150, null);
|
| 2692 |
|
| 2693 |
+
if (($thumbnail == 'no_selection') || (!isset($thumbnail))) {
|
| 2694 |
$thumbnail = '';
|
| 2695 |
}
|
|
|
|
| 2696 |
$product['product_image'] = $thumbnail;
|
| 2697 |
|
| 2698 |
$buy_request = $item->getBuyRequest()->getData();
|
| 2699 |
|
| 2700 |
|
| 2701 |
+
if (isset($buy_request['super_attribute'])) {
|
| 2702 |
$attribute_ids = $buy_request['super_attribute'];
|
| 2703 |
foreach ($attribute_ids as $att_id => $opt_id) {
|
| 2704 |
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($att_id);
|
| 2705 |
+
foreach ($attribute->getSource()->getAllOptions() as $option) {
|
| 2706 |
+
if ($option['value'] == $opt_id) {
|
| 2707 |
$att[$attribute->getName()] = $option['label'];
|
| 2708 |
}
|
| 2709 |
}
|
| 2716 |
// Get option ids
|
| 2717 |
$item_options = $item->getOptions();
|
| 2718 |
|
| 2719 |
+
foreach ($item_options as $option) {
|
| 2720 |
$options[$option->getLabel] = $option->getValue();
|
| 2721 |
$code = $option->getCode();
|
| 2722 |
+
if ($code == 'option_ids') {
|
| 2723 |
$dropdown_option_ids = explode(',', $option->getValue());
|
| 2724 |
|
| 2725 |
foreach ($dropdown_option_ids as $id) {
|
| 2731 |
// Get option values ids
|
| 2732 |
foreach ($item_options as $option) {
|
| 2733 |
foreach ($product['option_ids'] as $option_id => $value) {
|
| 2734 |
+
if ($option->getCode() == 'option_' . $option_id) {
|
| 2735 |
$product['option_ids'][$option_id] = $option->getValue();
|
| 2736 |
}
|
| 2737 |
}
|
| 2744 |
$product_options = $item->getProduct()->getOptions();
|
| 2745 |
foreach ($product_options as $option) {
|
| 2746 |
foreach ($product['option_ids'] as $option_id => $option_value) {
|
| 2747 |
+
if ($option->getOptionId() == $option_id) {
|
| 2748 |
$product['prod_options'][$option->getTitle()] = '';
|
| 2749 |
$option_values = $option->getValues();
|
| 2750 |
foreach ($option_values as $value) {
|
| 2751 |
+
if ($value->getOptionTypeId() == $option_value) {
|
| 2752 |
$product['prod_options'][$option->getTitle()] = $value->getTitle();
|
| 2753 |
// $product['prod_options'][$option->getTitle()]['price'] = $value->getPrice();
|
| 2754 |
}
|
| 2771 |
);
|
| 2772 |
}
|
| 2773 |
|
| 2774 |
+
protected function _price_format($iso_code, $curr_format, $price, $convert_to, $force = false, $format = true)
|
| 2775 |
+
{
|
| 2776 |
$currency_symbol = '';
|
| 2777 |
$price = str_replace(' ', '', $price);
|
| 2778 |
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
|
| 2779 |
|
| 2780 |
+
if (!in_array(ucwords($convert_to), Mage::getModel('directory/currency')->getConfigAllowCurrencies())) {
|
| 2781 |
$convert_to = $baseCurrencyCode;
|
| 2782 |
}
|
| 2783 |
|
| 2784 |
+
if (strlen($convert_to) == 3) {
|
| 2785 |
try {
|
| 2786 |
$price = Mage::helper('directory')->currencyConvert($price, $baseCurrencyCode, $convert_to);
|
| 2787 |
$iso_code = $convert_to;
|
| 2788 |
+
} catch (Exception $e) {
|
| 2789 |
Mage::log(
|
| 2790 |
+
"Error while currency converting (" . var_export($e->getMessage(), true) . ")",
|
| 2791 |
null,
|
| 2792 |
'emagicone_mobassistantconnector.log'
|
| 2793 |
);
|
| 2795 |
|
| 2796 |
}
|
| 2797 |
|
| 2798 |
+
if ($format) {
|
| 2799 |
$price = number_format(floatval($price), 2, '.', ' ');
|
| 2800 |
}
|
| 2801 |
|
| 2802 |
preg_match('/^[a-zA-Z]+$/', $iso_code, $matches);
|
| 2803 |
|
| 2804 |
+
if (count($matches) > 0) {
|
| 2805 |
+
if (strlen($matches[0]) == 3) {
|
| 2806 |
$currency_symbol = Mage::app()->getLocale()->currency($iso_code)->getSymbol();
|
| 2807 |
}
|
| 2808 |
} else {
|
| 2809 |
$currency_symbol = $iso_code;
|
| 2810 |
}
|
| 2811 |
|
| 2812 |
+
if ($force) {
|
| 2813 |
return $currency_symbol;
|
| 2814 |
}
|
| 2815 |
$sign = '<span>' . $currency_symbol . '</span>';
|
| 2816 |
+
if ($curr_format == 1) {
|
| 2817 |
$price = $sign . $price;
|
| 2818 |
} elseif ($curr_format == 2) {
|
| 2819 |
$price = $price;
|
| 2827 |
}
|
| 2828 |
|
| 2829 |
|
| 2830 |
+
protected function _get_default_currency()
|
| 2831 |
+
{
|
| 2832 |
$symbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getBaseCurrencyCode())->getSymbol();
|
| 2833 |
$currency = Mage::app()->getStore()->getBaseCurrencyCode();
|
| 2834 |
return array('currency' => $currency, 'symbol' => $symbol);
|
| 2835 |
}
|
| 2836 |
|
| 2837 |
+
protected function _get_store_currencies($storeId)
|
| 2838 |
+
{
|
| 2839 |
$CurrencyCode = Mage::getModel('core/config_data')
|
| 2840 |
->getCollection()
|
| 2841 |
+
->addFieldToFilter('path', 'currency/options/allow')
|
| 2842 |
+
->addFieldToFilter('scope_id', $storeId)
|
| 2843 |
->getData();
|
| 2844 |
+
$currencies_array = explode(',', $CurrencyCode[0]['value']);
|
| 2845 |
+
if ($currencies_array[0] == '') {
|
| 2846 |
+
$currencies_array[] = Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
|
|
|
|
| 2847 |
}
|
| 2848 |
|
| 2849 |
foreach ($currencies_array as $curCode) {
|
| 2850 |
+
$currencySymbol = Mage::app()->getLocale()->currency($curCode)->getSymbol();
|
| 2851 |
+
$currencyName = Mage::app()->getLocale()->currency($curCode)->getName();
|
| 2852 |
$currencies[] = array('code' => $curCode, 'symbol' => (is_null($currencySymbol) ? $curCode : $currencySymbol), 'name' => $currencyName);
|
| 2853 |
}
|
| 2854 |
|
| 2855 |
return $currencies;
|
| 2856 |
}
|
| 2857 |
|
| 2858 |
+
protected function _get_timezone_offset()
|
| 2859 |
+
{
|
| 2860 |
$timezone = Mage::app()->getStore()->getConfig('general/locale/timezone');
|
| 2861 |
|
| 2862 |
|
| 2867 |
// $offset2 = (($hours >= 0) ? '+'.$hours : $hours) .':'. $mins;
|
| 2868 |
|
| 2869 |
|
|
|
|
| 2870 |
$origin_dtz = new DateTimeZone("UTC");
|
| 2871 |
$remote_dtz = new DateTimeZone($timezone);
|
| 2872 |
$origin_dt = new DateTime("now", $origin_dtz);
|
| 2875 |
|
| 2876 |
$hours = intval($offset / 60 / 60);
|
| 2877 |
$mins = $offset / 60 % 60;
|
| 2878 |
+
$offset = (($hours >= 0) ? '+' . $hours : $hours) . ':' . $mins;
|
| 2879 |
//
|
| 2880 |
// $offset = $offset / 60 / 60;
|
| 2881 |
|
| 2883 |
}
|
| 2884 |
|
| 2885 |
|
| 2886 |
+
protected function reset_null(&$item)
|
| 2887 |
+
{
|
| 2888 |
+
if (empty($item) && $item != 0) {
|
| 2889 |
$item = '';
|
| 2890 |
}
|
| 2891 |
$item = trim($item);
|
| 2892 |
}
|
| 2893 |
|
| 2894 |
|
| 2895 |
+
protected function validate_types(&$array, $names)
|
| 2896 |
+
{
|
| 2897 |
foreach ($names as $name => $type) {
|
| 2898 |
if (isset($array["$name"])) {
|
| 2899 |
switch ($type) {
|
| 2927 |
}
|
| 2928 |
|
| 2929 |
|
| 2930 |
+
protected function get_custom_period($period = 0)
|
| 2931 |
+
{
|
| 2932 |
$custom_period = array('start_date' => "", 'end_date' => "");
|
| 2933 |
$format = "m/d/Y";
|
| 2934 |
|
| 2935 |
+
switch ($period) {
|
| 2936 |
case 0: //3 days
|
| 2937 |
+
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date("m"), date("d") - 2, date("Y")));
|
| 2938 |
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date("m"), date("d"), date("Y")));
|
| 2939 |
break;
|
| 2940 |
|
| 2941 |
case 1: //7 days
|
| 2942 |
+
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date("m"), date("d") - 6, date("Y")));
|
| 2943 |
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date("m"), date("d"), date("Y")));
|
| 2944 |
break;
|
| 2945 |
|
| 2946 |
case 2: //Prev week
|
| 2947 |
+
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date("n"), date("j") - 6, date("Y")) - ((date("N")) * 3600 * 24));
|
| 2948 |
+
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date("n"), date("j"), date("Y")) - ((date("N")) * 3600 * 24));
|
| 2949 |
break;
|
| 2950 |
|
| 2951 |
case 3: //Prev month
|
| 2952 |
+
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date("m") - 1, 1, date("Y")));
|
| 2953 |
+
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date("m"), date("d") - date("j"), date("Y")));
|
| 2954 |
break;
|
| 2955 |
|
| 2956 |
case 4: //This quarter
|
| 2958 |
$start_m = 1;
|
| 2959 |
$end_m = 3;
|
| 2960 |
|
| 2961 |
+
if ($m <= 3) {
|
| 2962 |
$start_m = 1;
|
| 2963 |
$end_m = 3;
|
| 2964 |
+
} else if ($m >= 4 && $m <= 6) {
|
| 2965 |
$start_m = 4;
|
| 2966 |
$end_m = 6;
|
| 2967 |
+
} else if ($m >= 7 && $m <= 9) {
|
| 2968 |
$start_m = 7;
|
| 2969 |
$end_m = 9;
|
| 2970 |
+
} else if ($m >= 10) {
|
| 2971 |
$start_m = 10;
|
| 2972 |
$end_m = 12;
|
| 2973 |
}
|
| 2974 |
|
| 2975 |
+
$custom_period['start_date'] = date($format, mktime(0, 0, 0, $start_m, 1, date("Y")));
|
| 2976 |
+
$custom_period['end_date'] = date($format, mktime(23, 59, 59, $end_m + 1, date(1) - 1, date("Y")));
|
| 2977 |
break;
|
| 2978 |
|
| 2979 |
case 5: //This year
|
| 2980 |
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date(1), date(1), date("Y")));
|
| 2981 |
+
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date(1), date(1) - 1, date("Y") + 1));
|
| 2982 |
break;
|
| 2983 |
|
| 2984 |
case 7: //Last year
|
| 2985 |
+
$custom_period['start_date'] = date($format, mktime(0, 0, 0, date(1), date(1), date("Y") - 1));
|
| 2986 |
+
$custom_period['end_date'] = date($format, mktime(23, 59, 59, date(1), date(1) - 1, date("Y")));
|
| 2987 |
+
break;
|
| 2988 |
+
case 8: //Previous quarter
|
| 2989 |
+
$m = date('n');
|
| 2990 |
+
$start_m = 1;
|
| 2991 |
+
$end_m = 3;
|
| 2992 |
+
|
| 2993 |
+
if ($m <= 3)
|
| 2994 |
+
{
|
| 2995 |
+
$start_m = 10;
|
| 2996 |
+
$end_m = 12;
|
| 2997 |
+
}
|
| 2998 |
+
else if ($m >= 4 && $m <= 6)
|
| 2999 |
+
{
|
| 3000 |
+
$start_m = 1;
|
| 3001 |
+
$end_m = 3;
|
| 3002 |
+
}
|
| 3003 |
+
else if ($m >= 7 && $m <= 9)
|
| 3004 |
+
{
|
| 3005 |
+
$start_m = 4;
|
| 3006 |
+
$end_m = 6;
|
| 3007 |
+
}
|
| 3008 |
+
else if ($m >= 10)
|
| 3009 |
+
{
|
| 3010 |
+
$start_m = 7;
|
| 3011 |
+
$end_m = 9;
|
| 3012 |
+
}
|
| 3013 |
+
|
| 3014 |
+
$custom_period['start_date'] = date($format, mktime(0, 0, 0, $start_m, 1, date('Y')));
|
| 3015 |
+
$custom_period['end_date'] = date($format, mktime(23, 59, 59, $end_m + 1, date(1) - 1, date('Y')));
|
| 3016 |
break;
|
| 3017 |
}
|
| 3018 |
|
| 3020 |
}
|
| 3021 |
|
| 3022 |
|
| 3023 |
+
protected function bd_nice_number($n, $is_count = false)
|
| 3024 |
+
{
|
| 3025 |
$n = floatval($n);
|
| 3026 |
|
| 3027 |
+
if (!is_numeric($n)) return $n;
|
| 3028 |
|
| 3029 |
$final_number = $n;
|
| 3030 |
$number_suf = "";
|
| 3031 |
// now filter it;
|
| 3032 |
+
if ($n > 1000000000000000) {
|
| 3033 |
//return number_format(round(($n / 1000000000000000), 1), 1, '.', ' ') . 'P';
|
| 3034 |
$final_number = round(($n / 1000000000000000), 2);
|
| 3035 |
$number_suf = "P";
|
| 3036 |
|
| 3037 |
+
} else if ($n > 1000000000000) {
|
| 3038 |
//return number_format(round(($n / 1000000000000),1), 1, '.', ' ') . 'T';
|
| 3039 |
$final_number = round(($n / 1000000000000), 2);
|
| 3040 |
$number_suf = "T";
|
| 3041 |
|
| 3042 |
+
} else if ($n > 1000000000) {
|
| 3043 |
//return number_format(round(($n / 1000000000),1), 1, '.', ' ') . 'G';
|
| 3044 |
$final_number = round(($n / 1000000000), 2);
|
| 3045 |
$number_suf = "G";
|
| 3046 |
|
| 3047 |
+
} else if ($n > 1000000) {
|
| 3048 |
//return number_format(round(($n / 1000000),1), 1, '.', ' ') . 'M';
|
| 3049 |
$final_number = round(($n / 1000000), 2);
|
| 3050 |
$number_suf = "M";
|
| 3051 |
|
| 3052 |
+
} else if ($n > 10000) {
|
| 3053 |
return number_format($n, 0, '', ' ');
|
| 3054 |
}
|
| 3055 |
|
| 3056 |
+
if ($is_count) {
|
| 3057 |
$final_number = intval($final_number);
|
| 3058 |
} else {
|
| 3059 |
$final_number = number_format($final_number, 2, '.', ' ') . $number_suf;
|
| 3062 |
return $final_number;
|
| 3063 |
}
|
| 3064 |
|
| 3065 |
+
protected function split_values($arr, $keys, $sign = ', ')
|
| 3066 |
+
{
|
| 3067 |
$new_arr = array();
|
| 3068 |
+
foreach ($keys as $key) {
|
| 3069 |
+
if (isset($arr[$key])) {
|
| 3070 |
+
if (!is_null($arr[$key]) && $arr[$key] != '') {
|
| 3071 |
$new_arr[] = $arr[$key];
|
| 3072 |
}
|
| 3073 |
}
|
app/code/community/Emagicone/Mobassistantconnector/etc/adminhtml.xml
CHANGED
|
@@ -1,26 +1,26 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
-
<config>
|
| 3 |
-
<acl>
|
| 4 |
-
<resources>
|
| 5 |
-
<all>
|
| 6 |
-
<title>Allow Everything</title>
|
| 7 |
-
</all>
|
| 8 |
-
<admin>
|
| 9 |
-
<children>
|
| 10 |
-
<system>
|
| 11 |
-
<children>
|
| 12 |
-
<config>
|
| 13 |
-
<children>
|
| 14 |
-
<mobassistantconnectorinfosec translate="title">
|
| 15 |
-
<title>An Example Section</title>
|
| 16 |
-
<sort_order>100</sort_order>
|
| 17 |
-
</mobassistantconnectorinfosec>
|
| 18 |
-
</children>
|
| 19 |
-
</config>
|
| 20 |
-
</children>
|
| 21 |
-
</system>
|
| 22 |
-
</children>
|
| 23 |
-
</admin>
|
| 24 |
-
</resources>
|
| 25 |
-
</acl>
|
| 26 |
</config>
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<acl>
|
| 4 |
+
<resources>
|
| 5 |
+
<all>
|
| 6 |
+
<title>Allow Everything</title>
|
| 7 |
+
</all>
|
| 8 |
+
<admin>
|
| 9 |
+
<children>
|
| 10 |
+
<system>
|
| 11 |
+
<children>
|
| 12 |
+
<config>
|
| 13 |
+
<children>
|
| 14 |
+
<mobassistantconnectorinfosec translate="title">
|
| 15 |
+
<title>An Example Section</title>
|
| 16 |
+
<sort_order>100</sort_order>
|
| 17 |
+
</mobassistantconnectorinfosec>
|
| 18 |
+
</children>
|
| 19 |
+
</config>
|
| 20 |
+
</children>
|
| 21 |
+
</system>
|
| 22 |
+
</children>
|
| 23 |
+
</admin>
|
| 24 |
+
</resources>
|
| 25 |
+
</acl>
|
| 26 |
</config>
|
app/code/community/Emagicone/Mobassistantconnector/etc/config.xml
CHANGED
|
@@ -1,120 +1,144 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
-
<config>
|
| 3 |
-
|
| 4 |
-
<default>
|
| 5 |
-
<mobassistantconnectorinfosec>
|
| 6 |
-
<emogeneral>
|
| 7 |
-
<status>0</status>
|
| 8 |
-
</emogeneral>
|
| 9 |
-
<emoaccess>
|
| 10 |
-
<login>1</login>
|
| 11 |
-
<password>c4ca4238a0b923820dcc509a6f75849b</password>
|
| 12 |
-
</emoaccess>
|
| 13 |
-
</mobassistantconnectorinfosec>
|
| 14 |
-
</default>
|
| 15 |
-
|
| 16 |
-
<modules>
|
| 17 |
-
<Emagicone_Mobassistantconnector>
|
| 18 |
-
<version>1.0.
|
| 19 |
-
</Emagicone_Mobassistantconnector>
|
| 20 |
-
</modules>
|
| 21 |
-
<frontend>
|
| 22 |
-
<routers>
|
| 23 |
-
<mobassistantconnector>
|
| 24 |
-
<use>standard</use>
|
| 25 |
-
<args>
|
| 26 |
-
<module>Emagicone_Mobassistantconnector</module>
|
| 27 |
-
<frontName>mobassistantconnector</frontName>
|
| 28 |
-
</args>
|
| 29 |
-
</mobassistantconnector>
|
| 30 |
-
</routers>
|
| 31 |
-
<translate>
|
| 32 |
-
<modules>
|
| 33 |
-
<translations>
|
| 34 |
-
<files>
|
| 35 |
-
<default>Emagicone_Mobassistantconnector.csv</default>
|
| 36 |
-
</files>
|
| 37 |
-
</translations>
|
| 38 |
-
</modules>
|
| 39 |
-
</translate>
|
| 40 |
-
</frontend>
|
| 41 |
-
|
| 42 |
-
<admin>
|
| 43 |
-
<routers>
|
| 44 |
-
<mobassistantconnectoradmin>
|
| 45 |
-
<use>admin</use>
|
| 46 |
-
<args>
|
| 47 |
-
<module>Emagicone_Mobassistantconnector</module>
|
| 48 |
-
<frontName>mobassistantconnector</frontName>
|
| 49 |
-
</args>
|
| 50 |
-
</mobassistantconnectoradmin>
|
| 51 |
-
</routers>
|
| 52 |
-
</admin>
|
| 53 |
-
|
| 54 |
-
<global>
|
| 55 |
-
<helpers>
|
| 56 |
-
<mobassistantconnector>
|
| 57 |
-
<class>Emagicone_Mobassistantconnector_Helper</class>
|
| 58 |
-
</mobassistantconnector>
|
| 59 |
-
</helpers>
|
| 60 |
-
|
| 61 |
-
<models>
|
| 62 |
-
<sales>
|
| 63 |
-
<rewrite>
|
| 64 |
-
<order>Emagicone_Mobassistantconnector_Model_Order</order>
|
| 65 |
-
</rewrite>
|
| 66 |
-
</sales>
|
| 67 |
-
|
| 68 |
-
<class>Emagicone_Mobassistantconnector_Model</class>
|
| 69 |
-
</emagiconemobassistantconnector>
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
<
|
| 79 |
-
</
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
</config>
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
|
| 4 |
+
<default>
|
| 5 |
+
<mobassistantconnectorinfosec>
|
| 6 |
+
<emogeneral>
|
| 7 |
+
<status>0</status>
|
| 8 |
+
</emogeneral>
|
| 9 |
+
<emoaccess>
|
| 10 |
+
<login>1</login>
|
| 11 |
+
<password>c4ca4238a0b923820dcc509a6f75849b</password>
|
| 12 |
+
</emoaccess>
|
| 13 |
+
</mobassistantconnectorinfosec>
|
| 14 |
+
</default>
|
| 15 |
+
|
| 16 |
+
<modules>
|
| 17 |
+
<Emagicone_Mobassistantconnector>
|
| 18 |
+
<version>1.2.0.1</version>
|
| 19 |
+
</Emagicone_Mobassistantconnector>
|
| 20 |
+
</modules>
|
| 21 |
+
<frontend>
|
| 22 |
+
<routers>
|
| 23 |
+
<mobassistantconnector>
|
| 24 |
+
<use>standard</use>
|
| 25 |
+
<args>
|
| 26 |
+
<module>Emagicone_Mobassistantconnector</module>
|
| 27 |
+
<frontName>mobassistantconnector</frontName>
|
| 28 |
+
</args>
|
| 29 |
+
</mobassistantconnector>
|
| 30 |
+
</routers>
|
| 31 |
+
<translate>
|
| 32 |
+
<modules>
|
| 33 |
+
<translations>
|
| 34 |
+
<files>
|
| 35 |
+
<default>Emagicone_Mobassistantconnector.csv</default>
|
| 36 |
+
</files>
|
| 37 |
+
</translations>
|
| 38 |
+
</modules>
|
| 39 |
+
</translate>
|
| 40 |
+
</frontend>
|
| 41 |
+
|
| 42 |
+
<admin>
|
| 43 |
+
<routers>
|
| 44 |
+
<mobassistantconnectoradmin>
|
| 45 |
+
<use>admin</use>
|
| 46 |
+
<args>
|
| 47 |
+
<module>Emagicone_Mobassistantconnector</module>
|
| 48 |
+
<frontName>mobassistantconnector</frontName>
|
| 49 |
+
</args>
|
| 50 |
+
</mobassistantconnectoradmin>
|
| 51 |
+
</routers>
|
| 52 |
+
</admin>
|
| 53 |
+
|
| 54 |
+
<global>
|
| 55 |
+
<helpers>
|
| 56 |
+
<mobassistantconnector>
|
| 57 |
+
<class>Emagicone_Mobassistantconnector_Helper</class>
|
| 58 |
+
</mobassistantconnector>
|
| 59 |
+
</helpers>
|
| 60 |
+
|
| 61 |
+
<models>
|
| 62 |
+
<sales>
|
| 63 |
+
<rewrite>
|
| 64 |
+
<order>Emagicone_Mobassistantconnector_Model_Order</order>
|
| 65 |
+
</rewrite>
|
| 66 |
+
</sales>
|
| 67 |
+
<emagiconemobassistantconnector>
|
| 68 |
+
<class>Emagicone_Mobassistantconnector_Model</class>
|
| 69 |
+
</emagiconemobassistantconnector>
|
| 70 |
+
<emagicone_mobassistantconnector>
|
| 71 |
+
<class>Emagicone_Mobassistantconnector_Model</class>
|
| 72 |
+
<resourceModel>emagicone_mobassistantconnector_resource</resourceModel>
|
| 73 |
+
</emagicone_mobassistantconnector>
|
| 74 |
+
<emagicone_mobassistantconnector_resource>
|
| 75 |
+
<class>Emagicone_Mobassistantconnector_Model_Resource</class>
|
| 76 |
+
<entities>
|
| 77 |
+
<sessions>
|
| 78 |
+
<table>emagicone_mobassistantconnector_sessions</table>
|
| 79 |
+
</sessions>
|
| 80 |
+
<failed>
|
| 81 |
+
<table>emagicone_mobassistantconnector_failed_login</table>
|
| 82 |
+
</failed>
|
| 83 |
+
</entities>
|
| 84 |
+
</emagicone_mobassistantconnector_resource>
|
| 85 |
+
|
| 86 |
+
</models>
|
| 87 |
+
|
| 88 |
+
<resources>
|
| 89 |
+
<emagicone_mobassistantconnector_setup>
|
| 90 |
+
<setup>
|
| 91 |
+
<module>Emagicone_Mobassistantconnector</module>
|
| 92 |
+
</setup>
|
| 93 |
+
</emagicone_mobassistantconnector_setup>
|
| 94 |
+
</resources>
|
| 95 |
+
|
| 96 |
+
<events>
|
| 97 |
+
<sales_order_save_after>
|
| 98 |
+
<observers>
|
| 99 |
+
<emagicone_mobassistantconnector_order_change>
|
| 100 |
+
<type>singleton</type>
|
| 101 |
+
<class>Emagicone_Mobassistantconnector_Model_Observer</class>
|
| 102 |
+
<method>checkOrder</method>
|
| 103 |
+
</emagicone_mobassistantconnector_order_change>
|
| 104 |
+
</observers>
|
| 105 |
+
</sales_order_save_after>
|
| 106 |
+
<customer_register_success>
|
| 107 |
+
<observers>
|
| 108 |
+
<emagicone_mobassistantconnector_customer_register_success>
|
| 109 |
+
<type>model</type>
|
| 110 |
+
<class>Emagicone_Mobassistantconnector_Model_Observer</class>
|
| 111 |
+
<method>customerRegisterSuccess</method>
|
| 112 |
+
</emagicone_mobassistantconnector_customer_register_success>
|
| 113 |
+
</observers>
|
| 114 |
+
</customer_register_success>
|
| 115 |
+
</events>
|
| 116 |
+
<layout>
|
| 117 |
+
<updates>
|
| 118 |
+
<emagicone_mobassistantconnector>
|
| 119 |
+
<file>emagicone_mobassistantconnector.xml</file>
|
| 120 |
+
</emagicone_mobassistantconnector>
|
| 121 |
+
</updates>
|
| 122 |
+
</layout>
|
| 123 |
+
</global>
|
| 124 |
+
|
| 125 |
+
<adminhtml>
|
| 126 |
+
<translate>
|
| 127 |
+
<modules>
|
| 128 |
+
<translations>
|
| 129 |
+
<files>
|
| 130 |
+
<default>Emagicone_mobassistantconnector.csv</default>
|
| 131 |
+
</files>
|
| 132 |
+
</translations>
|
| 133 |
+
</modules>
|
| 134 |
+
</translate>
|
| 135 |
+
<layout>
|
| 136 |
+
<updates>
|
| 137 |
+
<mobassistantconnector>
|
| 138 |
+
<file>mobassistantconnector.xml</file>
|
| 139 |
+
</mobassistantconnector>
|
| 140 |
+
</updates>
|
| 141 |
+
</layout>
|
| 142 |
+
</adminhtml>
|
| 143 |
+
|
| 144 |
</config>
|
app/code/community/Emagicone/Mobassistantconnector/sql/emagicone_mobassistantconnector_setup/install-1.0.0.php
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Created by PhpStorm.
|
| 4 |
+
* User: jarchik
|
| 5 |
+
* Date: 5/13/15
|
| 6 |
+
* Time: 11:41 AM
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
$installer = $this;
|
| 10 |
+
|
| 11 |
+
$installer->startSetup();
|
| 12 |
+
|
| 13 |
+
/*$table = $installer->getConnection()
|
| 14 |
+
->newTable($installer->getTable('emo_assistantconnector/sessions'))
|
| 15 |
+
->addColumn('key', Varien_Db_Ddl_Table::TYPE_VARCHAR, 100, array(
|
| 16 |
+
'identity' => false,
|
| 17 |
+
'primary' => true,
|
| 18 |
+
), 'Key')
|
| 19 |
+
->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(
|
| 20 |
+
'nullable' => false,
|
| 21 |
+
'unsigned' => false,
|
| 22 |
+
), 'Date added');
|
| 23 |
+
$installer->getConnection()->createTable($table);*/
|
| 24 |
+
|
| 25 |
+
$installer->run("
|
| 26 |
+
-- DROP TABLE IF EXISTS {$this->getTable('emagicone_mobassistantconnector_sessions')};
|
| 27 |
+
CREATE TABLE {$this->getTable('emagicone_mobassistantconnector_sessions')} (
|
| 28 |
+
`session_id` int(11) NOT NULL auto_increment,
|
| 29 |
+
`session_key` varchar(100) NOT NULL default '',
|
| 30 |
+
`date_added` int(11) NOT NULL,
|
| 31 |
+
PRIMARY KEY (`session_id`)
|
| 32 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
| 33 |
+
");
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
/*$table = $installer->getConnection()
|
| 38 |
+
->newTable($installer->getTable('emagicone_mobassistantconnector/failed'))
|
| 39 |
+
->addColumn('ip', Varien_Db_Ddl_Table::TYPE_VARCHAR, 100, array(
|
| 40 |
+
'identity' => false,
|
| 41 |
+
'primary' => true,
|
| 42 |
+
), 'Id')
|
| 43 |
+
->addColumn('date_added', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array(
|
| 44 |
+
'nullable' => false,
|
| 45 |
+
'unsigned' => false,
|
| 46 |
+
), 'Date added');
|
| 47 |
+
$installer->getConnection()->createTable($table);*/
|
| 48 |
+
|
| 49 |
+
$installer->run("
|
| 50 |
+
-- DROP TABLE IF EXISTS {$this->getTable('emagicone_mobassistantconnector_failed_login')};
|
| 51 |
+
CREATE TABLE {$this->getTable('emagicone_mobassistantconnector_failed_login')} (
|
| 52 |
+
`attempt_id` int(11) NOT NULL auto_increment,
|
| 53 |
+
`ip` varchar(20) NOT NULL default '',
|
| 54 |
+
`date_added` int(11) NOT NULL,
|
| 55 |
+
PRIMARY KEY (`attempt_id`)
|
| 56 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
| 57 |
+
");
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
$installer->endSetup();
|
package.xml
CHANGED
|
@@ -1,18 +1,23 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>mobile_assistant_connector</name>
|
| 4 |
-
<version>1.1
|
| 5 |
-
<stability>
|
| 6 |
<license uri="http://www.gnu.org/licenses/gpl.html">GNU</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Mobile Assistant Connector</summary>
|
| 10 |
<description>Mobile Assistant Connector</description>
|
| 11 |
-
<notes>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
<authors><author><name>eMagicOne</name><user>mobile</user><email>mobile@emagicone.com</email></author></authors>
|
| 13 |
-
<date>2015-
|
| 14 |
-
<time>
|
| 15 |
-
<contents><target name="magecommunity"><dir name="Emagicone"><dir name="Mobassistantconnector"><dir name="Helper"><file name="Data.php" hash="
|
| 16 |
<compatible/>
|
| 17 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><extension><name>curl</name><min>1.0</min><max>3.0</max></extension><extension><name>json</name><min>1.0</min><max>3.0</max></extension><extension><name>date</name><min>1.0</min><max>3.0</max></extension></required></dependencies>
|
| 18 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>mobile_assistant_connector</name>
|
| 4 |
+
<version>1.2.0.1</version>
|
| 5 |
+
<stability>beta</stability>
|
| 6 |
<license uri="http://www.gnu.org/licenses/gpl.html">GNU</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Mobile Assistant Connector</summary>
|
| 10 |
<description>Mobile Assistant Connector</description>
|
| 11 |
+
<notes>Added:
|
| 12 |
+
- previous quarter stats on dashboard
|
| 13 |
+
- changed security level
|
| 14 |
+
- downloading and printing PDF invoice
|
| 15 |
+

|
| 16 |
+
Works only with beta release of app (2.6.0.1)</notes>
|
| 17 |
<authors><author><name>eMagicOne</name><user>mobile</user><email>mobile@emagicone.com</email></author></authors>
|
| 18 |
+
<date>2015-05-26</date>
|
| 19 |
+
<time>15:26:16</time>
|
| 20 |
+
<contents><target name="magecommunity"><dir name="Emagicone"><dir name="Mobassistantconnector"><dir name="Helper"><file name="Access.php" hash="19c6ccbaa8e82e770cc544f789cffddc"/><file name="Data.php" hash="2209bd29f7745d48d515ac68fd451e2d"/></dir><dir name="Model"><file name="Defpassword.php" hash="ab8f696fce0029f113986b83ddeb8232"/><file name="Failed.php" hash="7da654c3cf1e9a3f5a55da7f36192117"/><file name="Login.php" hash="bedbce507924854910524fbabe1c4948"/><file name="Observer.php" hash="bb18972490df3223aeb473d917a2acf4"/><file name="Order.php" hash="f3d5529e0504ea0265cb661e03f41109"/><file name="Password.php" hash="66e2050ecc7b56deb654b5476ac1746c"/><dir name="Resource"><dir name="Failed"><file name="Collection.php" hash="18980688d80660f6a663a2c4dce20f54"/></dir><file name="Failed.php" hash="a69ca1239d3400097fabc415ee02751b"/><dir name="Sessions"><file name="Collection.php" hash="397e9a6f637472b59abe42bca09ea616"/></dir><file name="Sessions.php" hash="4d9f6cdd340fd95549d287c6107285ac"/></dir><file name="Sessions.php" hash="e3a32e26446e4cd27032c99dde8d4cfa"/></dir><dir name="controllers"><file name="IndexController.php" hash="c5391d9bd16865db30039203a26a8d0d"/><dir name="adminhtml"><file name="IndexController.php" hash="ef5ca028e534cbf81b39a643885c9511"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="333ed888c7f8a1e067821b6547e34340"/><file name="config.xml" hash="5a97e58205c483005b7cd6a98c91756b"/><file name="system.xml" hash="916fe7ee643e4dcb15a5498219605896"/></dir><dir name="sql"><dir name="emagicone_mobassistantconnector_setup"><file name="install-1.0.0.php" hash="93cc0471b2386cc278cdf7ec8f1a2ae5"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Emagicone_Mobassistantconnector.xml" hash="7bb654478173d96ad294000fc9625820"/></dir></target><target name="magelocale"><dir><dir name="en_GB"><file name="Emagicone_Mobassistantconnector.csv" hash="eaf733f81ff47627c4389d487c93709f"/><file name="__Emagicone_Mobassistantconnector.csv" hash="eaf733f81ff47627c4389d487c93709f"/></dir><dir name="en_US"><file name="Emagicone_Mobassistantconnector.csv" hash="510d79a25c0bfb7a096aab57d8c5b458"/><file name="__Emagicone_Mobassistantconnector.csv" hash="510d79a25c0bfb7a096aab57d8c5b458"/></dir><dir name="es_ES"><file name="Emagicone_Mobassistantconnector.csv" hash="acc37c432dd8b4134844291931b70fbf"/><file name="__Emagicone_Mobassistantconnector.csv" hash="acc37c432dd8b4134844291931b70fbf"/></dir><dir name="fr_FR"><file name="Emagicone_Mobassistantconnector.csv" hash="76c48723a6bbd59534781fd3c7f6d86e"/><file name="__Emagicone_Mobassistantconnector.csv" hash="76c48723a6bbd59534781fd3c7f6d86e"/></dir><dir name="ru_RU"><file name="Emagicone_Mobassistantconnector.csv" hash="2346397cbe029dcc724717b953a3f38c"/><file name="__Emagicone_Mobassistantconnector.csv" hash="2346397cbe029dcc724717b953a3f38c"/></dir><dir name="uk_UA"><file name="Emagicone_Mobassistantconnector.csv" hash="cad0e0c3ec7603e6b886d815357d1766"/><file name="__Emagicone_Mobassistantconnector.csv" hash="cad0e0c3ec7603e6b886d815357d1766"/></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="mobassistantconnector.xml" hash="b5c4d423be8de0c5d73d64783dcb9a3c"/></dir><dir name="template"><dir name="mobassistantconnector"><file name="jsinit.phtml" hash="785c82b5cf6b2a7dc94a1436d1c9115f"/></dir></dir></dir></dir></dir></target></contents>
|
| 21 |
<compatible/>
|
| 22 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><extension><name>curl</name><min>1.0</min><max>3.0</max></extension><extension><name>json</name><min>1.0</min><max>3.0</max></extension><extension><name>date</name><min>1.0</min><max>3.0</max></extension></required></dependencies>
|
| 23 |
</package>
|
