Ltc_Komfortkasse - Version 1.7.2

Version Notes

performance improvements

Download this release

Release Info

Developer Komfortkasse
Extension Ltc_Komfortkasse
Version 1.7.2
Comparing to
See all releases


Code changes from version 1.6.3 to 1.7.2

app/code/community/Ltc/Komfortkasse/Helper/788426360839 DELETED
@@ -1,18 +0,0 @@
1
- a:5:{i:0;s:487:"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1, query was: SELECT o.increment_id FROM sales_flat_order o join sales_flat_order_payment p on p.parent_id = o.entity_id left join m2epro_order m on m.magento_order_id=o.entity_id left join m2epro_ebay_order e on e.order_id=m.id where o.store_id=3 and created_at > 2015-10-15 and ()";i:1;s:1889:"#0 /srv/http/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
2
- #1 /srv/http/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
3
- #2 /srv/http/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
4
- #3 /srv/http/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT o.increm...', Array)
5
- #4 /srv/http/lib/Varien/Db/Adapter/Pdo/Mysql.php(504): Zend_Db_Adapter_Pdo_Abstract->query('SELECT o.increm...', Array)
6
- #5 /srv/http/lib/Zend/Db/Adapter/Abstract.php(737): Varien_Db_Adapter_Pdo_Mysql->query('SELECT o.increm...', Array)
7
- #6 /srv/http/app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse_Order.php(137): Zend_Db_Adapter_Abstract->fetchAll('SELECT o.increm...')
8
- #7 /srv/http/app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse.php(71): Komfortkasse_Order::getOpenIDs()
9
- #8 /srv/http/app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse.php(23): Komfortkasse::read(false)
10
- #9 /srv/http/app/code/community/Ltc/Komfortkasse/Helper/Data.php(44): Komfortkasse::readorders()
11
- #10 /srv/http/app/code/community/Ltc/Komfortkasse/controllers/MainController.php(46): Ltc_Komfortkasse_Helper_Data->readorders()
12
- #11 /srv/http/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Ltc_Komfortkasse_MainController->readordersAction()
13
- #12 /srv/http/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('readorders')
14
- #13 /srv/http/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
15
- #14 /srv/http/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
16
- #15 /srv/http/app/Mage.php(684): Mage_Core_Model_App->run(Array)
17
- #16 /srv/http/index.php(86): Mage::run('base', 'website')
18
- #17 {main}";s:3:"url";s:29:"/komfortkasse/main/readorders";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:12:"german_esouq";}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse.php CHANGED
@@ -8,7 +8,7 @@ require_once 'Komfortkasse_Order.php';
8
  */
9
  class Komfortkasse
10
  {
11
- const PLUGIN_VER = '1.6.3';
12
  const MAXLEN_SSL = 117;
13
  const LEN_MCRYPT = 16;
14
 
@@ -20,7 +20,7 @@ class Komfortkasse
20
  */
21
  public static function readorders()
22
  {
23
- Komfortkasse::read(false);
24
 
25
  }
26
 
@@ -34,7 +34,7 @@ class Komfortkasse
34
  */
35
  public static function readrefunds()
36
  {
37
- Komfortkasse::read(true);
38
 
39
  }
40
 
@@ -75,7 +75,7 @@ class Komfortkasse
75
  $o = $o . Komfortkasse::kk_csv($id);
76
  }
77
 
78
- Komfortkasse::output(Komfortkasse::kkencrypt($o));
79
  } else {
80
  $o = '';
81
  $ex = explode(';', $param);
@@ -100,9 +100,9 @@ class Komfortkasse
100
 
101
  $cry = Komfortkasse::kkencrypt($o);
102
  if ($cry === false) {
103
- Komfortkasse::output(Komfortkasse::kkcrypterror());
104
  } else {
105
- Komfortkasse::output($cry);
106
  }
107
  }
108
  // end if
@@ -122,7 +122,7 @@ class Komfortkasse
122
 
123
  $enc = Komfortkasse::kkencrypt($dec);
124
 
125
- Komfortkasse::output($enc);
126
 
127
  }
128
 
@@ -136,37 +136,39 @@ class Komfortkasse
136
  */
137
  public static function init()
138
  {
139
- Komfortkasse::output('connection:connectionsuccess|');
 
 
140
 
141
- Komfortkasse::output('accesskey:');
142
  // Set access code.
143
  $hashed = md5(Komfortkasse_Config::getRequestParameter('accesscode'));
144
  $current = Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode);
145
  if ($current != '' && $current !== 'undefined' && $current != $hashed) {
146
- Komfortkasse::output('Access Code already set! Shop ' . $current . ', given (hash) ' . $hashed);
147
- return;
148
  }
149
 
150
  if ($hashed != Komfortkasse_Config::getRequestParameter('accesscode_hash')) {
151
- Komfortkasse::output('MD5 Hashes do not match! Shop ' . $hashed . ' given ' . Komfortkasse_Config::getRequestParameter('accesscode_hash'));
152
- return;
153
  }
154
 
155
  Komfortkasse_Config::setConfig(Komfortkasse_Config::accesscode, $hashed);
156
- Komfortkasse::output('accesskeysuccess|');
157
 
158
- Komfortkasse::output('apikey:');
159
  // Set API key.
160
  $apikey = Komfortkasse_Config::getRequestParameter('apikey');
161
  if (Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) != '' && Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) !== 'undefined' && Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) !== $apikey) {
162
- Komfortkasse::output('API Key already set! Shop ' . Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) . ', given ' . $apikey);
163
- return;
164
  }
165
 
166
  Komfortkasse_Config::setConfig(Komfortkasse_Config::apikey, $apikey);
167
- Komfortkasse::output('apikeysuccess|');
168
 
169
- Komfortkasse::output('encryption:');
170
  $encryptionstring = null;
171
  // Look for openssl encryption.
172
 
@@ -218,24 +220,25 @@ class Komfortkasse
218
  $encryptionstring = 'ERROR:no encryption possible|';
219
  }
220
 
221
- Komfortkasse::output($encryptionstring);
222
 
223
- Komfortkasse::output('decryptiontest:');
224
  $decrypt = Komfortkasse::kkdecrypt($crypttest, Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
225
  if ($decrypt === 'Can you hear me?') {
226
- Komfortkasse::output('ok');
227
  } else {
228
- Komfortkasse::output(Komfortkasse::kkcrypterror());
229
  }
230
 
231
- Komfortkasse::output('|encryptiontest:');
232
  $encrypt = Komfortkasse::kkencrypt('Yes, I see you!', Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
233
  if ($encrypt !== false) {
234
- Komfortkasse::output($encrypt);
235
  } else {
236
- Komfortkasse::output(Komfortkasse::kkcrypterror());
237
  }
238
 
 
239
  }
240
 
241
  // end init()
@@ -248,7 +251,7 @@ class Komfortkasse
248
  */
249
  public static function updateorders()
250
  {
251
- Komfortkasse::update(false);
252
 
253
  }
254
 
@@ -262,7 +265,7 @@ class Komfortkasse
262
  */
263
  public static function updaterefunds()
264
  {
265
- Komfortkasse::update(true);
266
 
267
  }
268
 
@@ -350,9 +353,9 @@ class Komfortkasse
350
 
351
  $cry = Komfortkasse::kkencrypt($o);
352
  if ($cry === false) {
353
- Komfortkasse::output(Komfortkasse::kkcrypterror());
354
  } else {
355
- Komfortkasse::output($cry);
356
  }
357
 
358
  }
@@ -402,6 +405,9 @@ class Komfortkasse
402
  if (!self::isOpen($order)) {
403
  return;
404
  }
 
 
 
405
 
406
  $queryRaw = http_build_query($order);
407
 
@@ -443,9 +449,9 @@ class Komfortkasse
443
 
444
  $cry = Komfortkasse::kkencrypt($o);
445
  if ($cry === false) {
446
- Komfortkasse::output(Komfortkasse::kkcrypterror());
447
  } else {
448
- Komfortkasse::output($cry);
449
  }
450
 
451
  }
@@ -793,20 +799,6 @@ class Komfortkasse
793
  // end kk_csv()
794
 
795
 
796
- /**
797
- * Output
798
- *
799
- * @param mixed $s Data to output
800
- */
801
- protected static function output($s)
802
- {
803
- echo $s;
804
-
805
- }
806
-
807
- // end output()
808
-
809
-
810
  /**
811
  * Count
812
  *
8
  */
9
  class Komfortkasse
10
  {
11
+ const PLUGIN_VER = '1.7.2';
12
  const MAXLEN_SSL = 117;
13
  const LEN_MCRYPT = 16;
14
 
20
  */
21
  public static function readorders()
22
  {
23
+ return Komfortkasse::read(false);
24
 
25
  }
26
 
34
  */
35
  public static function readrefunds()
36
  {
37
+ return Komfortkasse::read(true);
38
 
39
  }
40
 
75
  $o = $o . Komfortkasse::kk_csv($id);
76
  }
77
 
78
+ return Komfortkasse_Config::output(Komfortkasse::kkencrypt($o));
79
  } else {
80
  $o = '';
81
  $ex = explode(';', $param);
100
 
101
  $cry = Komfortkasse::kkencrypt($o);
102
  if ($cry === false) {
103
+ return Komfortkasse_Config::output(Komfortkasse::kkcrypterror());
104
  } else {
105
+ return Komfortkasse_Config::output($cry);
106
  }
107
  }
108
  // end if
122
 
123
  $enc = Komfortkasse::kkencrypt($dec);
124
 
125
+ return Komfortkasse_Config::output($enc);
126
 
127
  }
128
 
136
  */
137
  public static function init()
138
  {
139
+ $ret = '';
140
+
141
+ $ret .= 'connection:connectionsuccess|';
142
 
143
+ $ret .= 'accesskey:';
144
  // Set access code.
145
  $hashed = md5(Komfortkasse_Config::getRequestParameter('accesscode'));
146
  $current = Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode);
147
  if ($current != '' && $current !== 'undefined' && $current != $hashed) {
148
+ $ret .= ('Access Code already set! Shop ' . $current . ', given (hash) ' . $hashed);
149
+ return Komfortkasse_Config::output($ret);
150
  }
151
 
152
  if ($hashed != Komfortkasse_Config::getRequestParameter('accesscode_hash')) {
153
+ $ret .= ('MD5 Hashes do not match! Shop ' . $hashed . ' given ' . Komfortkasse_Config::getRequestParameter('accesscode_hash'));
154
+ return Komfortkasse_Config::output($ret);
155
  }
156
 
157
  Komfortkasse_Config::setConfig(Komfortkasse_Config::accesscode, $hashed);
158
+ $ret .= ('accesskeysuccess|');
159
 
160
+ $ret .= ('apikey:');
161
  // Set API key.
162
  $apikey = Komfortkasse_Config::getRequestParameter('apikey');
163
  if (Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) != '' && Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) !== 'undefined' && Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) !== $apikey) {
164
+ $ret .= ('API Key already set! Shop ' . Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) . ', given ' . $apikey);
165
+ return Komfortkasse_Config::output($ret);
166
  }
167
 
168
  Komfortkasse_Config::setConfig(Komfortkasse_Config::apikey, $apikey);
169
+ $ret .= ('apikeysuccess|');
170
 
171
+ $ret .= ('encryption:');
172
  $encryptionstring = null;
173
  // Look for openssl encryption.
174
 
220
  $encryptionstring = 'ERROR:no encryption possible|';
221
  }
222
 
223
+ $ret .= ($encryptionstring);
224
 
225
+ $ret .= ('decryptiontest:');
226
  $decrypt = Komfortkasse::kkdecrypt($crypttest, Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
227
  if ($decrypt === 'Can you hear me?') {
228
+ $ret .= ('ok');
229
  } else {
230
+ $ret .= (Komfortkasse::kkcrypterror());
231
  }
232
 
233
+ $ret .= ('|encryptiontest:');
234
  $encrypt = Komfortkasse::kkencrypt('Yes, I see you!', Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
235
  if ($encrypt !== false) {
236
+ $ret .= ($encrypt);
237
  } else {
238
+ $ret .= (Komfortkasse::kkcrypterror());
239
  }
240
 
241
+ return Komfortkasse_Config::output($ret);
242
  }
243
 
244
  // end init()
251
  */
252
  public static function updateorders()
253
  {
254
+ return Komfortkasse::update(false);
255
 
256
  }
257
 
265
  */
266
  public static function updaterefunds()
267
  {
268
+ return Komfortkasse::update(true);
269
 
270
  }
271
 
353
 
354
  $cry = Komfortkasse::kkencrypt($o);
355
  if ($cry === false) {
356
+ return Komfortkasse_Config::output(Komfortkasse::kkcrypterror());
357
  } else {
358
+ return Komfortkasse_Config::output($cry);
359
  }
360
 
361
  }
405
  if (!self::isOpen($order)) {
406
  return;
407
  }
408
+ if (method_exists (Komfortkasse_Order, 'isOpen') && !Komfortkasse_Order::isOpen($order)) {
409
+ return;
410
+ }
411
 
412
  $queryRaw = http_build_query($order);
413
 
449
 
450
  $cry = Komfortkasse::kkencrypt($o);
451
  if ($cry === false) {
452
+ return Komfortkasse_Config::output(Komfortkasse::kkcrypterror());
453
  } else {
454
+ return Komfortkasse_Config::output($cry);
455
  }
456
 
457
  }
799
  // end kk_csv()
800
 
801
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
802
  /**
803
  * Count
804
  *
app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse.php.bak DELETED
@@ -1,864 +0,0 @@
1
- <?php
2
- require_once 'Komfortkasse_Config.php';
3
- require_once 'Komfortkasse_Order.php';
4
-
5
- /**
6
- * Komfortkasse
7
- * Main Class, multi-shop
8
- */
9
- class Komfortkasse
10
- {
11
- const PLUGIN_VER = '1.4.5';
12
- const MAXLEN_SSL = 117;
13
- const LEN_MCRYPT = 16;
14
-
15
-
16
- /**
17
- * Read orders.
18
- *
19
- * @return void
20
- */
21
- public static function readorders()
22
- {
23
- Komfortkasse::read(false);
24
-
25
- }
26
-
27
- // end readorders()
28
-
29
-
30
- /**
31
- * Read refunds.
32
- *
33
- * @return void
34
- */
35
- public static function readrefunds()
36
- {
37
- Komfortkasse::read(true);
38
-
39
- }
40
-
41
- // end readrefunds()
42
-
43
-
44
- /**
45
- * Read orders/refunds.
46
- *
47
- * @param bool $refunds if refunds should be read.
48
- *
49
- * @return void
50
- */
51
- public static function read($refunds)
52
- {
53
- if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
54
- return;
55
- }
56
-
57
- if (Komfortkasse::check() === false) {
58
- return;
59
- }
60
-
61
- // Schritt 1: alle IDs ausgeben.
62
- $param = Komfortkasse_Config::getRequestParameter('o');
63
- $param = Komfortkasse::kkdecrypt($param);
64
-
65
- if ($param === 'all') {
66
- $o = '';
67
- if ($refunds === true) {
68
- $ids = Komfortkasse_Order::getRefundIDs();
69
- } else {
70
- $ids = Komfortkasse_Order::getOpenIDs();
71
- }
72
-
73
- foreach ($ids as $id) {
74
- $o = $o . Komfortkasse::kk_csv($id);
75
- }
76
-
77
- Komfortkasse::output(Komfortkasse::kkencrypt($o));
78
- } else {
79
- $o = '';
80
- $ex = explode(';', $param);
81
- foreach ($ex as $id) {
82
- $id = trim($id);
83
- // Schritt 2: details pro auftrag ausgeben.
84
- if ($refunds === true) {
85
- $order = Komfortkasse_Order::getRefund($id);
86
- } else {
87
- $order = Komfortkasse_Order::getOrder($id);
88
- if ($order['payment_method'])
89
- $order['type'] = self::getOrderType($order);
90
- }
91
-
92
- if (!$order) {
93
- continue;
94
- }
95
-
96
- $o = $o . http_build_query($order);
97
- $o = $o . "\n";
98
- }
99
-
100
- $cry = Komfortkasse::kkencrypt($o);
101
- if ($cry === false) {
102
- Komfortkasse::output(Komfortkasse::kkcrypterror());
103
- } else {
104
- Komfortkasse::output($cry);
105
- }
106
- }
107
- // end if
108
- }
109
-
110
- // end read()
111
-
112
-
113
- /**
114
- * Test.
115
- *
116
- * @return void
117
- */
118
- public static function test()
119
- {
120
- $dec = Komfortkasse::kkdecrypt(Komfortkasse_Config::getRequestParameter('test'));
121
-
122
- $enc = Komfortkasse::kkencrypt($dec);
123
-
124
- Komfortkasse::output($enc);
125
-
126
- }
127
-
128
- // end test()
129
-
130
-
131
- /**
132
- * Init.
133
- *
134
- * @return void
135
- */
136
- public static function init()
137
- {
138
- Komfortkasse::output('connection:connectionsuccess|');
139
-
140
- Komfortkasse::output('accesskey:');
141
- // Set access code.
142
- $hashed = md5(Komfortkasse_Config::getRequestParameter('accesscode'));
143
- $current = Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode);
144
- if ($current != '' && $current !== 'undefined' && $current != $hashed) {
145
- Komfortkasse::output('Access Code already set! Shop ' . $current . ', given (hash) ' . $hashed);
146
- return;
147
- }
148
-
149
- if ($hashed != Komfortkasse_Config::getRequestParameter('accesscode_hash')) {
150
- Komfortkasse::output('MD5 Hashes do not match! Shop ' . $hashed . ' given ' . Komfortkasse_Config::getRequestParameter('accesscode_hash'));
151
- return;
152
- }
153
-
154
- Komfortkasse_Config::setConfig(Komfortkasse_Config::accesscode, $hashed);
155
- Komfortkasse::output('accesskeysuccess|');
156
-
157
- Komfortkasse::output('apikey:');
158
- // Set API key.
159
- $apikey = Komfortkasse_Config::getRequestParameter('apikey');
160
- if (Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) != '' && Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) !== 'undefined' && Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) !== $apikey) {
161
- Komfortkasse::output('API Key already set! Shop ' . Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey) . ', given ' . $apikey);
162
- return;
163
- }
164
-
165
- Komfortkasse_Config::setConfig(Komfortkasse_Config::apikey, $apikey);
166
- Komfortkasse::output('apikeysuccess|');
167
-
168
- Komfortkasse::output('encryption:');
169
- $encryptionstring = null;
170
- // Look for openssl encryption.
171
- if (extension_loaded('openssl') === true) {
172
-
173
- // Look for public&privatekey encryption.
174
- $kpriv = Komfortkasse_Config::getRequestParameter('privateKey');
175
- $kpub = Komfortkasse_Config::getRequestParameter('publicKey');
176
- Komfortkasse_Config::setConfig(Komfortkasse_Config::privatekey, $kpriv);
177
- Komfortkasse_Config::setConfig(Komfortkasse_Config::publickey, $kpub);
178
-
179
- // Try with rsa.
180
- $crypttest = Komfortkasse_Config::getRequestParameter('testSSLEnc');
181
- $decrypt = Komfortkasse::kkdecrypt($crypttest, 'openssl');
182
- if ($decrypt === 'Can you hear me?') {
183
- $encryptionstring = 'openssl#' . OPENSSL_VERSION_TEXT . '#' . OPENSSL_VERSION_NUMBER . '|';
184
- Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'openssl');
185
- }
186
- }
187
-
188
- if (!$encryptionstring && extension_loaded('mcrypt') === true) {
189
- // Look for mcrypt encryption.
190
- $sec = Komfortkasse_Config::getRequestParameter('mCryptSecretKey');
191
- $iv = Komfortkasse_Config::getRequestParameter('mCryptIV');
192
- Komfortkasse_Config::setConfig(Komfortkasse_Config::privatekey, $sec);
193
- Komfortkasse_Config::setConfig(Komfortkasse_Config::publickey, $iv);
194
-
195
- // Try with mcrypt.
196
- $crypttest = Komfortkasse_Config::getRequestParameter('testMCryptEnc');
197
- $decrypt = Komfortkasse::kkdecrypt($crypttest, 'mcrypt');
198
- if ($decrypt === 'Can you hear me?') {
199
- $encryptionstring = 'mcrypt|';
200
- Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'mcrypt');
201
- }
202
- }
203
-
204
- // Fallback: base64.
205
- if (!$encryptionstring) {
206
- // Try with base64 encoding.
207
- $crypttest = Komfortkasse_Config::getRequestParameter('testBase64Enc');
208
- $decrypt = Komfortkasse::kkdecrypt($crypttest, 'base64');
209
- if ($decrypt === 'Can you hear me?') {
210
- $encryptionstring = 'base64|';
211
- Komfortkasse_Config::setConfig(Komfortkasse_Config::encryption, 'base64');
212
- }
213
- }
214
-
215
- if (!$encryptionstring) {
216
- $encryptionstring = 'ERROR:no encryption possible|';
217
- }
218
-
219
- Komfortkasse::output($encryptionstring);
220
-
221
- Komfortkasse::output('decryptiontest:');
222
- $decrypt = Komfortkasse::kkdecrypt($crypttest, Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
223
- if ($decrypt === 'Can you hear me?') {
224
- Komfortkasse::output('ok');
225
- } else {
226
- Komfortkasse::output(Komfortkasse::kkcrypterror());
227
- }
228
-
229
- Komfortkasse::output('|encryptiontest:');
230
- $encrypt = Komfortkasse::kkencrypt('Yes, I see you!', Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption));
231
- if ($encrypt !== false) {
232
- Komfortkasse::output($encrypt);
233
- } else {
234
- Komfortkasse::output(Komfortkasse::kkcrypterror());
235
- }
236
-
237
- }
238
-
239
- // end init()
240
-
241
-
242
- /**
243
- * Update orders.
244
- *
245
- * @return void
246
- */
247
- public static function updateorders()
248
- {
249
- Komfortkasse::update(false);
250
-
251
- }
252
-
253
- // end updateorders()
254
-
255
-
256
- /**
257
- * Update refunds.
258
- *
259
- * @return void
260
- */
261
- public static function updaterefunds()
262
- {
263
- Komfortkasse::update(true);
264
-
265
- }
266
-
267
- // end updaterefunds()
268
-
269
-
270
- /**
271
- * Update refunds or order.
272
- *
273
- * @param bool $refunds if refunds should be updated.
274
- *
275
- * @return void
276
- */
277
- public static function update($refunds)
278
- {
279
- if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update)) {
280
- return;
281
- }
282
-
283
- if (Komfortkasse::check() === false) {
284
- return;
285
- }
286
-
287
- $param = Komfortkasse_Config::getRequestParameter('o');
288
- $param = Komfortkasse::kkdecrypt($param);
289
-
290
- if ($refunds === false) {
291
- $openids = Komfortkasse_Order::getOpenIDs();
292
- }
293
-
294
- $o = '';
295
- $lines = explode("\n", $param);
296
- foreach ($lines as $line) {
297
- $col = explode(';', $line);
298
- $count = Komfortkasse::mycount($col);
299
- $id = trim($col [0]);
300
- if ($count > 1) {
301
- $status = trim($col [1]);
302
- } else {
303
- $status = null;
304
- }
305
-
306
- if ($count > 2) {
307
- $callbackid = trim($col [2]);
308
- } else {
309
- $callbackid = null;
310
- }
311
-
312
- if (empty($id) === true || empty($status) === true) {
313
- continue;
314
- }
315
-
316
- if ($refunds === true) {
317
- Komfortkasse_Order::updateRefund($id, $status, $callbackid);
318
- } else {
319
- $order = Komfortkasse_Order::getOrder($id);
320
- if ($id != $order ['number']) {
321
- continue;
322
- }
323
-
324
- $newstatus = Komfortkasse::getNewStatus($status, $order);
325
- if (empty($newstatus) === true) {
326
- continue;
327
- }
328
-
329
- // only update if order status update is necessary (dont update if order has been updated manually)
330
- if ($order['status'] == $newstatus) {
331
- $o = $o . Komfortkasse::kk_csv($id);
332
- continue;
333
- }
334
-
335
- // dont update if order is no longer relevant (will be marked as DISAPPEARED later on)
336
- if (in_array($order ['number'], $openids) === false) {
337
- continue;
338
- }
339
-
340
- Komfortkasse_Order::updateOrder($order, $newstatus, $callbackid);
341
- }
342
-
343
- $o = $o . Komfortkasse::kk_csv($id);
344
- } // end foreach
345
-
346
- $cry = Komfortkasse::kkencrypt($o);
347
- if ($cry === false) {
348
- Komfortkasse::output(Komfortkasse::kkcrypterror());
349
- } else {
350
- Komfortkasse::output($cry);
351
- }
352
-
353
- }
354
-
355
- // end update()
356
-
357
- private static function isOpen($order)
358
- {
359
- $status = '';
360
- switch ($order ['type']) {
361
- case 'PREPAYMENT' :
362
- $status = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open, $order);
363
- break;
364
- case 'INVOICE' :
365
- $status = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_invoice, $order);
366
- break;
367
- case 'COD' :
368
- $status = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_cod, $order);
369
- break;
370
- default:
371
- return false;
372
- }
373
-
374
- return in_array($order['status'], explode(',', $status));
375
- }
376
-
377
- /**
378
- * Notify order.
379
- *
380
- * @param unknown $id Order ID
381
- *
382
- * @return void
383
- */
384
- public static function notifyorder($id)
385
- {
386
- if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
387
- return;
388
- }
389
-
390
- $order = Komfortkasse_Order::getOrder($id);
391
- $order['type'] = self::getOrderType($order);
392
-
393
- // See if order is relevant.
394
- if (!self::isOpen($order)) {
395
- return;
396
- }
397
-
398
- $queryRaw = http_build_query($order);
399
-
400
- $queryEnc = Komfortkasse::kkencrypt($queryRaw);
401
-
402
- $query = http_build_query(array ('q' => $queryEnc,'hash' => Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode, $order),'key' => Komfortkasse_Config::getConfig(Komfortkasse_Config::apikey)
403
- ));
404
-
405
- $contextData = array ('method' => 'POST','timeout' => 2,'header' => "Connection: close\r\n" . 'Content-Length: ' . strlen($query) . "\r\n",'content' => $query
406
- );
407
-
408
- $context = stream_context_create(array ('http' => $contextData
409
- ));
410
-
411
- // Development: http://localhost:8080/kkos01/api...
412
- $result = @file_get_contents('http://api.komfortkasse.eu/api/shop/neworder.jsf', false, $context);
413
-
414
- }
415
-
416
- // end notifyorder()
417
-
418
-
419
- /**
420
- * Info.
421
- *
422
- * @return void
423
- */
424
- public static function info()
425
- {
426
- if (Komfortkasse::check() === false) {
427
- return;
428
- }
429
-
430
- $version = Komfortkasse_Config::getVersion();
431
-
432
- $o = '';
433
- $o = $o . Komfortkasse::kk_csv($version);
434
- $o = $o . Komfortkasse::kk_csv(Komfortkasse::PLUGIN_VER);
435
-
436
- $cry = Komfortkasse::kkencrypt($o);
437
- if ($cry === false) {
438
- Komfortkasse::output(Komfortkasse::kkcrypterror());
439
- } else {
440
- Komfortkasse::output($cry);
441
- }
442
-
443
- }
444
-
445
- // end info()
446
-
447
-
448
- /**
449
- * Retrieve new status.
450
- *
451
- * @param unknown $status Status
452
- *
453
- * @return mixed
454
- */
455
- protected static function getNewStatus($status, $order)
456
- {
457
- $orderType = self::getOrderType($order);
458
-
459
- switch ($orderType) {
460
- case 'PREPAYMENT' :
461
- switch ($status) {
462
- case 'PAID' :
463
- return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_paid, $order);
464
- case 'CANCELLED' :
465
- return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_cancelled, $order);
466
- }
467
- return null;
468
- case 'INVOICE' :
469
- switch ($status) {
470
- case 'PAID' :
471
- return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_paid_invoice, $order);
472
- case 'CANCELLED' :
473
- return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_cancelled_invoice, $order);
474
- }
475
- return null;
476
- case 'COD' :
477
- switch ($status) {
478
- case 'PAID' :
479
- return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_paid_cod, $order);
480
- case 'CANCELLED' :
481
- return Komfortkasse_Config::getConfig(Komfortkasse_Config::status_cancelled_cod, $order);
482
- }
483
- return null;
484
- }
485
-
486
- }
487
-
488
- // end getNewStatus()
489
-
490
-
491
- /**
492
- * Check.
493
- *
494
- * @return boolean
495
- */
496
- public static function check()
497
- {
498
- $ac = Komfortkasse_Config::getRequestParameter('accesscode');
499
-
500
- if (!$ac || md5($ac) !== Komfortkasse_Config::getConfig(Komfortkasse_Config::accesscode)) {
501
- return false;
502
- } else {
503
- return true;
504
- }
505
-
506
- }
507
-
508
- // end check()
509
-
510
-
511
- /**
512
- * Encrypt.
513
- *
514
- * @param string $s String to encrypt
515
- * @param string $encryption encryption method
516
- * @param string $keystring key string
517
- *
518
- * @return mixed
519
- *
520
- */
521
- protected static function kkencrypt($s, $encryption = null, $keystring = null)
522
- {
523
- if (!$encryption) {
524
- $encryption = Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption);
525
- }
526
- if (!$keystring) {
527
- $keystring = Komfortkasse_Config::getConfig(Komfortkasse_Config::publickey);
528
- }
529
- if ($s === '') {
530
- return '';
531
- }
532
-
533
- switch ($encryption) {
534
- case 'openssl' :
535
- return Komfortkasse::kkencrypt_openssl($s, $keystring);
536
- case 'mcrypt' :
537
- return Komfortkasse::kkencrypt_mcrypt($s);
538
- case 'base64' :
539
- return Komfortkasse::kkencrypt_base64($s);
540
- }
541
-
542
- }
543
-
544
- // end kkencrypt()
545
-
546
-
547
- /**
548
- * Decrypt.
549
- *
550
- *
551
- * @param string $s String to decrypt
552
- * @param string $encryption encryption method
553
- * @param string $keystring key string
554
- *
555
- * @return Ambigous <boolean, string>|string
556
- */
557
- protected static function kkdecrypt($s, $encryption = null, $keystring = null)
558
- {
559
- if (!$encryption) {
560
- $encryption = Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption);
561
- }
562
- if (!$keystring) {
563
- $keystring = Komfortkasse_Config::getConfig(Komfortkasse_Config::privatekey);
564
- }
565
- if ($s === '') {
566
- return '';
567
- }
568
-
569
- switch ($encryption) {
570
- case 'openssl' :
571
- return Komfortkasse::kkdecrypt_openssl($s, $keystring);
572
- case 'mcrypt' :
573
- return Komfortkasse::kkdecrypt_mcrypt($s);
574
- case 'base64' :
575
- return Komfortkasse::kkdecrypt_base64($s);
576
- }
577
-
578
- }
579
-
580
- // end kkdecrypt()
581
-
582
-
583
- /**
584
- * Show encryption/decryption error.
585
- *
586
- * @param string $encryption encryption method
587
- *
588
- * @return mixed
589
- */
590
- protected static function kkcrypterror($encryption)
591
- {
592
- if (!$encryption) {
593
- $encryption = Komfortkasse_Config::getConfig(Komfortkasse_Config::encryption);
594
- }
595
-
596
- switch ($encryption) {
597
- case 'openssl' :
598
- return str_replace(':', ';', openssl_error_string());
599
- }
600
-
601
- }
602
-
603
- // end kkcrypterror()
604
-
605
-
606
- /**
607
- * Encrypt with base 64.
608
- *
609
- * @param string $s String to encrypt
610
- *
611
- * @return string decrypted string
612
- */
613
- protected static function kkencrypt_base64($s)
614
- {
615
- return Komfortkasse::mybase64_encode($s);
616
-
617
- }
618
-
619
- // end kkencrypt_base64()
620
-
621
-
622
- /**
623
- * Decrypt with base 64.
624
- *
625
- * @param string $s String to decrypt
626
- *
627
- * @return string decrypted string
628
- */
629
- protected static function kkdecrypt_base64($s)
630
- {
631
- return Komfortkasse::mybase64_decode($s);
632
-
633
- }
634
-
635
- // end kkdecrypt_base64()
636
-
637
-
638
- /**
639
- * Encrypt with mcrypt.
640
- *
641
- * @param string $s String to encrypt
642
- *
643
- * @return string decrypted string
644
- */
645
- protected static function kkencrypt_mcrypt($s)
646
- {
647
- $key = Komfortkasse_Config::getConfig(Komfortkasse_Config::privatekey);
648
- $iv = Komfortkasse_Config::getConfig(Komfortkasse_Config::publickey);
649
- $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $iv);
650
- $init = mcrypt_generic_init($td, $key, $iv);
651
-
652
- $padlen = ((strlen($s) + Komfortkasse::LEN_MCRYPT) % Komfortkasse::LEN_MCRYPT);
653
- $s = str_pad($s, (strlen($s) + $padlen), ' ');
654
- $encrypted = mcrypt_generic($td, $s);
655
-
656
- mcrypt_generic_deinit($td);
657
- mcrypt_module_close($td);
658
-
659
- return Komfortkasse::mybase64_encode($encrypted);
660
-
661
- }
662
-
663
- // end kkencrypt_mcrypt()
664
-
665
-
666
- /**
667
- * Encrypt with open ssl.
668
- *
669
- * @param string $s String to encrypt
670
- * @param string $keystring Key string
671
- *
672
- * @return string decrypted string
673
- */
674
- protected static function kkencrypt_openssl($s, $keystring)
675
- {
676
- $ret = '';
677
-
678
- $pubkey = "-----BEGIN PUBLIC KEY-----\n" . chunk_split($keystring, 64, "\n") . "-----END PUBLIC KEY-----\n";
679
- $key = openssl_get_publickey($pubkey);
680
- if ($key === false) {
681
- return false;
682
- }
683
-
684
- do {
685
- $current = substr($s, 0, Komfortkasse::MAXLEN_SSL);
686
- $s = substr($s, Komfortkasse::MAXLEN_SSL);
687
- if (openssl_public_encrypt($current, $encrypted, $key) === false) {
688
- return false;
689
- }
690
-
691
- $ret = $ret . "\n" . Komfortkasse::mybase64_encode($encrypted);
692
- } while ( $s );
693
-
694
- openssl_free_key($key);
695
- return $ret;
696
-
697
- }
698
-
699
- // end kkencrypt_openssl()
700
-
701
-
702
- /**
703
- * Decrypt with open ssl.
704
- *
705
- * @param string $s String to decrypt
706
- * @param string $keystring Key string
707
- *
708
- * @return string decrypted string
709
- */
710
- protected static function kkdecrypt_openssl($s, $keystring)
711
- {
712
- $ret = '';
713
-
714
- $privkey = "-----BEGIN RSA PRIVATE KEY-----\n" . chunk_split($keystring, 64, "\n") . "-----END RSA PRIVATE KEY-----\n";
715
- $key = openssl_get_privatekey($privkey);
716
- if ($key === false) {
717
- return false;
718
- }
719
-
720
- $parts = explode("\n", $s);
721
- foreach ($parts as $part) {
722
- if ($part) {
723
- if (openssl_private_decrypt(Komfortkasse::mybase64_decode($part), $decrypted, $key) === false) {
724
- return false;
725
- }
726
- $ret = $ret . $decrypted;
727
- }
728
- }
729
-
730
- openssl_free_key($key);
731
- return $ret;
732
-
733
- }
734
-
735
- // end kkdecrypt_openssl()
736
-
737
-
738
- /**
739
- * Decrypt with mcrypt.
740
- *
741
- * @param string $s String to decrypt
742
- *
743
- * @return string decrypted string
744
- */
745
- protected static function kkdecrypt_mcrypt($s)
746
- {
747
- $key = Komfortkasse_Config::getConfig(Komfortkasse_Config::privatekey);
748
- $iv = Komfortkasse_Config::getConfig(Komfortkasse_Config::publickey);
749
- $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $iv);
750
- $init = mcrypt_generic_init($td, $key, $iv);
751
-
752
- $ret = '';
753
-
754
- $parts = explode("\n", $s);
755
- foreach ($parts as $part) {
756
- if ($part) {
757
- $decrypted = mdecrypt_generic($td, Komfortkasse::mybase64_decode($part));
758
- $ret = $ret . trim($decrypted);
759
- }
760
- }
761
-
762
- mcrypt_generic_deinit($td);
763
- mcrypt_module_close($td);
764
- return $ret;
765
-
766
- }
767
-
768
- // end kkdecrypt_mcrypt()
769
-
770
-
771
- /**
772
- * Output CSV.
773
- *
774
- * @param string $s String to output
775
- *
776
- * @return string CSV
777
- */
778
- protected static function kk_csv($s)
779
- {
780
- return '"' . str_replace('"', '', str_replace(';', ',', utf8_encode($s))) . '";';
781
-
782
- }
783
-
784
- // end kk_csv()
785
-
786
-
787
- /**
788
- * Output
789
- *
790
- * @param mixed $s Data to output
791
- */
792
- protected static function output($s)
793
- {
794
- echo $s;
795
-
796
- }
797
-
798
- // end output()
799
-
800
-
801
- /**
802
- * Count
803
- *
804
- * @param array $array Arrays
805
- *
806
- * @return int count
807
- */
808
- protected static function mycount($array)
809
- {
810
- return count($array);
811
-
812
- }
813
-
814
- // end mycount()
815
- protected static function mybase64_decode($s)
816
- {
817
- return base64_decode($s);
818
-
819
- }
820
-
821
- // end mybase64_decode()
822
- protected static function mybase64_encode($s)
823
- {
824
- return base64_encode($s);
825
-
826
- }
827
-
828
- // end mybase64_encode()
829
-
830
- public static function getOrderType($order) {
831
- $payment_method = $order['payment_method'];
832
-
833
- $paycodes = preg_split('/,/', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $order));
834
- if (in_array($payment_method, $paycodes))
835
- return 'PREPAYMENT';
836
- $paycodes = preg_split('/,/', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $order));
837
- if (in_array($payment_method, $paycodes))
838
- return 'INVOICE';
839
- $paycodes = preg_split('/,/', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_cod, $order));
840
- if (in_array($payment_method, $paycodes))
841
- return 'COD';
842
- return '';
843
- }
844
-
845
- public static function readinvoicepdf() {
846
- Komfortkasse_Order::getInvoicePdfPrepare();
847
-
848
- if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export)) {
849
- return;
850
- }
851
-
852
- if (Komfortkasse::check() === false) {
853
- return;
854
- }
855
-
856
- $invoiceNumber = Komfortkasse_Config::getRequestParameter('o');
857
- $invoiceNumber = Komfortkasse::kkdecrypt($invoiceNumber);
858
- $orderNumber = Komfortkasse_Config::getRequestParameter('order_id');
859
- $orderNumber = Komfortkasse::kkdecrypt($orderNumber);
860
-
861
- return Komfortkasse_Order::getInvoicePdf($invoiceNumber, $orderNumber);
862
-
863
- }
864
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse_Config.php CHANGED
@@ -3,7 +3,7 @@
3
  /**
4
  * Komfortkasse
5
  * Config Class
6
- * @version 1.4.4.15-Magento */
7
  class Komfortkasse_Config
8
  {
9
  const activate_export = 'payment/komfortkasse/activate_export';
@@ -109,4 +109,10 @@ class Komfortkasse_Config
109
  return Mage::getVersion();
110
 
111
  } // end getVersion()
 
 
 
 
 
 
112
  }//end class
3
  /**
4
  * Komfortkasse
5
  * Config Class
6
+ * @version 1.7.2-Magento */
7
  class Komfortkasse_Config
8
  {
9
  const activate_export = 'payment/komfortkasse/activate_export';
109
  return Mage::getVersion();
110
 
111
  } // end getVersion()
112
+
113
+ public static function output($s)
114
+ {
115
+ echo $s;
116
+ }
117
+
118
  }//end class
app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse_Order.php CHANGED
@@ -8,7 +8,7 @@
8
  * status: data type according to the shop system
9
  * delivery_ and billing_: _firstname, _lastname, _company, _street, _postcode, _city, _countrycode
10
  * products: an Array of item numbers
11
- * @version 1.6.3-Magento1
12
  */
13
  $path = Mage::getModuleDir('', 'Ltc_Komfortkasse');
14
  global $komfortkasse_order_extension;
@@ -161,6 +161,8 @@ class Komfortkasse_Order
161
  {
162
  $ret = array ();
163
 
 
 
164
  foreach (Mage::app()->getWebsites() as $website) {
165
  foreach ($website->getGroups() as $group) {
166
  $stores = $group->getStores();
@@ -178,7 +180,7 @@ class Komfortkasse_Order
178
  $paymentMethodsInvoice = explode(',', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $store_id_order));
179
 
180
  $cmModel = Mage::getModel("sales/order_creditmemo");
181
- $cmCollection = $cmModel->getCollection()->addFieldToFilter('store_id', $store_id);
182
 
183
  foreach ($cmCollection as $creditMemo) {
184
  if ($creditMemo->getTransactionId() == null) {
@@ -608,4 +610,35 @@ class Komfortkasse_Order
608
  }
609
 
610
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
611
  }//end class
8
  * status: data type according to the shop system
9
  * delivery_ and billing_: _firstname, _lastname, _company, _street, _postcode, _city, _countrycode
10
  * products: an Array of item numbers
11
+ * @version 1.7.2-Magento1
12
  */
13
  $path = Mage::getModuleDir('', 'Ltc_Komfortkasse');
14
  global $komfortkasse_order_extension;
161
  {
162
  $ret = array ();
163
 
164
+ $minDate = date('Y-m-d', time() - 31536000); // 1 Jahr
165
+
166
  foreach (Mage::app()->getWebsites() as $website) {
167
  foreach ($website->getGroups() as $group) {
168
  $stores = $group->getStores();
180
  $paymentMethodsInvoice = explode(',', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $store_id_order));
181
 
182
  $cmModel = Mage::getModel("sales/order_creditmemo");
183
+ $cmCollection = $cmModel->getCollection()->addFieldToFilter('store_id', $store_id)->addAttributeToFilter('created_at', array('gt' => $minDate));
184
 
185
  foreach ($cmCollection as $creditMemo) {
186
  if ($creditMemo->getTransactionId() == null) {
610
  }
611
 
612
  }
613
+
614
+ public static function isOpen($order)
615
+ {
616
+ if ($order['payment_method'] == 'm2epropayment') {
617
+ // m2e Bestellung nur relevant wenn eBay-Zahlungsart passend
618
+ $mage = Mage::getModel('sales/order')->loadByIncrementId($order['number']);
619
+ $m2e = Mage::getModel('M2ePro/Order');
620
+ if ($m2e && $m2e->load($mage->getEntityId(), 'magento_order_id')) {
621
+ $ebay = Mage::getModel('M2ePro/Ebay_Order');
622
+ if ($ebay->load($m2e->getId(), 'order_id')) {
623
+ $ebay_method = $ebay->getPaymentMethod();
624
+
625
+ $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $order);
626
+ if (strstr($paymentMethods, 'm2epropayment') !== false) {
627
+ return strstr($ebay_method, 'berweisung') !== false;
628
+ }
629
+ $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_cod, $order);
630
+ if (strstr($paymentMethods, 'm2epropayment') !== false) {
631
+ return strstr($ebay_method, 'Nachnahme') !== false;
632
+ }
633
+ $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $order);
634
+ if (strstr($paymentMethods, 'm2epropayment') !== false) {
635
+ return strstr($ebay_method, 'Rechnung') !== false;
636
+ }
637
+
638
+ }
639
+ }
640
+ }
641
+ }
642
+
643
+
644
  }//end class
app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse_Order.php.esouq ADDED
@@ -0,0 +1,611 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ /**
5
+ * Komfortkasse Order Class
6
+ * in KK, an Order is an Array providing the following members:
7
+ * number, date, email, customer_number, payment_method, amount, currency_code, exchange_rate, language_code, invoice_number, store_id
8
+ * status: data type according to the shop system
9
+ * delivery_ and billing_: _firstname, _lastname, _company, _street, _postcode, _city, _countrycode
10
+ * products: an Array of item numbers
11
+ * @version 1.6.3-Magento1
12
+ */
13
+ $path = Mage::getModuleDir('', 'Ltc_Komfortkasse');
14
+ global $komfortkasse_order_extension;
15
+ $komfortkasse_order_extension = false;
16
+ if (file_exists("{$path}/Helper/Komfortkasse_Order_Extension.php") === true) {
17
+ $komfortkasse_order_extension = true;
18
+ include_once "{$path}/Helper/Komfortkasse_Order_Extension.php";
19
+ }
20
+ class Komfortkasse_Order
21
+ {
22
+
23
+
24
+ private static function createInClause($arr)
25
+ {
26
+ if (!is_array($arr)) {
27
+ $arr = explode(',', $arr);
28
+ }
29
+ $tmp = array ();
30
+ foreach ($arr as $item) {
31
+ $tmp [] = str_replace('\'', '', $item);
32
+ }
33
+ return '(\'' . implode('\', \'', $tmp) . '\')';
34
+
35
+ }
36
+
37
+
38
+ /**
39
+ * Get open order IDs.
40
+ *
41
+ * @return string all order IDs that are "open" and relevant for transfer to kk
42
+ */
43
+ public static function getOpenIDs()
44
+ {
45
+ $ret = array ();
46
+
47
+ $resource = Mage::getSingleton('core/resource');
48
+ $readConnection = $resource->getConnection('core_read');
49
+ $tableOrder = $resource->getTableName('sales/order');
50
+ $tablePayment = $resource->getTableName('sales/order_payment');
51
+
52
+ $minDate = date('Y-m-d', time() - 31536000); // 1 Jahr
53
+
54
+ $m2e = Mage::getModel('M2ePro/Order');
55
+
56
+ $shopIds = Komfortkasse_Config::getRequestParameter('s');
57
+ if ($shopIds)
58
+ $shopIds = Komfortkasse::kkdecrypt($shopIds);
59
+ $store_codes = $shopIds ? explode(',', $shopIds) : array ();
60
+
61
+ foreach (Mage::app()->getWebsites() as $website) {
62
+ foreach ($website->getGroups() as $group) {
63
+ $stores = $group->getStores();
64
+ foreach ($stores as $store) {
65
+ $store_code = $store->getCode();
66
+ if (empty($store_codes) || in_array($store_code, $store_codes)) {
67
+
68
+ $store_id = $store->getId();
69
+ $store_id_order = array ();
70
+ $store_id_order ['store_id'] = $store_id;
71
+
72
+ if (Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export, $store_id_order)) {
73
+
74
+ $m2e_active = $m2e && Komfortkasse_Config::getConfig('payment/m2epropayment/active', $store_id_order);
75
+
76
+ $query = 'SELECT o.increment_id FROM ' . $tableOrder . ' o join ' . $tablePayment . ' p on p.parent_id = o.entity_id';
77
+ if ($m2e_active)
78
+ $query .= ' left join ' . $resource->getTableName('M2ePro/Order') . ' m on m.magento_order_id=o.entity_id left join ' . $resource->getTableName('M2ePro/Ebay_Order') . ' e on e.order_id=m.id ';
79
+
80
+ $query .= ' where o.store_id=' . $store_id . ' and created_at > ' . $minDate . ' and (';
81
+ $first = true;
82
+ $m2e_used = false;
83
+
84
+ // PREPAYMENT
85
+ $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open, $store_id_order);
86
+ $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $store_id_order);
87
+ if ($openOrders && $paymentMethods) {
88
+ if (!$first)
89
+ $query .= ' or ';
90
+ $query .= '(o.status in ' . self::createInClause($openOrders) . ' and p.method in ' . self::createInClause($paymentMethods);
91
+
92
+ if ($m2e_active && !$m2e_used && strstr($paymentMethods, 'm2epropayment') !== false) {
93
+ $query .= ' and (p.method <> \'m2epropayment\' or e.payment_details like \'%"method":"%berweisung"%\') ';
94
+ $m2e_used = true;
95
+ }
96
+
97
+ $query .= ')';
98
+ $first = false;
99
+ }
100
+
101
+ // COD
102
+ $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_cod, $store_id_order);
103
+ $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_cod, $store_id_order);
104
+ if ($openOrders && $paymentMethods) {
105
+ if (!$first)
106
+ $query .= ' or ';
107
+ $query .= '(o.status in ' . self::createInClause($openOrders) . ' and p.method in ' . self::createInClause($paymentMethods);
108
+
109
+ if ($m2e_active && !$m2e_used && strstr($paymentMethods, 'm2epropayment') !== false) {
110
+ $query .= ' and (p.method <> \'m2epropayment\' or e.payment_details like \'%"method":"Nachnahme"%\') ';
111
+ $m2e_used = true;
112
+ }
113
+
114
+ $query .= ')';
115
+ $first = false;
116
+ }
117
+
118
+ // INVOICE
119
+ $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_invoice, $store_id_order);
120
+ $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $store_id_order);
121
+ if ($openOrders && $paymentMethods) {
122
+ if (!$first)
123
+ $query .= ' or ';
124
+ $query .= '(o.status in ' . self::createInClause($openOrders) . ' and p.method in ' . self::createInClause($paymentMethods);
125
+
126
+ if ($m2e_active && !$m2e_used && strstr($paymentMethods, 'm2epropayment') !== false) {
127
+ $query .= ' and (p.method <> \'m2epropayment\' or e.payment_details like \'%"method":"Rechnung"%\') ';
128
+ $m2e_used = true;
129
+ }
130
+
131
+ $query .= ')';
132
+ $first = false;
133
+ }
134
+
135
+ $query .= ')';
136
+ if (!$first) { // nur wenn min. eine teil-query angehängt wurde
137
+ $results = $readConnection->fetchAll($query);
138
+ foreach ($results as $result) {
139
+ $ret [] = $result ['increment_id'];
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ }
147
+
148
+ return $ret;
149
+
150
+ }
151
+
152
+ // end getOpenIDs()
153
+
154
+
155
+ /**
156
+ * Get refund IDS.
157
+ *
158
+ * @return string all refund IDs that are "open" and relevant for transfer to kk
159
+ */
160
+ public static function getRefundIDs()
161
+ {
162
+ $ret = array ();
163
+
164
+ foreach (Mage::app()->getWebsites() as $website) {
165
+ foreach ($website->getGroups() as $group) {
166
+ $stores = $group->getStores();
167
+ foreach ($stores as $store) {
168
+
169
+ $store_id = $store->getId();
170
+ $store_id_order = array ();
171
+ $store_id_order ['store_id'] = $store_id;
172
+
173
+ if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export, $store_id_order)) {
174
+ continue;
175
+ }
176
+
177
+ $paymentMethods = explode(',', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $store_id_order));
178
+ $paymentMethodsInvoice = explode(',', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $store_id_order));
179
+
180
+ $cmModel = Mage::getModel("sales/order_creditmemo");
181
+ $cmCollection = $cmModel->getCollection()->addFieldToFilter('store_id', $store_id);
182
+
183
+ foreach ($cmCollection as $creditMemo) {
184
+ if ($creditMemo->getTransactionId() == null) {
185
+ $order = $creditMemo->getOrder();
186
+ try {
187
+ $method = $order->getPayment()->getMethodInstance()->getCode();
188
+ } catch ( Exception $e ) {
189
+ // payment method has been deleted
190
+ $method = null;
191
+ }
192
+ if ($method && (in_array($method, $paymentMethods, true) === true || in_array($method, $paymentMethodsInvoice, true) === true)) {
193
+ $cmId = $creditMemo->getIncrementId();
194
+ $ret [] = $cmId;
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+
202
+ return $ret;
203
+
204
+ }
205
+
206
+ // end getRefundIDs()
207
+
208
+
209
+ /**
210
+ * Get order.
211
+ *
212
+ * @param string $number order number
213
+ *
214
+ * @return array order
215
+ */
216
+ public static function getOrder($number)
217
+ {
218
+ $order = Mage::getModel('sales/order')->loadByIncrementId($number);
219
+ if (empty($number) === true || empty($order) === true || $number != $order->getIncrementId()) {
220
+ return null;
221
+ }
222
+
223
+ $conf_general = Mage::getStoreConfig('general', $order->getStoreId());
224
+
225
+ $ret = array ();
226
+ $ret ['store_id'] = $order->getStoreId();
227
+ $ret ['invoice_date'] = null;
228
+ $ret ['number'] = $order->getIncrementId();
229
+ $ret ['status'] = $order->getStatus();
230
+ $ret ['date'] = date('d.m.Y', strtotime($order->getCreatedAtStoreDate()->get(Zend_Date::DATE_MEDIUM)));
231
+ $ret ['email'] = $order->getCustomerEmail();
232
+ $ret ['customer_number'] = $order->getCustomerId();
233
+ try {
234
+ $ret ['payment_method'] = $order->getPayment()->getMethodInstance()->getCode();
235
+ } catch ( Exception $e ) {
236
+ }
237
+ $ret ['amount'] = $order->getGrandTotal();
238
+ $ret ['currency_code'] = $order->getOrderCurrencyCode();
239
+ $ret ['exchange_rate'] = $order->getBaseToOrderRate();
240
+
241
+ // Rechnungsnummer und -datum, evtl. Rechnungsbetrag
242
+ $useInvoiceAmount = Komfortkasse::getOrderType($ret) == 'INVOICE' && Komfortkasse_Config::getConfig(Komfortkasse_Config::use_invoice_total, $ret);
243
+ $considerCreditnotes = $useInvoiceAmount && Komfortkasse_Config::getConfig(Komfortkasse_Config::consider_creditnotes, $ret);
244
+ $creditnotesAsInvoices = Komfortkasse_Config::getConfig(Komfortkasse_Config::creditnotes_as_invoices, $ret);
245
+ $lastOnly = Komfortkasse_Config::getConfig(Komfortkasse_Config::last_receipt_only, $ret);
246
+ $invoiceColl = $order->getInvoiceCollection();
247
+ $creditColl = $order->getCreditmemosCollection();
248
+ $invAmount = 0.0;
249
+
250
+ if ($lastOnly) {
251
+ // nur der letzte Beleg wird übertragen
252
+ $newestInvoice = null;
253
+ foreach ($invoiceColl as $invoice) {
254
+ if (!$invoice->isCanceled()) {
255
+ if ($newestInvoice == null || $newestInvoice->getCreatedAt() < $invoice->getCreatedAt()) {
256
+ $newestInvoice = $invoice;
257
+ }
258
+ }
259
+ }
260
+ $newestCredit = null;
261
+ if ($creditnotesAsInvoices) {
262
+ foreach ($creditColl as $credit) {
263
+ if ($newestCredit == null || $newestCredit->getCreatedAt() < $credit->getCreatedAt()) {
264
+ $newestCredit = $credit;
265
+ }
266
+ }
267
+ }
268
+ if ($newestCredit != null || $newestInvoice != null) {
269
+ if ($newestCredit == null || ($newestInvoice != null && $newestInvoice->getCreatedAt() > $newestCredit->getCreatedAt())) {
270
+ $ret ['invoice_number'] [] = $newestInvoice->getIncrementId();
271
+ $ret ['invoice_date'] = date('d.m.Y', strtotime($newestInvoice->getCreatedAt()));
272
+ $invAmount = $newestInvoice->getGrandTotal();
273
+ } else if ($newestCredit != null) {
274
+ $ret ['invoice_number'] [] = $newestCredit->getIncrementId();
275
+ $ret ['invoice_date'] = date('d.m.Y', strtotime($newestCredit->getCreatedAt()));
276
+ $invAmount = $newestCredit->getGrandTotal();
277
+ }
278
+ }
279
+ } else {
280
+ // alle Belege werden übertragen
281
+ if ($invoiceColl->getSize() > 0 || ($creditnotesAsInvoices && $creditColl->getSize() > 0)) {
282
+ foreach ($invoiceColl as $invoice) {
283
+ if (!$invoice->isCanceled()) {
284
+ $ret ['invoice_number'] [] = $invoice->getIncrementId();
285
+ $invoiceDate = date('d.m.Y', strtotime($invoice->getCreatedAt()));
286
+ if ($ret ['invoice_date'] == null || strtotime($ret ['invoice_date']) < strtotime($invoiceDate)) {
287
+ $ret ['invoice_date'] = $invoiceDate;
288
+ }
289
+ $invAmount = $invAmount + $invoice->getGrandTotal();
290
+ }
291
+ }
292
+ if (!$creditnotesAsInvoices && $considerCreditnotes) {
293
+ foreach ($creditColl as $credit) {
294
+ $invAmount = $invAmount - $credit->getGrandTotal();
295
+ }
296
+ }
297
+ if ($creditnotesAsInvoices) {
298
+ foreach ($creditColl as $credit) {
299
+ $ret ['invoice_number'] [] = $credit->getIncrementId();
300
+ $invoiceDate = date('d.m.Y', strtotime($credit->getCreatedAt()));
301
+ if ($ret ['invoice_date'] == null || strtotime($ret ['invoice_date']) < strtotime($invoiceDate)) {
302
+ $ret ['invoice_date'] = $invoiceDate;
303
+ }
304
+ $invAmount = $invAmount + $credit->getGrandTotal();
305
+ }
306
+ }
307
+ }
308
+ }
309
+ if ($useInvoiceAmount && $invAmount > 0)
310
+ $ret ['amount'] = $invAmount;
311
+
312
+ $shippingAddress = $order->getShippingAddress();
313
+ if ($shippingAddress) {
314
+ $ret ['delivery_firstname'] = utf8_encode($shippingAddress->getFirstname());
315
+ $ret ['delivery_lastname'] = utf8_encode($shippingAddress->getLastname());
316
+ $ret ['delivery_company'] = utf8_encode($shippingAddress->getCompany());
317
+ $ret ['delivery_street'] = utf8_encode($shippingAddress->getStreetFull());
318
+ $ret ['delivery_postcode'] = utf8_encode($shippingAddress->getPostcode());
319
+ $ret ['delivery_city'] = utf8_encode($shippingAddress->getCity());
320
+ $ret ['delivery_countrycode'] = utf8_encode($shippingAddress->getCountryId());
321
+ }
322
+
323
+ $billingAddress = $order->getBillingAddress();
324
+ if ($billingAddress) {
325
+ $ret ['language_code'] = substr($conf_general ['locale'] ['code'], 0, 2) . '-' . $billingAddress->getCountryId();
326
+ $ret ['billing_firstname'] = utf8_encode($billingAddress->getFirstname());
327
+ $ret ['billing_lastname'] = utf8_encode($billingAddress->getLastname());
328
+ $ret ['billing_company'] = utf8_encode($billingAddress->getCompany());
329
+ $ret ['billing_street'] = utf8_encode($billingAddress->getStreetFull());
330
+ $ret ['billing_postcode'] = utf8_encode($billingAddress->getPostcode());
331
+ $ret ['billing_city'] = utf8_encode($billingAddress->getCity());
332
+ $ret ['billing_countrycode'] = utf8_encode($billingAddress->getCountryId());
333
+ } else {
334
+ $ret ['language_code'] = substr($conf_general ['locale'] ['code'], 0, 2);
335
+ }
336
+
337
+ foreach ($order->getAllItems() as $itemId => $item) {
338
+ $sku = $item->getSku();
339
+ if ($sku) {
340
+ $ret ['products'] [] = $sku;
341
+ } else {
342
+ $ret ['products'] [] = $item->getName();
343
+ }
344
+ }
345
+
346
+ $m2e = Mage::getModel('M2ePro/Order');
347
+ if ($m2e && $m2e->load($order->getEntityId(), 'magento_order_id')) {
348
+ $ebay = Mage::getModel('M2ePro/Ebay_Order');
349
+ if ($ebay->load($m2e->getId(), 'order_id')) {
350
+ $ret ['marketplace_number'] = $ebay->getEbayOrderId();
351
+ $ret ['customer_number'] = $ebay->getBuyerUserId();
352
+ }
353
+ }
354
+
355
+ global $komfortkasse_order_extension;
356
+ if ($komfortkasse_order_extension && method_exists('Komfortkasse_Order_Extension', 'extendOrder') === true) {
357
+ $ret = Komfortkasse_Order_Extension::extendOrder($order, $ret);
358
+ }
359
+
360
+ return $ret;
361
+
362
+ }
363
+
364
+ // end getOrder()
365
+
366
+
367
+ /**
368
+ * Get refund.
369
+ *
370
+ * @param string $number refund number
371
+ *
372
+ * @return array refund
373
+ */
374
+ public static function getRefund($number)
375
+ {
376
+ $resource = Mage::getSingleton('core/resource');
377
+ $id = $resource->getConnection('core_read')->fetchOne('SELECT `entity_id` FROM `' . $resource->getTableName('sales/creditmemo') . "` WHERE `increment_id` = '" . $number . "'");
378
+
379
+ $creditMemo = Mage::getModel('sales/order_creditmemo')->load($id);
380
+ if (empty($number) === true || empty($creditMemo) === true || $number != $creditMemo->getIncrementId()) {
381
+ return null;
382
+ }
383
+
384
+ $ret = array ();
385
+ $ret ['number'] = $creditMemo->getOrder()->getIncrementId();
386
+ // Number of the Creditmemo.
387
+ $ret ['customer_number'] = $creditMemo->getIncrementId();
388
+ $ret ['date'] = date('d.m.Y', strtotime($creditMemo->getCreatedAt()));
389
+ $ret ['amount'] = $creditMemo->getGrandTotal();
390
+
391
+ return $ret;
392
+
393
+ }
394
+
395
+ // end getRefund()
396
+
397
+
398
+ /**
399
+ * Update order.
400
+ *
401
+ * @param array $order order
402
+ * @param string $status status
403
+ * @param string $callbackid callback ID
404
+ *
405
+ * @return void
406
+ */
407
+ public static function updateOrder($order, $status, $callbackid)
408
+ {
409
+ if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update, $order)) {
410
+ return;
411
+ }
412
+
413
+ // Hint: PAID and CANCELLED are supported as of now.
414
+ $order = Mage::getModel('sales/order')->loadByIncrementId($order ['number']);
415
+
416
+ Mage::log('Komfortkasse: update order ' . $order->getIncrementId() . ' START', null, 'komfortkasse.log');
417
+ Mage::dispatchEvent('komfortkasse_change_order_status_before', array ('order' => $order,'status' => $status,'callbackid' => $callbackid
418
+ ));
419
+
420
+ $stateCollection = Mage::getModel('sales/order_status')->getCollection()->joinStates();
421
+ $stateCollection->addFieldToFilter('main_table.status', array ('like' => $status
422
+ ));
423
+ $state = $stateCollection->getFirstItem()->getState();
424
+
425
+ if ($state == 'processing' || $state == 'closed' || $state == 'complete') {
426
+
427
+ // If there is already an invoice, update the invoice, not the order.
428
+ $invoiceColl = $order->getInvoiceCollection();
429
+ if ($invoiceColl->getSize() > 0) {
430
+ foreach ($order->getInvoiceCollection() as $invoice) {
431
+ Mage::log('Komfortkasse: update order ' . $order->getIncrementId() . ' invoice ' . $invoice->getIncrementId() . ' pay', null, 'komfortkasse.log');
432
+ $invoice->pay();
433
+ Mage::log('Komfortkasse: update order ' . $order->getIncrementId() . ' invoice ' . $invoice->getIncrementId() . ' addComment ' . $callbackid, null, 'komfortkasse.log');
434
+ $invoice->addComment($callbackid, false, false);
435
+ self::mysave($invoice);
436
+ }
437
+ } else {
438
+ $payment = $order->getPayment();
439
+ Mage::log('Komfortkasse: update order ' . $order->getIncrementId() . ' payment capture', null, 'komfortkasse.log');
440
+ $payment->capture(null);
441
+
442
+ if ($callbackid) {
443
+ $payment->setTransactionId($callbackid);
444
+ Mage::log('Komfortkasse: update order ' . $order->getIncrementId() . ' addTransaction', null, 'komfortkasse.log');
445
+ $transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
446
+ }
447
+ }
448
+ $order->save();
449
+ $order = Mage::getModel('sales/order')->loadByIncrementId($order->getIncrementId());
450
+
451
+ Mage::log('Komfortkasse: update order ' . $order->getIncrementId() . ' add status history ' . $status . ' / ' . $callbackid, null, 'komfortkasse.log');
452
+ $history = $order->addStatusHistoryComment('' . $callbackid, $status);
453
+ $order->setStatus($status);
454
+ $order->save();
455
+ } else if ($state == 'canceled') {
456
+
457
+ if ($callbackid) {
458
+ Mage::log('Komfortkasse: update order ' . $order->getIncrementId() . ' add status history ' . $status . ' / ' . $callbackid, null, 'komfortkasse.log');
459
+ $history = $order->addStatusHistoryComment('' . $callbackid, $status);
460
+ }
461
+ if ($order->canCancel()) {
462
+ Mage::log('Komfortkasse: update order ' . $order->getIncrementId() . ' cancel', null, 'komfortkasse.log');
463
+ $order->cancel();
464
+ }
465
+ Mage::log('Komfortkasse: update order ' . $order->getIncrementId() . ' set status ' . $status, null, 'komfortkasse.log');
466
+ $order->setStatus($status);
467
+ $order->save();
468
+ } else {
469
+
470
+ Mage::log('Komfortkasse: update order ' . $order->getIncrementId() . ' add status history ' . $status . ' / ' . $callbackid, null, 'komfortkasse.log');
471
+ $history = $order->addStatusHistoryComment('' . $callbackid, $status);
472
+ $order->save();
473
+ }
474
+
475
+ Mage::dispatchEvent('komfortkasse_change_order_status_after', array ('order' => $order,'status' => $status,'callbackid' => $callbackid
476
+ ));
477
+
478
+ Mage::log('Komfortkasse: update order ' . $order->getIncrementId() . ' END. Status: ' . $order->getStatus, null, 'komfortkasse.log');
479
+
480
+ }
481
+
482
+ // end updateOrder()
483
+
484
+
485
+ /**
486
+ * Update order.
487
+ *
488
+ * @param string $refundIncrementId Increment ID of refund
489
+ * @param string $status status
490
+ * @param string $callbackid callback ID
491
+ *
492
+ * @return void
493
+ */
494
+ public static function updateRefund($refundIncrementId, $status, $callbackid)
495
+ {
496
+ $resource = Mage::getSingleton('core/resource');
497
+ $id = $resource->getConnection('core_read')->fetchOne('SELECT `entity_id` FROM `' . $resource->getTableName('sales/creditmemo') . "` WHERE `increment_id` = '" . $refundIncrementId . "'");
498
+
499
+ $creditMemo = Mage::getModel('sales/order_creditmemo')->load($id);
500
+
501
+ $store_id = $creditMemo->getStoreId();
502
+ $store_id_order = array ();
503
+ $store_id_order ['store_id'] = $store_id;
504
+
505
+ if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update, $store_id_order)) {
506
+ return;
507
+ }
508
+
509
+ if ($creditMemo->getTransactionId() == null) {
510
+ $creditMemo->setTransactionId($callbackid);
511
+ }
512
+
513
+ $history = $creditMemo->addComment($status . ' [' . $callbackid . ']', false, false);
514
+
515
+ $creditMemo->save();
516
+
517
+ }
518
+
519
+ // end updateRefund()
520
+
521
+
522
+ /**
523
+ * Call an object's save method
524
+ *
525
+ * @param unknown $object
526
+ *
527
+ * @return void
528
+ */
529
+ private static function mysave($object)
530
+ {
531
+ $object->save();
532
+
533
+ }
534
+
535
+
536
+ public static function getInvoicePdfPrepare()
537
+ {
538
+
539
+ }
540
+
541
+
542
+ public static function getInvoicePdf($invoiceNumber, $orderNumber)
543
+ {
544
+ if ($invoiceNumber) {
545
+
546
+ $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceNumber);
547
+ $fileName = $invoiceNumber . '.pdf';
548
+
549
+ if ($invoice && (!$orderNumber || $invoice->getOrderIncrementId() == $orderNumber)) {
550
+
551
+ $pdfGenerated = false;
552
+
553
+ // try easy pdf (www.easypdfinvoice.com)
554
+ if (!$pdfGenerated) {
555
+ $pdfProModel = Mage::getModel('pdfpro/order_invoice');
556
+ if ($pdfProModel !== false) {
557
+ $invoiceData = $pdfProModel->initInvoiceData($invoice);
558
+ $result = Mage::helper('pdfpro')->initPdf(array ($invoiceData
559
+ ));
560
+ if ($result ['success']) {
561
+ $content = $result ['content'];
562
+ $pdfGenerated = true;
563
+ }
564
+ }
565
+ }
566
+
567
+ // try Magento Standard
568
+ if (!$pdfGenerated) {
569
+ $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array ($invoice
570
+ ));
571
+ $content = $pdf->render();
572
+ }
573
+ } else if (Komfortkasse_Config::getConfig(Komfortkasse_Config::creditnotes_as_invoices, self::getOrder($orderNumber))) {
574
+
575
+ // try credit note
576
+ $collection = Mage::getResourceModel('sales/order_creditmemo_collection')->addFieldToFilter('increment_id', $invoiceNumber);
577
+ $credit = $collection->count() == 1 ? $collection->getFirstItem() : null;
578
+
579
+ if ($credit && (!$orderNumber || $credit->getOrder()->getIncrementId() == $orderNumber)) {
580
+
581
+ $pdfGenerated = false;
582
+
583
+ // try easy pdf (www.easypdfinvoice.com)
584
+ if (!$pdfGenerated) {
585
+ $pdfProModel = Mage::getModel('pdfpro/order_creditmemo');
586
+ if ($pdfProModel !== false) {
587
+ $creditData = $pdfProModel->initCreditmemoData($credit);
588
+ $result = Mage::helper('pdfpro')->initPdf(array ($creditData
589
+ ));
590
+ if ($result ['success']) {
591
+ $content = $result ['content'];
592
+ // $pdfGenerated = true;
593
+ }
594
+ }
595
+ }
596
+
597
+ // try Magento Standard
598
+ if (!$pdfGenerated) {
599
+ $pdf = Mage::getModel('sales/order_pdf_creditmemo')->getPdf(array ($credit
600
+ ));
601
+ $content = $pdf->render();
602
+ }
603
+ }
604
+ }
605
+
606
+
607
+ return $content;
608
+ }
609
+
610
+ }
611
+ }//end class
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Ltc_Komfortkasse</name>
4
- <version>1.6.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://creativecommons.org/licenses/by-nd/4.0/">CC BY-ND 4.0</license>
7
  <channel>community</channel>
@@ -13,11 +13,11 @@ Zus&#xE4;tzlich k&#xF6;nnen automatische Zahlungserinnerungen versendet werden u
13
  &#xD;
14
  Es ist eine Anmeldung auf www.komfortkasse.eu erforderlich (kostenloses Paket verf&#xFC;gbar).&#xD;
15
  </description>
16
- <notes>improvements for multi shop environments</notes>
17
  <authors><author><name>Komfortkasse</name><user>komfortkasse</user><email>integration@komfortkasse.eu</email></author></authors>
18
- <date>2016-10-14</date>
19
- <time>14:13:23</time>
20
- <contents><target name="magecommunity"><dir name="Ltc"><dir name="Komfortkasse"><dir name="Helper"><file name="788426360839" hash="15e420365e230f5866897d2cbcce2bac"/><file name="Data.php" hash="42f1d168bb70725128e15daf305802ba"/><file name="Komfortkasse.php" hash="47d6e4d1a948cdbd171f193933c988a8"/><file name="Komfortkasse.php.bak" hash="2a8cd73b832172bbbed17f2c062f7e4a"/><file name="Komfortkasse_Config.php" hash="991250ec3cdbc9b7b79ab38888e3a022"/><file name="Komfortkasse_Order.php" hash="94eac48800d5f69047701b20e5631a19"/></dir><dir name="Model"><file name="Encryptionoptions.php" hash="1fbe2ffc43cc3c1489688d20f4c8af11"/><file name="Observer.php" hash="5b616b6d3651df44f8297c732dc478bb"/></dir><dir name="controllers"><file name="MainController.php" hash="b983fe60b2bbfa3aa1d57850cc6c045b"/></dir><dir name="etc"><file name="config.xml" hash="4964d847be82ded534fcbc1e12f214a3"/><file name="system.xml" hash="4477e69044c79edab2b70691b0236bd8"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ltc_Komfortkasse.xml" hash="433066ef75047d9468dcea87888283d2"/></dir></target></contents>
21
  <compatible/>
22
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
23
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Ltc_Komfortkasse</name>
4
+ <version>1.7.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://creativecommons.org/licenses/by-nd/4.0/">CC BY-ND 4.0</license>
7
  <channel>community</channel>
13
  &#xD;
14
  Es ist eine Anmeldung auf www.komfortkasse.eu erforderlich (kostenloses Paket verf&#xFC;gbar).&#xD;
15
  </description>
16
+ <notes>performance improvements</notes>
17
  <authors><author><name>Komfortkasse</name><user>komfortkasse</user><email>integration@komfortkasse.eu</email></author></authors>
18
+ <date>2016-11-10</date>
19
+ <time>13:41:45</time>
20
+ <contents><target name="magecommunity"><dir name="Ltc"><dir name="Komfortkasse"><dir name="Helper"><file name="Data.php" hash="42f1d168bb70725128e15daf305802ba"/><file name="Komfortkasse.php" hash="ab2894ec6276d3a7f1a639e15abdcb44"/><file name="Komfortkasse_Config.php" hash="fc3c24ab940dabaf5655de5b0d9ec14f"/><file name="Komfortkasse_Order.php" hash="c97ec577120a6f166986c7f712b5da25"/><file name="Komfortkasse_Order.php.esouq" hash="94eac48800d5f69047701b20e5631a19"/></dir><dir name="Model"><file name="Encryptionoptions.php" hash="1fbe2ffc43cc3c1489688d20f4c8af11"/><file name="Observer.php" hash="5b616b6d3651df44f8297c732dc478bb"/></dir><dir name="controllers"><file name="MainController.php" hash="b983fe60b2bbfa3aa1d57850cc6c045b"/></dir><dir name="etc"><file name="config.xml" hash="4964d847be82ded534fcbc1e12f214a3"/><file name="system.xml" hash="4477e69044c79edab2b70691b0236bd8"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ltc_Komfortkasse.xml" hash="433066ef75047d9468dcea87888283d2"/></dir></target></contents>
21
  <compatible/>
22
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
23
  </package>