Ltc_Komfortkasse - Version 1.4.4

Version Notes

Bugfixes and performance improvements

Download this release

Release Info

Developer Komfortkasse
Extension Ltc_Komfortkasse
Version 1.4.4
Comparing to
See all releases


Code changes from version 1.4.3.1 to 1.4.4

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.4.3.1';
12
  const MAXLEN_SSL = 117;
13
  const LEN_MCRYPT = 16;
14
 
@@ -353,6 +353,26 @@ class Komfortkasse
353
 
354
  // end update()
355
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
 
357
  /**
358
  * Notify order.
@@ -367,15 +387,14 @@ class Komfortkasse
367
  return;
368
  }
369
 
370
- // See if order is relevant.
371
- $openids = Komfortkasse_Order::getOpenIDs();
372
- if (in_array($id, $openids) === false) {
373
- return;
374
- }
375
-
376
  $order = Komfortkasse_Order::getOrder($id);
377
  $order['type'] = self::getOrderType($order['payment_method']);
378
 
 
 
 
 
 
379
  $queryRaw = http_build_query($order);
380
 
381
  $queryEnc = Komfortkasse::kkencrypt($queryRaw);
8
  */
9
  class Komfortkasse
10
  {
11
+ const PLUGIN_VER = '1.4.4';
12
  const MAXLEN_SSL = 117;
13
  const LEN_MCRYPT = 16;
14
 
353
 
354
  // end update()
355
 
356
+ private static function isOpen($order)
357
+ {
358
+ $methods = '';
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, $order);
366
+ break;
367
+ case 'COD' :
368
+ $status = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open, $order);
369
+ break;
370
+ default:
371
+ return false;
372
+ }
373
+
374
+ return in_array($order['status'], explode(',', $status));
375
+ }
376
 
377
  /**
378
  * Notify order.
387
  return;
388
  }
389
 
 
 
 
 
 
 
390
  $order = Komfortkasse_Order::getOrder($id);
391
  $order['type'] = self::getOrderType($order['payment_method']);
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);
app/code/community/Ltc/Komfortkasse/Helper/Komfortkasse_Order.php CHANGED
@@ -1,497 +1,444 @@
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.4.3.1-Magento1
12
- */
13
- $path = Mage::getModuleDir('', 'Ltc_Komfortkasse');
14
- $order_extension = false;
15
- if (file_exists("{$path}/Helper/Komfortkasse_Order_Extension.php") === true) {
16
- $order_extension = true;
17
- include_once "{$path}/Helper/Komfortkasse_Order_Extension.php";
18
- }
19
- class Komfortkasse_Order
20
- {
21
-
22
- /**
23
- * Get open order IDs.
24
- *
25
- * @return string all order IDs that are "open" and relevant for transfer to kk
26
- */
27
- public static function getOpenIDs()
28
- {
29
- $ret = array ();
30
-
31
- foreach (Mage::app()->getWebsites() as $website) {
32
- foreach ($website->getGroups() as $group) {
33
- $stores = $group->getStores();
34
- foreach ($stores as $store) {
35
-
36
- $store_id = $store->getId();
37
- $store_id_order = array ();
38
- $store_id_order ['store_id'] = $store_id;
39
-
40
- if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export, $store_id_order)) {
41
- continue;
42
- }
43
-
44
- // PREPAYMENT
45
-
46
- $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open, $store_id_order);
47
- $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $store_id_order);
48
-
49
- if (!empty($openOrders) && !empty($paymentMethods)) {
50
- $openOrders = explode(',', $openOrders);
51
- $paymentMethods = explode(',', $paymentMethods);
52
-
53
- $salesModel = Mage::getModel('sales/order');
54
- $salesCollection = $salesModel->getCollection()->addAttributeToFilter('status', array ('in' => $openOrders
55
- ))->addFieldToFilter('store_id', $store_id);
56
-
57
- foreach ($salesCollection as $order) {
58
- try {
59
- try {
60
- $method = $order->getPayment()->getMethodInstance()->getCode();
61
- } catch (Exception $e) {
62
- // payment method has been deleted
63
- $method = null;
64
- }
65
- if ($method && in_array($method, $paymentMethods, true) === true) {
66
- $orderId = $order->getIncrementId();
67
- $ret [] = $orderId;
68
- }
69
- } catch ( Exception $e ) {
70
- }
71
- }
72
-
73
- // Add all orders with unpaid invoices (in case the invoice is created before shipping).
74
- $invoiceModel = Mage::getModel('sales/order_invoice');
75
- $invoiceCollection = $invoiceModel->getCollection()->addAttributeToFilter('state', Mage_Sales_Model_Order_Invoice::STATE_OPEN)->addFieldToFilter('store_id', $store_id);
76
- foreach ($invoiceCollection as $invoice) {
77
- try {
78
- $order = $invoice->getOrder();
79
- try {
80
- $method = $order->getPayment()->getMethodInstance()->getCode();
81
- } catch (Exception $e) {
82
- // payment method has been deleted
83
- $method = null;
84
- }
85
- if ($method && in_array($method, $paymentMethods, true) === true) {
86
- $orderId = $order->getIncrementId();
87
- if (in_array($orderId, $ret) === false) {
88
- $ret [] = $orderId;
89
- }
90
- }
91
- } catch ( Exception $e ) {
92
- }
93
- }
94
- }
95
-
96
- // INVOICE
97
-
98
- $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_invoice, $store_id_order);
99
- $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $store_id_order);
100
-
101
- if (!empty($openOrders) && !empty($paymentMethods)) {
102
- $openOrders = explode(',', $openOrders);
103
- $paymentMethods = explode(',', $paymentMethods);
104
-
105
- $salesModel = Mage::getModel('sales/order');
106
- $salesCollection = $salesModel->getCollection()->addAttributeToFilter('status', array ('in' => $openOrders
107
- ))->addFieldToFilter('store_id', $store_id);
108
-
109
- foreach ($salesCollection as $order) {
110
- try {
111
- try {
112
- $method = $order->getPayment()->getMethodInstance()->getCode();
113
- } catch (Exception $e) {
114
- // payment method has been deleted
115
- $method = null;
116
- }
117
- if ($method && in_array($method, $paymentMethods, true) === true) {
118
- $orderId = $order->getIncrementId();
119
- $ret [] = $orderId;
120
- }
121
- } catch ( Exception $e ) {
122
- }
123
- }
124
- }
125
-
126
- // COD
127
-
128
- $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_cod, $store_id_order);
129
- $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_cod, $store_id_order);
130
-
131
- if (!empty($openOrders) && !empty($paymentMethods)) {
132
- $openOrders = explode(',', $openOrders);
133
- $paymentMethods = explode(',', $paymentMethods);
134
-
135
- $salesModel = Mage::getModel('sales/order');
136
- $salesCollection = $salesModel->getCollection()->addAttributeToFilter('status', array ('in' => $openOrders
137
- ))->addFieldToFilter('store_id', $store_id);
138
-
139
- foreach ($salesCollection as $order) {
140
- try {
141
- $method = $order->getPayment()->getMethodInstance()->getCode();
142
- } catch (Exception $e) {
143
- // payment method has been deleted
144
- $method = null;
145
- }
146
- if ($method && in_array($method, $paymentMethods, true) === true) {
147
- $orderId = $order->getIncrementId();
148
- $ret [] = $orderId;
149
- }
150
- }
151
- }
152
- }
153
- }
154
- }
155
-
156
-
157
- return $ret;
158
-
159
- }
160
-
161
- // end getOpenIDs()
162
-
163
-
164
- /**
165
- * Get refund IDS.
166
- *
167
- * @return string all refund IDs that are "open" and relevant for transfer to kk
168
- */
169
- public static function getRefundIDs()
170
- {
171
- $ret = array ();
172
-
173
- foreach (Mage::app()->getWebsites() as $website) {
174
- foreach ($website->getGroups() as $group) {
175
- $stores = $group->getStores();
176
- foreach ($stores as $store) {
177
-
178
- $store_id = $store->getId();
179
- $store_id_order = array ();
180
- $store_id_order ['store_id'] = $store_id;
181
-
182
- if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export, $store_id_order)) {
183
- continue;
184
- }
185
-
186
- $paymentMethods = explode(',', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $store_id_order));
187
-
188
- $cmModel = Mage::getModel("sales/order_creditmemo");
189
- $cmCollection = $cmModel->getCollection()->addFieldToFilter('store_id', $store_id);
190
-
191
- foreach ($cmCollection as $creditMemo) {
192
- if ($creditMemo->getTransactionId() == null) {
193
- $order = $creditMemo->getOrder();
194
- try {
195
- $method = $order->getPayment()->getMethodInstance()->getCode();
196
- } catch (Exception $e) {
197
- // payment method has been deleted
198
- $method = null;
199
- }
200
- if ($method && in_array($method, $paymentMethods, true) === true) {
201
- $cmId = $creditMemo->getIncrementId();
202
- $ret [] = $cmId;
203
- }
204
- }
205
- }
206
- }
207
- }
208
- }
209
-
210
- return $ret;
211
-
212
- }
213
-
214
- // end getRefundIDs()
215
-
216
-
217
- /**
218
- * Get order.
219
- *
220
- * @param string $number order number
221
- *
222
- * @return array order
223
- */
224
- public static function getOrder($number)
225
- {
226
- $order = Mage::getModel('sales/order')->loadByIncrementId($number);
227
- if (empty($number) === true || empty($order) === true || $number != $order->getIncrementId()) {
228
- return null;
229
- }
230
-
231
- $conf_general = Mage::getStoreConfig('general', $order->getStoreId());
232
-
233
- $ret = array ();
234
- $ret ['number'] = $order->getIncrementId();
235
- $ret ['status'] = $order->getStatus();
236
- $ret ['date'] = date('d.m.Y', strtotime($order->getCreatedAtStoreDate()->get(Zend_Date::DATE_MEDIUM)));
237
- $ret ['email'] = $order->getCustomerEmail();
238
- $ret ['customer_number'] = $order->getCustomerId();
239
- try {
240
- $ret ['payment_method'] = $order->getPayment()->getMethodInstance()->getCode();
241
- } catch (Exception $e) { }
242
- $ret ['amount'] = $order->getGrandTotal();
243
- $ret ['currency_code'] = $order->getOrderCurrencyCode();
244
- $ret ['exchange_rate'] = $order->getBaseToOrderRate();
245
-
246
- // Rechnungsnummer und -datum
247
- $invoiceColl = $order->getInvoiceCollection();
248
- if ($invoiceColl->getSize() > 0) {
249
- foreach ($order->getInvoiceCollection() as $invoice) {
250
- $ret ['invoice_number'] [] = $invoice->getIncrementId();
251
- $invoiceDate = date('d.m.Y', strtotime($invoice->getCreatedAt()));
252
- if ($ret['invoice_date'] == null || strtotime($ret['invoice_date']) < strtotime($invoiceDate)) {
253
- $ret['invoice_date'] = $invoiceDate;
254
- }
255
- }
256
- }
257
-
258
- $shippingAddress = $order->getShippingAddress();
259
- if ($shippingAddress) {
260
- $ret ['delivery_firstname'] = utf8_encode($shippingAddress->getFirstname());
261
- $ret ['delivery_lastname'] = utf8_encode($shippingAddress->getLastname());
262
- $ret ['delivery_company'] = utf8_encode($shippingAddress->getCompany());
263
- $ret ['delivery_street'] = utf8_encode($shippingAddress->getStreetFull());
264
- $ret ['delivery_postcode'] = utf8_encode($shippingAddress->getPostcode());
265
- $ret ['delivery_city'] = utf8_encode($shippingAddress->getCity());
266
- $ret ['delivery_countrycode'] = utf8_encode($shippingAddress->getCountryId());
267
- }
268
-
269
- $billingAddress = $order->getBillingAddress();
270
- if ($billingAddress) {
271
- $ret ['language_code'] = substr($conf_general ['locale'] ['code'], 0, 2) . '-' . $billingAddress->getCountryId();
272
- $ret ['billing_firstname'] = utf8_encode($billingAddress->getFirstname());
273
- $ret ['billing_lastname'] = utf8_encode($billingAddress->getLastname());
274
- $ret ['billing_company'] = utf8_encode($billingAddress->getCompany());
275
- $ret ['billing_street'] = utf8_encode($billingAddress->getStreetFull());
276
- $ret ['billing_postcode'] = utf8_encode($billingAddress->getPostcode());
277
- $ret ['billing_city'] = utf8_encode($billingAddress->getCity());
278
- $ret ['billing_countrycode'] = utf8_encode($billingAddress->getCountryId());
279
- } else {
280
- $ret ['language_code'] = substr($conf_general ['locale'] ['code'], 0, 2);
281
- }
282
-
283
- foreach ($order->getAllItems() as $itemId => $item) {
284
- $sku = $item->getSku();
285
- if ($sku) {
286
- $ret ['products'] [] = $sku;
287
- } else {
288
- $ret ['products'] [] = $item->getName();
289
- }
290
- }
291
-
292
- $ret ['store_id'] = $order->getStoreId();
293
-
294
- if ($order_extension && method_exists('Komfortkasse_Order_Extension', 'extendOrder') === true) {
295
- $ret = Komfortkasse_Order_Extension::extendOrder($order, $ret);
296
- }
297
-
298
- return $ret;
299
-
300
- }
301
-
302
- // end getOrder()
303
-
304
-
305
- /**
306
- * Get refund.
307
- *
308
- * @param string $number refund number
309
- *
310
- * @return array refund
311
- */
312
- public static function getRefund($number)
313
- {
314
- $resource = Mage::getSingleton('core/resource');
315
- $id = $resource->getConnection('core_read')->fetchOne('SELECT `entity_id` FROM `' . $resource->getTableName('sales/creditmemo') . "` WHERE `increment_id` = '" . $number . "'");
316
-
317
- $creditMemo = Mage::getModel('sales/order_creditmemo')->load($id);
318
- if (empty($number) === true || empty($creditMemo) === true || $number != $creditMemo->getIncrementId()) {
319
- return null;
320
- }
321
-
322
- $ret = array ();
323
- $ret ['number'] = $creditMemo->getOrder()->getIncrementId();
324
- // Number of the Creditmemo.
325
- $ret ['customer_number'] = $creditMemo->getIncrementId();
326
- $ret ['date'] = date('d.m.Y', strtotime($creditMemo->getCreatedAt()));
327
- $ret ['amount'] = $creditMemo->getGrandTotal();
328
-
329
- return $ret;
330
-
331
- }
332
-
333
- // end getRefund()
334
-
335
-
336
- /**
337
- * Update order.
338
- *
339
- * @param array $order order
340
- * @param string $status status
341
- * @param string $callbackid callback ID
342
- *
343
- * @return void
344
- */
345
- public static function updateOrder($order, $status, $callbackid)
346
- {
347
- if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update, $order)) {
348
- return;
349
- }
350
-
351
- // Hint: PAID and CANCELLED are supported as of now.
352
- $order = Mage::getModel('sales/order')->loadByIncrementId($order ['number']);
353
-
354
- Mage::dispatchEvent('komfortkasse_change_order_status_before', array ('order' => $order,'status' => $status,'callbackid' => $callbackid
355
- ));
356
-
357
- $stateCollection = Mage::getModel('sales/order_status')->getCollection()->joinStates();
358
- $stateCollection->addFieldToFilter('main_table.status', array ('like' => $status
359
- ));
360
- $state = $stateCollection->getFirstItem()->getState();
361
-
362
- if ($state == 'processing' || $state == 'closed' || $state == 'complete') {
363
-
364
- // If there is already an invoice, update the invoice, not the order.
365
- $invoiceColl = $order->getInvoiceCollection();
366
- if ($invoiceColl->getSize() > 0) {
367
- foreach ($order->getInvoiceCollection() as $invoice) {
368
- $invoice->pay();
369
- $invoice->addComment($callbackid, false, false);
370
- self::mysave($invoice);
371
- }
372
- } else {
373
- $payment = $order->getPayment();
374
- $payment->capture(null);
375
-
376
- if ($callbackid) {
377
- $payment->setTransactionId($callbackid);
378
- $transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
379
- }
380
- }
381
-
382
- $history = $order->addStatusHistoryComment('' . $callbackid, $status);
383
- $order->save();
384
- } else if ($state == 'canceled') {
385
-
386
- if ($callbackid) {
387
- $history = $order->addStatusHistoryComment('' . $callbackid, $status);
388
- }
389
- if ($order->canCancel()) {
390
- $order->cancel();
391
- }
392
- $order->setStatus($status);
393
- $order->save();
394
- } else {
395
-
396
- $history = $order->addStatusHistoryComment('' . $callbackid, $status);
397
- $order->save();
398
- }
399
-
400
- Mage::dispatchEvent('komfortkasse_change_order_status_after', array ('order' => $order,'status' => $status,'callbackid' => $callbackid
401
- ));
402
-
403
- }
404
-
405
- // end updateOrder()
406
-
407
-
408
- /**
409
- * Update order.
410
- *
411
- * @param string $refundIncrementId Increment ID of refund
412
- * @param string $status status
413
- * @param string $callbackid callback ID
414
- *
415
- * @return void
416
- */
417
- public static function updateRefund($refundIncrementId, $status, $callbackid)
418
- {
419
- $resource = Mage::getSingleton('core/resource');
420
- $id = $resource->getConnection('core_read')->fetchOne('SELECT `entity_id` FROM `' . $resource->getTableName('sales/creditmemo') . "` WHERE `increment_id` = '" . $refundIncrementId . "'");
421
-
422
- $creditMemo = Mage::getModel('sales/order_creditmemo')->load($id);
423
-
424
- $store_id = $creditMemo->getStoreId();
425
- $store_id_order = array ();
426
- $store_id_order ['store_id'] = $store_id;
427
-
428
- if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update, $store_id_order)) {
429
- return;
430
- }
431
-
432
- if ($creditMemo->getTransactionId() == null) {
433
- $creditMemo->setTransactionId($callbackid);
434
- }
435
-
436
- $history = $creditMemo->addComment($status . ' [' . $callbackid . ']', false, false);
437
-
438
- $creditMemo->save();
439
-
440
- }
441
-
442
- // end updateRefund()
443
-
444
-
445
- /**
446
- * Call an object's save method
447
- *
448
- * @param unknown $object
449
- *
450
- * @return void
451
- */
452
- private static function mysave($object)
453
- {
454
- $object->save();
455
-
456
- }
457
-
458
-
459
- public static function getInvoicePdfPrepare()
460
- {
461
-
462
- }
463
-
464
-
465
- public static function getInvoicePdf($invoiceNumber)
466
- {
467
- if ($invoiceNumber && $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceNumber)) {
468
- $fileName = $invoiceNumber . '.pdf';
469
-
470
- $pdfGenerated = false;
471
-
472
- // try easy pdf (www.easypdfinvoice.com)
473
- if (!$pdfGenerated) {
474
- $pdfProModel = Mage::getModel('pdfpro/order_invoice');
475
- if ($pdfProModel !== false) {
476
- $invoiceData = $pdfProModel->initInvoiceData($invoice);
477
- $result = Mage::helper('pdfpro')->initPdf(array ($invoiceData
478
- ));
479
- if ($result ['success']) {
480
- $content = $result ['content'];
481
- $pdfGenerated = true;
482
- }
483
- }
484
- }
485
-
486
- // try Magento Standard
487
- if (!$pdfGenerated) {
488
- $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array ($invoice
489
- ));
490
- $content = $pdf->render();
491
- }
492
-
493
- return $content;
494
- }
495
-
496
- }
497
  }//end class
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.4.4-Magento1
12
+ */
13
+ $path = Mage::getModuleDir('', 'Ltc_Komfortkasse');
14
+ $order_extension = false;
15
+ if (file_exists("{$path}/Helper/Komfortkasse_Order_Extension.php") === true) {
16
+ $order_extension = true;
17
+ include_once "{$path}/Helper/Komfortkasse_Order_Extension.php";
18
+ }
19
+ class Komfortkasse_Order
20
+ {
21
+
22
+ private static function createInClause($arr)
23
+ {
24
+ if (!is_array($arr)) {
25
+ $arr = explode(',', $arr);
26
+ }
27
+ $tmp = array ();
28
+ foreach ($arr as $item) {
29
+ $tmp [] = str_replace('\'', '', $item);
30
+ }
31
+ return '(\'' . implode('\', \'', $tmp) . '\')';
32
+
33
+ }
34
+
35
+ /**
36
+ * Get open order IDs.
37
+ *
38
+ * @return string all order IDs that are "open" and relevant for transfer to kk
39
+ */
40
+ public static function getOpenIDs()
41
+ {
42
+ $ret = array ();
43
+
44
+ $resource = Mage::getSingleton('core/resource');
45
+ $readConnection = $resource->getConnection('core_read');
46
+ $tableOrder = $resource->getTableName('sales/order');
47
+ $tablePayment = $resource->getTableName('sales/order_payment');
48
+
49
+ foreach (Mage::app()->getWebsites() as $website) {
50
+ foreach ($website->getGroups() as $group) {
51
+ $stores = $group->getStores();
52
+ foreach ($stores as $store) {
53
+ $store_id = $store->getId();
54
+ $store_id_order = array ();
55
+ $store_id_order ['store_id'] = $store_id;
56
+
57
+ if (Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export, $store_id_order)) {
58
+
59
+ $query = 'SELECT o.increment_id FROM ' . $tableOrder . ' o join ' . $tablePayment . ' p on p.parent_id = o.entity_id where o.store_id=' . $store_id . ' and (';
60
+ $first = true;
61
+
62
+ // PREPAYMENT
63
+ $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open, $store_id_order);
64
+ $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $store_id_order);
65
+ if ($openOrders && $paymentMethods) {
66
+ if (!$first)
67
+ $query .= ' or ';
68
+ $query .= '(o.status in ' . self::createInClause($openOrders) . ' and p.method in ' . self::createInClause($paymentMethods) . ')';
69
+ $first = false;
70
+ }
71
+
72
+ // COD
73
+ $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_cod, $store_id_order);
74
+ $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_cod, $store_id_order);
75
+ if ($openOrders && $paymentMethods) {
76
+ if (!$first)
77
+ $query .= ' or ';
78
+ $query .= '(o.status in ' . self::createInClause($openOrders) . ' and p.method in ' . self::createInClause($paymentMethods) . ')';
79
+ $first = false;
80
+ }
81
+
82
+ // INVOICE
83
+ $openOrders = Komfortkasse_Config::getConfig(Komfortkasse_Config::status_open_invoice, $store_id_order);
84
+ $paymentMethods = Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods_invoice, $store_id_order);
85
+ if ($openOrders && $paymentMethods) {
86
+ if (!$first)
87
+ $query .= ' or ';
88
+ $query .= '(o.status in ' . self::createInClause($openOrders) . ' and p.method in ' . self::createInClause($paymentMethods) . ')';
89
+ $first = false;
90
+ }
91
+
92
+ $query .= ')';
93
+
94
+ $results = $readConnection->fetchAll($query);
95
+ foreach ($results as $result) {
96
+ $ret[] = $result['increment_id'];
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+ return $ret;
104
+
105
+ }
106
+
107
+ // end getOpenIDs()
108
+
109
+
110
+ /**
111
+ * Get refund IDS.
112
+ *
113
+ * @return string all refund IDs that are "open" and relevant for transfer to kk
114
+ */
115
+ public static function getRefundIDs()
116
+ {
117
+ $ret = array ();
118
+
119
+ foreach (Mage::app()->getWebsites() as $website) {
120
+ foreach ($website->getGroups() as $group) {
121
+ $stores = $group->getStores();
122
+ foreach ($stores as $store) {
123
+
124
+ $store_id = $store->getId();
125
+ $store_id_order = array ();
126
+ $store_id_order ['store_id'] = $store_id;
127
+
128
+ if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_export, $store_id_order)) {
129
+ continue;
130
+ }
131
+
132
+ $paymentMethods = explode(',', Komfortkasse_Config::getConfig(Komfortkasse_Config::payment_methods, $store_id_order));
133
+
134
+ $cmModel = Mage::getModel("sales/order_creditmemo");
135
+ $cmCollection = $cmModel->getCollection()->addFieldToFilter('store_id', $store_id);
136
+
137
+ foreach ($cmCollection as $creditMemo) {
138
+ if ($creditMemo->getTransactionId() == null) {
139
+ $order = $creditMemo->getOrder();
140
+ try {
141
+ $method = $order->getPayment()->getMethodInstance()->getCode();
142
+ } catch ( Exception $e ) {
143
+ // payment method has been deleted
144
+ $method = null;
145
+ }
146
+ if ($method && in_array($method, $paymentMethods, true) === true) {
147
+ $cmId = $creditMemo->getIncrementId();
148
+ $ret [] = $cmId;
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ return $ret;
157
+
158
+ }
159
+
160
+ // end getRefundIDs()
161
+
162
+
163
+ /**
164
+ * Get order.
165
+ *
166
+ * @param string $number order number
167
+ *
168
+ * @return array order
169
+ */
170
+ public static function getOrder($number)
171
+ {
172
+ $order = Mage::getModel('sales/order')->loadByIncrementId($number);
173
+ if (empty($number) === true || empty($order) === true || $number != $order->getIncrementId()) {
174
+ return null;
175
+ }
176
+
177
+ $conf_general = Mage::getStoreConfig('general', $order->getStoreId());
178
+
179
+ $ret = array ();
180
+ $ret ['number'] = $order->getIncrementId();
181
+ $ret ['status'] = $order->getStatus();
182
+ $ret ['date'] = date('d.m.Y', strtotime($order->getCreatedAtStoreDate()->get(Zend_Date::DATE_MEDIUM)));
183
+ $ret ['email'] = $order->getCustomerEmail();
184
+ $ret ['customer_number'] = $order->getCustomerId();
185
+ try {
186
+ $ret ['payment_method'] = $order->getPayment()->getMethodInstance()->getCode();
187
+ } catch ( Exception $e ) {
188
+ }
189
+ $ret ['amount'] = $order->getGrandTotal();
190
+ $ret ['currency_code'] = $order->getOrderCurrencyCode();
191
+ $ret ['exchange_rate'] = $order->getBaseToOrderRate();
192
+
193
+ // Rechnungsnummer und -datum
194
+ $invoiceColl = $order->getInvoiceCollection();
195
+ if ($invoiceColl->getSize() > 0) {
196
+ foreach ($order->getInvoiceCollection() as $invoice) {
197
+ $ret ['invoice_number'] [] = $invoice->getIncrementId();
198
+ $invoiceDate = date('d.m.Y', strtotime($invoice->getCreatedAt()));
199
+ if ($ret ['invoice_date'] == null || strtotime($ret ['invoice_date']) < strtotime($invoiceDate)) {
200
+ $ret ['invoice_date'] = $invoiceDate;
201
+ }
202
+ }
203
+ }
204
+
205
+ $shippingAddress = $order->getShippingAddress();
206
+ if ($shippingAddress) {
207
+ $ret ['delivery_firstname'] = utf8_encode($shippingAddress->getFirstname());
208
+ $ret ['delivery_lastname'] = utf8_encode($shippingAddress->getLastname());
209
+ $ret ['delivery_company'] = utf8_encode($shippingAddress->getCompany());
210
+ $ret ['delivery_street'] = utf8_encode($shippingAddress->getStreetFull());
211
+ $ret ['delivery_postcode'] = utf8_encode($shippingAddress->getPostcode());
212
+ $ret ['delivery_city'] = utf8_encode($shippingAddress->getCity());
213
+ $ret ['delivery_countrycode'] = utf8_encode($shippingAddress->getCountryId());
214
+ }
215
+
216
+ $billingAddress = $order->getBillingAddress();
217
+ if ($billingAddress) {
218
+ $ret ['language_code'] = substr($conf_general ['locale'] ['code'], 0, 2) . '-' . $billingAddress->getCountryId();
219
+ $ret ['billing_firstname'] = utf8_encode($billingAddress->getFirstname());
220
+ $ret ['billing_lastname'] = utf8_encode($billingAddress->getLastname());
221
+ $ret ['billing_company'] = utf8_encode($billingAddress->getCompany());
222
+ $ret ['billing_street'] = utf8_encode($billingAddress->getStreetFull());
223
+ $ret ['billing_postcode'] = utf8_encode($billingAddress->getPostcode());
224
+ $ret ['billing_city'] = utf8_encode($billingAddress->getCity());
225
+ $ret ['billing_countrycode'] = utf8_encode($billingAddress->getCountryId());
226
+ } else {
227
+ $ret ['language_code'] = substr($conf_general ['locale'] ['code'], 0, 2);
228
+ }
229
+
230
+ foreach ($order->getAllItems() as $itemId => $item) {
231
+ $sku = $item->getSku();
232
+ if ($sku) {
233
+ $ret ['products'] [] = $sku;
234
+ } else {
235
+ $ret ['products'] [] = $item->getName();
236
+ }
237
+ }
238
+
239
+ $ret ['store_id'] = $order->getStoreId();
240
+
241
+ if ($order_extension && method_exists('Komfortkasse_Order_Extension', 'extendOrder') === true) {
242
+ $ret = Komfortkasse_Order_Extension::extendOrder($order, $ret);
243
+ }
244
+
245
+ return $ret;
246
+
247
+ }
248
+
249
+ // end getOrder()
250
+
251
+
252
+ /**
253
+ * Get refund.
254
+ *
255
+ * @param string $number refund number
256
+ *
257
+ * @return array refund
258
+ */
259
+ public static function getRefund($number)
260
+ {
261
+ $resource = Mage::getSingleton('core/resource');
262
+ $id = $resource->getConnection('core_read')->fetchOne('SELECT `entity_id` FROM `' . $resource->getTableName('sales/creditmemo') . "` WHERE `increment_id` = '" . $number . "'");
263
+
264
+ $creditMemo = Mage::getModel('sales/order_creditmemo')->load($id);
265
+ if (empty($number) === true || empty($creditMemo) === true || $number != $creditMemo->getIncrementId()) {
266
+ return null;
267
+ }
268
+
269
+ $ret = array ();
270
+ $ret ['number'] = $creditMemo->getOrder()->getIncrementId();
271
+ // Number of the Creditmemo.
272
+ $ret ['customer_number'] = $creditMemo->getIncrementId();
273
+ $ret ['date'] = date('d.m.Y', strtotime($creditMemo->getCreatedAt()));
274
+ $ret ['amount'] = $creditMemo->getGrandTotal();
275
+
276
+ return $ret;
277
+
278
+ }
279
+
280
+ // end getRefund()
281
+
282
+
283
+ /**
284
+ * Update order.
285
+ *
286
+ * @param array $order order
287
+ * @param string $status status
288
+ * @param string $callbackid callback ID
289
+ *
290
+ * @return void
291
+ */
292
+ public static function updateOrder($order, $status, $callbackid)
293
+ {
294
+ if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update, $order)) {
295
+ return;
296
+ }
297
+
298
+ // Hint: PAID and CANCELLED are supported as of now.
299
+ $order = Mage::getModel('sales/order')->loadByIncrementId($order ['number']);
300
+
301
+ Mage::dispatchEvent('komfortkasse_change_order_status_before', array ('order' => $order,'status' => $status,'callbackid' => $callbackid
302
+ ));
303
+
304
+ $stateCollection = Mage::getModel('sales/order_status')->getCollection()->joinStates();
305
+ $stateCollection->addFieldToFilter('main_table.status', array ('like' => $status
306
+ ));
307
+ $state = $stateCollection->getFirstItem()->getState();
308
+
309
+ if ($state == 'processing' || $state == 'closed' || $state == 'complete') {
310
+
311
+ // If there is already an invoice, update the invoice, not the order.
312
+ $invoiceColl = $order->getInvoiceCollection();
313
+ if ($invoiceColl->getSize() > 0) {
314
+ foreach ($order->getInvoiceCollection() as $invoice) {
315
+ $invoice->pay();
316
+ $invoice->addComment($callbackid, false, false);
317
+ self::mysave($invoice);
318
+ }
319
+ } else {
320
+ $payment = $order->getPayment();
321
+ $payment->capture(null);
322
+
323
+ if ($callbackid) {
324
+ $payment->setTransactionId($callbackid);
325
+ $transaction = $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
326
+ }
327
+ }
328
+
329
+ $history = $order->addStatusHistoryComment('' . $callbackid, $status);
330
+ $order->save();
331
+ } else if ($state == 'canceled') {
332
+
333
+ if ($callbackid) {
334
+ $history = $order->addStatusHistoryComment('' . $callbackid, $status);
335
+ }
336
+ if ($order->canCancel()) {
337
+ $order->cancel();
338
+ }
339
+ $order->setStatus($status);
340
+ $order->save();
341
+ } else {
342
+
343
+ $history = $order->addStatusHistoryComment('' . $callbackid, $status);
344
+ $order->save();
345
+ }
346
+
347
+ Mage::dispatchEvent('komfortkasse_change_order_status_after', array ('order' => $order,'status' => $status,'callbackid' => $callbackid
348
+ ));
349
+
350
+ }
351
+
352
+ // end updateOrder()
353
+
354
+
355
+ /**
356
+ * Update order.
357
+ *
358
+ * @param string $refundIncrementId Increment ID of refund
359
+ * @param string $status status
360
+ * @param string $callbackid callback ID
361
+ *
362
+ * @return void
363
+ */
364
+ public static function updateRefund($refundIncrementId, $status, $callbackid)
365
+ {
366
+ $resource = Mage::getSingleton('core/resource');
367
+ $id = $resource->getConnection('core_read')->fetchOne('SELECT `entity_id` FROM `' . $resource->getTableName('sales/creditmemo') . "` WHERE `increment_id` = '" . $refundIncrementId . "'");
368
+
369
+ $creditMemo = Mage::getModel('sales/order_creditmemo')->load($id);
370
+
371
+ $store_id = $creditMemo->getStoreId();
372
+ $store_id_order = array ();
373
+ $store_id_order ['store_id'] = $store_id;
374
+
375
+ if (!Komfortkasse_Config::getConfig(Komfortkasse_Config::activate_update, $store_id_order)) {
376
+ return;
377
+ }
378
+
379
+ if ($creditMemo->getTransactionId() == null) {
380
+ $creditMemo->setTransactionId($callbackid);
381
+ }
382
+
383
+ $history = $creditMemo->addComment($status . ' [' . $callbackid . ']', false, false);
384
+
385
+ $creditMemo->save();
386
+
387
+ }
388
+
389
+ // end updateRefund()
390
+
391
+
392
+ /**
393
+ * Call an object's save method
394
+ *
395
+ * @param unknown $object
396
+ *
397
+ * @return void
398
+ */
399
+ private static function mysave($object)
400
+ {
401
+ $object->save();
402
+
403
+ }
404
+
405
+
406
+ public static function getInvoicePdfPrepare()
407
+ {
408
+
409
+ }
410
+
411
+
412
+ public static function getInvoicePdf($invoiceNumber)
413
+ {
414
+ if ($invoiceNumber && $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceNumber)) {
415
+ $fileName = $invoiceNumber . '.pdf';
416
+
417
+ $pdfGenerated = false;
418
+
419
+ // try easy pdf (www.easypdfinvoice.com)
420
+ if (!$pdfGenerated) {
421
+ $pdfProModel = Mage::getModel('pdfpro/order_invoice');
422
+ if ($pdfProModel !== false) {
423
+ $invoiceData = $pdfProModel->initInvoiceData($invoice);
424
+ $result = Mage::helper('pdfpro')->initPdf(array ($invoiceData
425
+ ));
426
+ if ($result ['success']) {
427
+ $content = $result ['content'];
428
+ $pdfGenerated = true;
429
+ }
430
+ }
431
+ }
432
+
433
+ // try Magento Standard
434
+ if (!$pdfGenerated) {
435
+ $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array ($invoice
436
+ ));
437
+ $content = $pdf->render();
438
+ }
439
+
440
+ return $content;
441
+ }
442
+
443
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  }//end class
app/code/community/Ltc/Komfortkasse/Model/Observer.php CHANGED
@@ -2,13 +2,21 @@
2
 
3
  /**
4
  * Komfortkasse
5
- * Magento2 Plugin - Observer Class
6
  *
7
- * @version 1.4.0.1-Magento2 */
8
  class Ltc_Komfortkasse_Model_Observer
9
  {
10
 
11
- private function getRegName(\Magento\Framework\Event\Observer $observer)
 
 
 
 
 
 
 
 
12
  {
13
  $id = $observer->getOrder()->getIncrementId();
14
  if ($id) {
@@ -19,7 +27,14 @@ class Ltc_Komfortkasse_Model_Observer
19
  }//end getRegName()
20
 
21
 
22
- public function noteNewOrder(\Magento\Framework\Event\Observer $observer)
 
 
 
 
 
 
 
23
  {
24
  $regName = self::getRegName($observer);
25
  if ($regName) {
@@ -29,8 +44,14 @@ class Ltc_Komfortkasse_Model_Observer
29
  }//end noteNewOrder()
30
 
31
 
32
-
33
- public function noteOrderStatus(\Magento\Framework\Event\Observer $observer)
 
 
 
 
 
 
34
  {
35
  $regName = self::getRegName($observer);
36
  if ($regName && !Mage::registry($regName)) {
@@ -40,7 +61,14 @@ class Ltc_Komfortkasse_Model_Observer
40
  }//end noteOrderStatus()
41
 
42
 
43
- public function checkOrderStatus(\Magento\Framework\Event\Observer $observer)
 
 
 
 
 
 
 
44
  {
45
  $regName = self::getRegName($observer);
46
  $orderStatus = Mage::registry($regName);
2
 
3
  /**
4
  * Komfortkasse
5
+ * Magento Plugin - Observer Class
6
  *
7
+ * @version 1.2.1.8-Magento */
8
  class Ltc_Komfortkasse_Model_Observer
9
  {
10
 
11
+
12
+ /**
13
+ * getRegName
14
+ *
15
+ * @param Varien_Event_Observer $observer Observer
16
+ *
17
+ * @return string
18
+ */
19
+ private function getRegName(Varien_Event_Observer $observer)
20
  {
21
  $id = $observer->getOrder()->getIncrementId();
22
  if ($id) {
27
  }//end getRegName()
28
 
29
 
30
+ /**
31
+ * noteNewOrder
32
+ *
33
+ * @param Varien_Event_Observer $observer Observer
34
+ *
35
+ * @return void
36
+ */
37
+ public function noteNewOrder(Varien_Event_Observer $observer)
38
  {
39
  $regName = self::getRegName($observer);
40
  if ($regName) {
44
  }//end noteNewOrder()
45
 
46
 
47
+ /**
48
+ * noteOrderStatus
49
+ *
50
+ * @param Varien_Event_Observer $observer Observer
51
+ *
52
+ * @return void
53
+ */
54
+ public function noteOrderStatus(Varien_Event_Observer $observer)
55
  {
56
  $regName = self::getRegName($observer);
57
  if ($regName && !Mage::registry($regName)) {
61
  }//end noteOrderStatus()
62
 
63
 
64
+ /**
65
+ * checkOrderStatus
66
+ *
67
+ * @param Varien_Event_Observer $observer Observer
68
+ *
69
+ * @return void
70
+ */
71
+ public function checkOrderStatus(Varien_Event_Observer $observer)
72
  {
73
  $regName = self::getRegName($observer);
74
  $orderStatus = Mage::registry($regName);
app/code/community/Ltc/Komfortkasse/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
  <config>
4
  <modules>
5
  <Ltc_Komfortkasse>
6
- <version>1.4.3.1</version>
7
  </Ltc_Komfortkasse>
8
  </modules>
9
  <global>
3
  <config>
4
  <modules>
5
  <Ltc_Komfortkasse>
6
+ <version>1.4.4</version>
7
  </Ltc_Komfortkasse>
8
  </modules>
9
  <global>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Ltc_Komfortkasse</name>
4
- <version>1.4.3.1</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>Bugfix for reading orders/refunds with payment methods that have been deleted</notes>
17
  <authors><author><name>Komfortkasse</name><user>komfortkasse</user><email>integration@komfortkasse.eu</email></author></authors>
18
- <date>2016-02-12</date>
19
- <time>07:14:20</time>
20
- <contents><target name="magecommunity"><dir name="Ltc"><dir name="Komfortkasse"><dir name="Helper"><file name="Data.php" hash="ec7f9f8fb6ea400a740ed2c127eb71bc"/><file name="Komfortkasse.php" hash="cc3e97d27237c6a1967fd78c4d6f3d13"/><file name="Komfortkasse_Config.php" hash="44cf103f0ddef60890cd6c221262b7e5"/><file name="Komfortkasse_Order.php" hash="ebb6a385e8d02cfc34c287ce15953e84"/></dir><dir name="Model"><file name="Observer.php" hash="2c12ce2b930cf734d8574e69156c7da8"/></dir><dir name="controllers"><file name="MainController.php" hash="b983fe60b2bbfa3aa1d57850cc6c045b"/></dir><dir name="etc"><file name="config.xml" hash="2a1d5ae7d86c2b89fa3c6a16fc36e84f"/><file name="system.xml" hash="c069f07b4f846e62bc5dd922c81e375b"/></dir></dir></dir><dir name="Mage"><dir name="Adminhtml"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><file name="KomfortkasseEncryptionOptions.php" hash="fea880dd3e60c13ede05be53511a6d93"/></dir></dir></dir></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.4.4</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>Bugfixes and performance improvements</notes>
17
  <authors><author><name>Komfortkasse</name><user>komfortkasse</user><email>integration@komfortkasse.eu</email></author></authors>
18
+ <date>2016-02-23</date>
19
+ <time>07:26:32</time>
20
+ <contents><target name="magecommunity"><dir name="Ltc"><dir name="Komfortkasse"><dir name="Helper"><file name="Data.php" hash="ec7f9f8fb6ea400a740ed2c127eb71bc"/><file name="Komfortkasse.php" hash="b87bacf0341fda90a98ca63b7b7faf01"/><file name="Komfortkasse_Config.php" hash="44cf103f0ddef60890cd6c221262b7e5"/><file name="Komfortkasse_Order.php" hash="5f0e709f14b8127b371cb605b6ad999a"/></dir><dir name="Model"><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="62882f4d9d6ae107d9067ba28d90b27a"/><file name="system.xml" hash="c069f07b4f846e62bc5dd922c81e375b"/></dir></dir></dir><dir name="Mage"><dir name="Adminhtml"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><file name="KomfortkasseEncryptionOptions.php" hash="fea880dd3e60c13ede05be53511a6d93"/></dir></dir></dir></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>