PageRenderTime 73ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/opensourcepos/application/controllers/impex.php

https://bitbucket.org/jit_bec/shopifine
PHP | 134 lines | 87 code | 30 blank | 17 comment | 2 complexity | 38f5720daff6877ecce7fc17ae3e0226 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /*
  3. * To change this template, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. /**
  7. * Description of users
  8. *
  9. * @author abhijit
  10. */
  11. require_once ("secure_area.php");
  12. class Impex extends Secure_area {
  13. function __construct()
  14. {
  15. parent::__construct('impex','adminmenu');
  16. }
  17. function index(){
  18. }
  19. public function importAttributeSets (){
  20. $status = $this->Attribute_set->importAttributeSets();
  21. log_message('debug', 'status of Attribute set import '.$status);
  22. }
  23. public function importCategories(){
  24. $status = $this->Category->importCategories();
  25. log_message('debug', 'status of category import '.$status);
  26. }
  27. public function importInvoices(){
  28. $status ="invoiced";
  29. $this->db->trans_start();
  30. $magentoInvoices = $this->Invoice_master->getUnprocessedInvoicesFromMagento();
  31. //first make an entry in invoice master
  32. //if (!$this->Invoice_master->exists($invoiceId)) { //insert
  33. foreach ($magentoInvoices as $inv){
  34. $inv_entity_id = $inv['entity_id'];
  35. $inv_increment_id = $inv['invoice_increment_id'];
  36. $order_id = $inv['order_id'];
  37. $order_increment_id = $inv['order_increment_id'];
  38. $inv_data = array
  39. (
  40. 'magento_invoice_increment_id'=>$inv_increment_id,
  41. 'magento_invoice_entity_id'=>$inv_entity_id,
  42. 'magento_order_increment_id'=>$order_increment_id,
  43. 'magento_order_id'=>$order_id,
  44. 'status'=>$status,
  45. 'created_at'=>date('Y-m-d H:i:s')
  46. );
  47. $this->Invoice_master->insert($inv_data);
  48. }
  49. $items = $this->Invoice_item->getUnprocessedInvoiceItemsFromMagento();
  50. foreach ($items as $item){
  51. $magento_entity_id = $item['entity_id'];
  52. $inv_entity_id = $item['parent_id'];
  53. $inv_increment_id = $item['increment_id'];
  54. $product_id = $item['product_id'];
  55. $type = $item['type_id'];
  56. $sku= $item['sku'];
  57. $name = $item['name'];
  58. $qty = $item['qty'];
  59. $inv_item_data = array
  60. (
  61. 'magento_entity_id'=>$magento_entity_id,
  62. 'magento_invoice_entity_id'=>$inv_entity_id,
  63. 'invoice_id' =>$inv_increment_id,
  64. 'sku'=>$sku,
  65. 'name'=>$name,
  66. 'type'=>$type,
  67. 'magento_product_id'=>$product_id,
  68. 'invoiced_number'=>$qty,
  69. 'created_at'=>date('Y-m-d H:i:s'),
  70. );
  71. $this->Invoice_item->insert($inv_item_data);
  72. }
  73. $this->db->trans_complete();
  74. if ($this->db->trans_status() === FALSE)
  75. {
  76. //echo $this->db->_error_message();
  77. //die( 'Transaction Failed while inserting invoice records. Please check log');
  78. }
  79. }
  80. function exportProductsMagmi (){
  81. $error = false;
  82. $result = $this->Product->getMagentoExportView();
  83. $resource = $this->Resource->getByResourceName('exportdir-impexconfig');
  84. $filename = $resource['relative_path_link'] . $this->Appconfig->get('create_product_file');
  85. // $filename = $result['relative_path_link'];
  86. $this->load->helper('file');
  87. //var_dump(($result));
  88. //delete_files($filename);
  89. //delete_files($filename);
  90. if ( ! write_file($filename,$result ,'w+'))
  91. {
  92. $error = true;
  93. }
  94. $data['mode'] = $this->Appconfig->get('create_product_mode');
  95. $data['profile'] = $this->Appconfig->get('create_product_profile');
  96. $data['filename'] = $filename;
  97. $data['error'] = $error;
  98. $this->load->view('impex/process_magento',$data);
  99. }
  100. function dbprefix (){
  101. var_dump ($this->db->dbprefix);
  102. }
  103. }
  104. ?>