WCB_Database_Interface

The WooCommerce Billogram Integration WCB Database Interface class.

Defined (1)

The class is defined in the following location(s).

/class-billogram2-database-interface.php  
  1. class WCB_Database_Interface{ 
  2.  
  3. /** 
  4. */ 
  5. function __construct() { 
  6.  
  7. /** 
  8. * Creates a n XML representation of a n Order 
  9. * @access public 
  10. * @internal param mixed $arr 
  11. * @return mixed 
  12. */ 
  13. public function read_unsynced_orders() { 
  14. global $wpdb; 
  15. return $wpdb->get_results("SELECT * from wcb_orders WHERE synced = 0"); 
  16.  
  17. /** 
  18. * Creates a n XML representation of a n Order 
  19. * @access public 
  20. * @internal param mixed $arr 
  21. * @return bool 
  22. */ 
  23. public function is_synced_order($id = NULL) { 
  24. global $wpdb; 
  25. if($id) { 
  26. $order = $wpdb->get_results("SELECT * from wcb_orders WHERE synced = 1 AND order_id = ".$id, ARRAY_A); 
  27. logthis("is_synced_order"); 
  28. if(!empty($order)) { 
  29. return true; 
  30. }else{ 
  31. return false; 
  32. else{ 
  33.  
  34.  
  35. /** 
  36. * Sets an order to synced 
  37. * @access public 
  38. * @param int $orderId 
  39. * @return bool 
  40. */ 
  41. public function set_as_synced($orderId) { 
  42. global $wpdb; 
  43. $wpdb->query("UPDATE wcb_orders SET synced = 1 WHERE order_id = ".$orderId); 
  44. return true; 
  45.  
  46.  
  47. /** 
  48. * Sets an subscription order to synced 
  49. * @access public 
  50. * @param int $orderId 
  51. * @return bool 
  52. */ 
  53. public function set_as_synced_subscription($orderId) { 
  54. global $wpdb; 
  55. $wpdb->query("UPDATE wcb_orders SET synced = 1 WHERE order_id = ".$orderId." AND invoice_id = 0 AND invoice_no = 0 AND ocr_number = 0"); 
  56. return true; 
  57.  
  58.  
  59. /** 
  60. * Sets an Product SKU 
  61. * @access public 
  62. * @param int $orderId 
  63. * @return bool 
  64. */ 
  65. public function set_product_sku($productId, $sku) { 
  66. global $wpdb; 
  67. $wpdb->query("INSERT INTO wcb_products VALUES (NULL, ".$productId.", '".$sku."')"); 
  68. return true; 
  69.  
  70.  
  71. /** 
  72. * Writes an update product SKU in database 
  73. * @access public 
  74. * @param $customerId 
  75. * @param $customerNumber 
  76. * @return bool 
  77. */ 
  78. public function update_product_sku($productId, $sku) { 
  79. global $wpdb; 
  80. $wpdb->query("UPDATE wcb_products SET product_sku = '". $sku ."' WHERE product_id = ".$productId); 
  81. return true; 
  82.  
  83. /** 
  84. * get an Product SKU 
  85. * @access public 
  86. * @param int $orderId 
  87. * @return bool 
  88. */ 
  89. public function get_product_sku($productId) { 
  90. global $wpdb; 
  91. return $wpdb->get_results("SELECT * from wcb_products WHERE product_id = '". $productId ."'"); 
  92.  
  93.  
  94. /** 
  95. * Writes an unsynced order to the database 
  96. * @access public 
  97. * @param int $orderId 
  98. * @return bool 
  99. */ 
  100. public function create_unsynced_order($orderId) { 
  101. global $wpdb; 
  102. $wpdb->query("INSERT INTO wcb_orders VALUES (NULL, ".$orderId.", '', 0, 0, 0)"); 
  103. return true; 
  104.  
  105. /** 
  106. * Creates a customer 
  107. * @access public 
  108. * @param $email 
  109. * @return bool 
  110. */ 
  111. public function create_customer($email) { 
  112. global $wpdb; 
  113. $wpdb->query("INSERT INTO wcb_customers VALUES (NULL, 0, '".$email."')"); 
  114. return $wpdb->insert_id; 
  115.  
  116. /** 
  117. * Creates a customer 
  118. * @access public 
  119. * @param $customer 
  120. * @return bool 
  121. */ 
  122. public function create_existing_customer($customer) { 
  123. global $wpdb; 
  124. if(!$customer->customer_no) { 
  125. return; 
  126. if($customer->contact->email && $customer->customer_no) { 
  127.  
  128. $wpdb->query("INSERT INTO wcb_customers VALUES (NULL, '".$customer->customer_no."', '".$customer->contact->email."')"); 
  129. return $wpdb->insert_id; 
  130.  
  131.  
  132. /** 
  133. * Gets customer by email 
  134. * @access public 
  135. * @param $email 
  136. * @return bool 
  137. */ 
  138. public function get_customer_by_email($email) { 
  139. global $wpdb; 
  140. return $wpdb->get_results("SELECT * from wcb_customers WHERE email = '". $email ."'"); 
  141.  
  142. /** 
  143. * Writes an unsynced order to the database 
  144. * @access public 
  145. * @param $customerId 
  146. * @param $customerNumber 
  147. * @return bool 
  148. */ 
  149. public function update_customer($customerId, $customerNumber) { 
  150. global $wpdb; 
  151. $wpdb->query("UPDATE wcb_customers SET customer_number = '". $customerNumber ."' WHERE id = ".$customerId); 
  152. return true; 
  153.  
  154. public function reset_database() { 
  155. global $wpdb; 
  156. $wpdb->query("DELETE FROM wcb_customers;"); 
  157. return true;