Qinvoice_Connect - Version 1.1.1

Version Notes

Compatible with v1.9 and 1.8
Support for bundled products

Download this release

Release Info

Developer Casper Mekel
Extension Qinvoice_Connect
Version 1.1.1
Comparing to
See all releases


Code changes from version 1.1.0 to 1.1.1

app/code/community/Qinvoice/Connect/Model/Order/Observer.php CHANGED
@@ -11,9 +11,7 @@ class Qinvoice_Connect_Model_Order_Observer
11
  return false;
12
  $order = $observer->getEvent()->getOrder();
13
 
14
-
15
- // print_r($order);
16
- //die();
17
 
18
  // GETTING TRIGGER SETTING
19
  $db = Mage::getSingleton('core/resource')->getConnection('core_write');
@@ -23,9 +21,6 @@ class Qinvoice_Connect_Model_Order_Observer
23
  $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
24
  $varOnOrder = $rowTwo['value'];
25
 
26
-
27
- mail('caspermekel@gmail.com','MAGE191','sendOnComplete '. $varOnOrder );
28
-
29
  if($varOnOrder == 'complete' && $order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE){
30
  $this->createInvoiceForQinvoice($order->getId(), false);
31
  }else{
@@ -37,10 +32,6 @@ class Qinvoice_Connect_Model_Order_Observer
37
  return false;
38
  $shipment = $observer->getEvent()->getShipment();
39
 
40
- mail('caspermekel@gmail.com','MAGE191','sendOnShip');
41
- print_r($order);
42
- die();
43
-
44
  $order = $shipment->getOrder();
45
 
46
  // GETTING TRIGGER SETTING
@@ -75,11 +66,7 @@ class Qinvoice_Connect_Model_Order_Observer
75
  return true;
76
  }
77
  }
78
- /**
79
- * Exports new orders to an xml file
80
- * @param Varien_Event_Observer $observer
81
- * @return Feed_Sales_Model_Order_Observer
82
- */
83
  public function sendOnPayment($observer){
84
  // Gets called even when other payment method is choosen.
85
 
@@ -102,6 +89,8 @@ class Qinvoice_Connect_Model_Order_Observer
102
  }
103
  public function createInvoiceForQinvoice($varOrderID,$ifPaid = false)
104
  {
 
 
105
  $paid = 0;
106
  $db = Mage::getSingleton('core/resource')->getConnection('core_write');
107
  // GETTING ORDER ID
@@ -225,6 +214,7 @@ class Qinvoice_Connect_Model_Order_Observer
225
  $resultRemark = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varRemarkPath."'");
226
  $rowRemark = $resultRemark->fetch(PDO::FETCH_ASSOC);
227
 
 
228
  $invoice_remark = $rowRemark['value'];
229
  $invoice_remark = str_replace('{order_id}',$rowOne['increment_id'],$invoice_remark);
230
  $invoice_remark = str_replace('{shipping_description}',$rowOne['shipping_description'],$invoice_remark);
@@ -287,6 +277,11 @@ class Qinvoice_Connect_Model_Order_Observer
287
  // $invoice->addTag('send: '. $send_mail);
288
  // $invoice->addTag('paid: '. $paid .' '. $rowOne['total_paid']);
289
 
 
 
 
 
 
290
  $attributes = Mage::getResourceModel('catalog/product_attribute_collection')->addVisibleFilter();
291
  $attributeArray = array();
292
 
@@ -297,135 +292,135 @@ class Qinvoice_Connect_Model_Order_Observer
297
  // 'value' => $attribute->getData('attribute_code')
298
  // );
299
  }
 
 
300
 
301
 
302
- for($i=0;$i<count($arrData);$i++)
303
- {
304
- $category = '';
305
- $_productId = $arrData[$i]['product_id'];
306
- $_product = Mage::getModel('catalog/product')->load($_productId);
307
- $category = $_product->getData('qinvoice_category');
308
- $productcode = $_product->getData('qinvoice_productcode');
309
-
310
- $arrItemOptions = unserialize($arrData[$i]['product_options']);
311
-
312
- $varDescription = '';
313
-
314
- //print_r();
315
-
316
- $product_attributes = explode(",",$pa_array['value']);
317
- foreach($product_attributes as $pa){
318
- if(isset($_product[$pa]))
319
- {
320
- $varDescription .= "\n". $attributeArray[$pa] .': '. $_product[$pa];
321
- }
 
322
  }
 
323
 
324
-
325
- if(@$arrItemOptions['options'])
 
 
326
  {
327
- for($k=0; $k <count($arrItemOptions['options']); $k++)
328
- {
329
- $varDescription .= "\n".$arrItemOptions['options'][$k]['label'].": ".$arrItemOptions['options'][$k]['print_value']."\n";
330
- }
331
  }
332
-
333
- if(@$arrItemOptions['attributes_info'])
 
 
 
334
  {
335
- for($k=0; $k <count($arrItemOptions['attributes_info']); $k++)
336
- {
337
- $varDescription .= "\n".$arrItemOptions['attributes_info'][$k]['label'].": ".$arrItemOptions['attributes_info'][$k]['value']."\n";
338
- }
339
  }
 
340
 
 
 
 
 
 
 
 
 
341
 
342
- //echo $varDescription;
343
 
 
 
344
 
345
- // else
346
- // {
347
- // $varDescription = ''; //"[".$arrData[$i]['sku']."] ".trim($arrData[$i]['name']);
348
- // }
349
- // print_r($_product);
350
- // echo '<pre>';
351
- // print_r( $arrItemOptions );
352
- // echo '</pre>';
353
-
 
 
 
 
 
 
354
 
355
-
356
- $params = array(
357
- 'code' => $productcode,
358
- 'description' => "[".$arrData[$i]['sku']."] ".trim($arrData[$i]['name']) . $varDescription,
359
- 'price' => $arrData[$i]['base_price']*100,
360
- //'price_incl' => ((($arrData[$i]['base_price']*$arrData[$i]['qty_ordered'])+$arrData[$i]['tax_amount'])/$arrData[$i]['qty_ordered'])*100,
361
- 'price_incl' => round(((($arrData[$i]['base_price']*$arrData[$i]['qty_ordered'])+$arrData[$i]['tax_amount'])/$arrData[$i]['qty_ordered'])*100),
362
- 'price_vat' => ($arrData[$i]['tax_amount']/$arrData[$i]['qty_ordered'])*100,
363
- 'vatpercentage' => trim(number_format($arrData[$i]['tax_percent'],2,'.', ''))*100,
364
- 'discount' => trim(number_format($arrData[$i]['base_discount_amount'], 2, '.', '')/$arrData[$i]['base_price'])*100,
365
- 'quantity' => $arrData[$i]['qty_ordered']*100,
366
- 'categories' => $category
367
- );
368
- //mail('casper@expertnetwork.nl', 'vat', $arrData[$i]['tax_percent']);
369
-
370
- // echo '<pre>';
371
- // print_r( $params );
372
- // echo '</pre>';
373
- // die();
374
- $invoice->addItem($params);
375
 
376
- }
377
- if($rowOne['shipping_amount'] > 0)
378
- {
379
- $params = array(
380
- 'code' => '',
381
- 'description' => trim($rowOne['shipping_description']),
382
- 'price' => $rowOne['shipping_amount']*100,
383
- 'price_incl' => $rowOne['shipping_incl_tax']*100,
384
- 'price_vat' => $rowOne['shipping_tax_amount']*100,
385
- 'vatpercentage' => round(($rowOne['shipping_tax_amount']/$rowOne['shipping_amount'])*100)*100,
386
- 'discount' => 0,
387
- 'quantity' => 100,
388
- 'categories' => 'shipping'
389
- );
390
-
391
- $invoice->addItem($params);
392
-
393
- }
394
 
395
 
396
 
397
-
398
- $result = $invoice->sendRequest();
399
- if($result == 1){
400
- //notify_to_admin('Casper Mekel','casper@newday.sk','Invoice generated!');
401
- }else{
402
- //notify_to_admin('Casper Mekel','casper@newday.sk','Something went wrong!');
403
- }
404
-
405
- return true;
406
 
407
 
408
  //$curlInvoiveResult = $this->sendCurlRequest($createInvoiceXML);
409
  }
410
-
411
- public function notify_to_admin($name, $email, $msg)
412
  {
413
  $varSubject = 'Qinvoice Notification';
414
 
415
- //Mage::log($msg);
416
-
417
  $mail = Mage::getModel('core/email');
418
- $mail->setToName($name);
419
- $mail->setToEmail($email);
420
  $mail->setBody($msg);
421
- $mail->setSubject($varSubject);
422
  $mail->setFromEmail("support@qinvoice.com");
423
- $mail->setFromName("Qinvoice Development");
424
  $mail->setType('text');
425
  $mail->send();
426
  }
 
427
  }
428
 
 
 
 
429
  class qinvoice{
430
 
431
  protected $gateway = '';
11
  return false;
12
  $order = $observer->getEvent()->getOrder();
13
 
14
+
 
 
15
 
16
  // GETTING TRIGGER SETTING
17
  $db = Mage::getSingleton('core/resource')->getConnection('core_write');
21
  $rowTwo = $resultTwo->fetch(PDO::FETCH_ASSOC);
22
  $varOnOrder = $rowTwo['value'];
23
 
 
 
 
24
  if($varOnOrder == 'complete' && $order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE){
25
  $this->createInvoiceForQinvoice($order->getId(), false);
26
  }else{
32
  return false;
33
  $shipment = $observer->getEvent()->getShipment();
34
 
 
 
 
 
35
  $order = $shipment->getOrder();
36
 
37
  // GETTING TRIGGER SETTING
66
  return true;
67
  }
68
  }
69
+
 
 
 
 
70
  public function sendOnPayment($observer){
71
  // Gets called even when other payment method is choosen.
72
 
89
  }
90
  public function createInvoiceForQinvoice($varOrderID,$ifPaid = false)
91
  {
92
+
93
+
94
  $paid = 0;
95
  $db = Mage::getSingleton('core/resource')->getConnection('core_write');
96
  // GETTING ORDER ID
214
  $resultRemark = $db->query("SELECT value FROM {$prefix}core_config_data WHERE path LIKE '".$varRemarkPath."'");
215
  $rowRemark = $resultRemark->fetch(PDO::FETCH_ASSOC);
216
 
217
+ $order_id = $rowOne['increment_id'];
218
  $invoice_remark = $rowRemark['value'];
219
  $invoice_remark = str_replace('{order_id}',$rowOne['increment_id'],$invoice_remark);
220
  $invoice_remark = str_replace('{shipping_description}',$rowOne['shipping_description'],$invoice_remark);
277
  // $invoice->addTag('send: '. $send_mail);
278
  // $invoice->addTag('paid: '. $paid .' '. $rowOne['total_paid']);
279
 
280
+
281
+ $order = Mage::getModel('sales/order')->loadByIncrementId($varOrderID);
282
+ $store_id = $order->getStoreId();
283
+
284
+
285
  $attributes = Mage::getResourceModel('catalog/product_attribute_collection')->addVisibleFilter();
286
  $attributeArray = array();
287
 
292
  // 'value' => $attribute->getData('attribute_code')
293
  // );
294
  }
295
+
296
+
297
 
298
 
299
+ for($i=0;$i<count($arrData);$i++)
300
+ {
301
+ $category = '';
302
+ $_productId = $arrData[$i]['product_id'];
303
+ $_product = Mage::getModel('catalog/product')->load($_productId);
304
+
305
+
306
+ $category = $_product->getData('qinvoice_category');
307
+ $productcode = $_product->getData('qinvoice_productcode');
308
+
309
+ $arrItemOptions = unserialize($arrData[$i]['product_options']);
310
+
311
+ $varDescription = '';
312
+
313
+ //print_r();
314
+
315
+ $product_attributes = explode(",",$pa_array['value']);
316
+ foreach($product_attributes as $pa){
317
+ if(isset($_product[$pa]))
318
+ {
319
+ $varDescription .= "\n". $attributeArray[$pa] .': '. $_product[$pa];
320
  }
321
+ }
322
 
323
+
324
+ if(@$arrItemOptions['options'])
325
+ {
326
+ for($k=0; $k <count($arrItemOptions['options']); $k++)
327
  {
328
+ $varDescription .= "\n".$arrItemOptions['options'][$k]['label'].": ".$arrItemOptions['options'][$k]['print_value']."\n";
 
 
 
329
  }
330
+ }
331
+
332
+ if(@$arrItemOptions['attributes_info'])
333
+ {
334
+ for($k=0; $k <count($arrItemOptions['attributes_info']); $k++)
335
  {
336
+ $varDescription .= "\n".$arrItemOptions['attributes_info'][$k]['label'].": ".$arrItemOptions['attributes_info'][$k]['value']."\n";
 
 
 
337
  }
338
+ }
339
 
340
+ if(@$arrItemOptions['bundle_options'])
341
+ {
342
+ foreach($arrItemOptions['bundle_options'] as $option){
343
+ foreach($option['value'] as $value){
344
+ $varDescription .= "\n".'['. $option['label'] .'] '. $value['qty'] .' x '. $value['title'];
345
+ }
346
+ }
347
+ }
348
 
 
349
 
350
+
351
+
352
 
353
+
354
+ $params = array(
355
+ 'code' => $productcode,
356
+ 'description' => "[".$arrData[$i]['sku']."] ".trim($arrData[$i]['name']) . $varDescription,
357
+ 'price' => $arrData[$i]['base_price']*100,
358
+ //'price_incl' => ((($arrData[$i]['base_price']*$arrData[$i]['qty_ordered'])+$arrData[$i]['tax_amount'])/$arrData[$i]['qty_ordered'])*100,
359
+ 'price_incl' => round(((($arrData[$i]['base_price']*$arrData[$i]['qty_ordered'])+$arrData[$i]['tax_amount'])/$arrData[$i]['qty_ordered'])*100),
360
+ 'price_vat' => ($arrData[$i]['tax_amount']/$arrData[$i]['qty_ordered'])*100,
361
+ 'vatpercentage' => trim(number_format($arrData[$i]['tax_percent'],2,'.', ''))*100,
362
+ 'discount' => trim(number_format($arrData[$i]['base_discount_amount'], 2, '.', '')/$arrData[$i]['base_price'])*100,
363
+ 'quantity' => $arrData[$i]['qty_ordered']*100,
364
+ 'categories' => $category
365
+ );
366
+
367
+ $invoice->addItem($params);
368
 
369
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
 
371
+ if($rowOne['shipping_amount'] > 0)
372
+ {
373
+ $params = array(
374
+ 'code' => '',
375
+ 'description' => trim($rowOne['shipping_description']),
376
+ 'price' => $rowOne['shipping_amount']*100,
377
+ 'price_incl' => $rowOne['shipping_incl_tax']*100,
378
+ 'price_vat' => $rowOne['shipping_tax_amount']*100,
379
+ 'vatpercentage' => round(($rowOne['shipping_tax_amount']/$rowOne['shipping_amount'])*100)*100,
380
+ 'discount' => 0,
381
+ 'quantity' => 100,
382
+ 'categories' => 'shipping'
383
+ );
384
+
385
+ $invoice->addItem($params);
386
+
387
+ }
 
388
 
389
 
390
 
391
+
392
+ $result = $invoice->sendRequest();
393
+ if($result != 1){
394
+ $this->notify_admin('Qinvoice Connect Error','Could not send invoice for order '. $order_id);
395
+ }
396
+
397
+ return true;
 
 
398
 
399
 
400
  //$curlInvoiveResult = $this->sendCurlRequest($createInvoiceXML);
401
  }
402
+ public function notify_admin($subject,$msg)
 
403
  {
404
  $varSubject = 'Qinvoice Notification';
405
 
406
+ Mage::log($subject .': '. $msg);
407
+
408
  $mail = Mage::getModel('core/email');
409
+ $mail->setToName(Mage::getStoreConfig('trans_email/ident_general/name') );
410
+ $mail->setToEmail(Mage::getStoreConfig('trans_email/ident_general/email') );
411
  $mail->setBody($msg);
412
+ $mail->setSubject($subject);
413
  $mail->setFromEmail("support@qinvoice.com");
414
+ $mail->setFromName("Qinvoice Support");
415
  $mail->setType('text');
416
  $mail->send();
417
  }
418
+
419
  }
420
 
421
+
422
+
423
+
424
  class qinvoice{
425
 
426
  protected $gateway = '';
app/code/community/Qinvoice/Connect/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
  <config>
4
  <modules>
5
  <Qinvoice_Connect>
6
- <version>1.1.0</version>
7
  </Qinvoice_Connect>
8
  </modules>
9
  <global>
@@ -13,23 +13,23 @@
13
  </invoice>
14
  </models>
15
  <events>
16
- <sales_order_place_after>
17
  <observers>
18
  <connect>
19
  <class>invoice/order_observer</class>
20
  <method>sendOnOrder</method>
21
  </connect>
22
  </observers>
23
- </sales_order_place_after>
24
 
25
- <sales_order_payment_pay>
26
  <observers>
27
  <connect>
28
  <class>invoice/order_observer</class>
29
  <method>sendOnPayment</method>
30
  </connect>
31
  </observers>
32
- </sales_order_payment_pay>
33
  </events>
34
  <helpers>
35
  <invoice>
3
  <config>
4
  <modules>
5
  <Qinvoice_Connect>
6
+ <version>1.1.1</version>
7
  </Qinvoice_Connect>
8
  </modules>
9
  <global>
13
  </invoice>
14
  </models>
15
  <events>
16
+ <sales_order_invoice_register>
17
  <observers>
18
  <connect>
19
  <class>invoice/order_observer</class>
20
  <method>sendOnOrder</method>
21
  </connect>
22
  </observers>
23
+ </sales_order_invoice_register>
24
 
25
+ <sales_order_invoice_pay>
26
  <observers>
27
  <connect>
28
  <class>invoice/order_observer</class>
29
  <method>sendOnPayment</method>
30
  </connect>
31
  </observers>
32
+ </sales_order_invoice_pay>
33
  </events>
34
  <helpers>
35
  <invoice>
package.xml CHANGED
@@ -1,18 +1,19 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Qinvoice_Connect</name>
4
- <version>1.1.0</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Automatically generate and send PDF invoices for every order to your customers through q-invoice.com</summary>
10
  <description>Invoices can be generated upon a successful payment or order and will be added to your administration. Q-invoice offers you the freedom to run multiple webshops or venues but still have your bookkeeping together at one place. Generate invoices in a layout of your choosing for maximal recognition, upload bankstatements and process payment with the click of your mouse. www.q-invoice.com</description>
11
- <notes>Compatible with v1.9.1</notes>
 
12
  <authors><author><name>Casper Mekel</name><user>caspermekel</user><email>info@q-invoice.com</email></author></authors>
13
- <date>2014-11-10</date>
14
- <time>16:22:54</time>
15
- <contents><target name="magecommunity"><dir name="Qinvoice"><file name="CHANGELOG" hash="fe63e41117f38a39736c3354a7b1d11d"/><dir name="Connect"><dir name="etc"><file name="config.xml" hash="c6d5f3ebe9fef8eae4641627488e4a77"/><file name="system.xml" hash="0f7c10edfb8942199b277a0170babe30"/></dir><dir name="Helper"><file name="Data.php" hash="ccb4b09674319e8b20e9c06a94adfa38"/></dir><dir name="Model"><dir name="Order"><file name="Observer.Boerdereike.php" hash="8ecdeaa4e9a41de7d5debfaf22967761"/><file name="Observer.php" hash="d02a784a89e10ef46a226a66b79cbd5c"/></dir><dir name="Source"><file name="Attribute.php" hash="72f35ffb8cd873d2c5e1e448ff4bf4e2"/><file name="Invoice.php" hash="4661f369f7e116fd761e5fffac9efeaf"/><file name="Method.php" hash="ac6891fc7e403250b24f5b0f2d6199bc"/><file name="Relation.php" hash="89ab031937b846ab5f0bcac7ccaa31b7"/><file name="Trigger.php" hash="be2c0e4bfc32c0bdd57b4b1b58da8d63"/></dir></dir><file name="readme.txt" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Qinvoice_Connect.xml" hash="fbedefa4e926092705c6941ad28f51f8"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><extension><name>curl</name><min>5.1</min><max>6.0</max></extension></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Qinvoice_Connect</name>
4
+ <version>1.1.1</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Automatically generate and send PDF invoices for every order to your customers through q-invoice.com</summary>
10
  <description>Invoices can be generated upon a successful payment or order and will be added to your administration. Q-invoice offers you the freedom to run multiple webshops or venues but still have your bookkeeping together at one place. Generate invoices in a layout of your choosing for maximal recognition, upload bankstatements and process payment with the click of your mouse. www.q-invoice.com</description>
11
+ <notes>Compatible with v1.9 and 1.8&#xD;
12
+ Support for bundled products</notes>
13
  <authors><author><name>Casper Mekel</name><user>caspermekel</user><email>info@q-invoice.com</email></author></authors>
14
+ <date>2014-11-14</date>
15
+ <time>11:06:48</time>
16
+ <contents><target name="magecommunity"><dir name="Qinvoice"><file name="CHANGELOG" hash="fe63e41117f38a39736c3354a7b1d11d"/><dir name="Connect"><dir name="Helper"><file name="Data.php" hash="ccb4b09674319e8b20e9c06a94adfa38"/></dir><dir name="Model"><dir name="Order"><file name="Observer.Boerdereike.php" hash="8ecdeaa4e9a41de7d5debfaf22967761"/><file name="Observer.php" hash="56c978beaeded1e98c65bfdf05554703"/></dir><dir name="Source"><file name="Attribute.php" hash="72f35ffb8cd873d2c5e1e448ff4bf4e2"/><file name="Invoice.php" hash="4661f369f7e116fd761e5fffac9efeaf"/><file name="Method.php" hash="ac6891fc7e403250b24f5b0f2d6199bc"/><file name="Relation.php" hash="89ab031937b846ab5f0bcac7ccaa31b7"/><file name="Trigger.php" hash="be2c0e4bfc32c0bdd57b4b1b58da8d63"/></dir></dir><dir name="etc"><file name="config.xml" hash="2c0d57f3c6a0b7874d8263e268dbc4c6"/><file name="system.xml" hash="0f7c10edfb8942199b277a0170babe30"/></dir><file name="readme.txt" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Qinvoice_Connect.xml" hash="fbedefa4e926092705c6941ad28f51f8"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><extension><name>curl</name><min>5.1</min><max>6.0</max></extension></required></dependencies>
19
  </package>