WC_PS_Product_SKU_Data

"Copyright 2012 A3 Revolution Web Design" This software is distributed under the terms of GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007.

Defined (1)

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

/classes/data/class-wc-ps-product-sku-data.php  
  1. class WC_PS_Product_SKU_Data 
  2. public function install_database() { 
  3. global $wpdb; 
  4. $collate = ''; 
  5. if ( $wpdb->has_cap( 'collation' ) ) { 
  6. if( ! empty($wpdb->charset ) ) $collate .= "DEFAULT CHARACTER SET $wpdb->charset"; 
  7. if( ! empty($wpdb->collate ) ) $collate .= " COLLATE $wpdb->collate"; 
  8.  
  9. require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 
  10.  
  11. $table_ps_product_sku = $wpdb->prefix. "ps_product_sku"; 
  12.  
  13. if ($wpdb->get_var("SHOW TABLES LIKE '$table_ps_product_sku'") != $table_ps_product_sku) { 
  14. $sql = "CREATE TABLE IF NOT EXISTS `{$table_ps_product_sku}` ( 
  15. post_id bigint(20) NOT NULL,  
  16. sku text NULL,  
  17. post_parent bigint(20) NOT NULL DEFAULT 0,  
  18. PRIMARY KEY (post_id),  
  19. KEY post_parent (post_parent) 
  20. ) $collate; "; 
  21.  
  22. $wpdb->query($sql); 
  23.  
  24.  
  25. /** 
  26. * Predictive Search Product SKU Table - set table name 
  27. * @return void 
  28. */ 
  29. public function set_table_wpdbfix() { 
  30. global $wpdb; 
  31. $meta_name = 'ps_product_sku'; 
  32.  
  33. $wpdb->ps_product_sku = $wpdb->prefix . $meta_name; 
  34.  
  35. $wpdb->tables[] = 'ps_product_sku'; 
  36.  
  37. /** 
  38. * Insert Predictive Search Product SKU 
  39. */ 
  40. public function insert_item( $post_id, $sku = '', $post_parent = 0 ) { 
  41. global $wpdb; 
  42. return $wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->ps_product_sku} VALUES(%d, %s, %d)", $post_id, stripslashes( $sku ), $post_parent ) ); 
  43.  
  44. /** 
  45. * Update Predictive Search Product SKU 
  46. */ 
  47. public function update_item( $post_id, $sku = '', $post_parent = 0 ) { 
  48. global $wpdb; 
  49.  
  50. $value = $this->is_item_existed( $post_id ); 
  51. if ( '0' == $value ) { 
  52. return $this->insert_item( $post_id, $sku, $post_parent ); 
  53. } else { 
  54. return $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->ps_product_sku} SET sku = %s WHERE post_id = %d ", stripslashes( $sku ), $post_id ) ); 
  55.  
  56. /** 
  57. * Get Predictive Search Product SKU 
  58. */ 
  59. public function get_item( $post_id ) { 
  60. global $wpdb; 
  61. return $wpdb->get_var( $wpdb->prepare( "SELECT sku FROM {$wpdb->ps_product_sku} WHERE post_id = %d LIMIT 0, 1 ", $post_id ) ); 
  62.  
  63. /** 
  64. * Check Predictive Search Product SKU Existed 
  65. */ 
  66. public function is_item_existed( $post_id ) { 
  67. global $wpdb; 
  68. return $wpdb->get_var( $wpdb->prepare( "SELECT EXISTS( SELECT 1 FROM {$wpdb->ps_product_sku} WHERE post_id = %d LIMIT 0, 1 )", $post_id ) ); 
  69.  
  70. /** 
  71. * Get Predictive Search Latest Post ID 
  72. */ 
  73. public function get_latest_post_id() { 
  74. global $wpdb; 
  75.  
  76. return $wpdb->get_var( "SELECT post_id FROM {$wpdb->ps_product_sku} ORDER BY post_id DESC LIMIT 0, 1" ); 
  77.  
  78. /** 
  79. * Check Latest Post ID is newest from WP database 
  80. */ 
  81. public function is_newest_id() { 
  82. global $wpdb; 
  83.  
  84. $post_types = array( 'product' ); 
  85.  
  86. $latest_id = $this->get_latest_post_id(); 
  87. if ( empty( $latest_id ) || is_null( $latest_id ) ) { 
  88. $latest_id = 0; 
  89.  
  90. $is_not_newest = $wpdb->get_var( 
  91. $wpdb->prepare( 
  92. "SELECT EXISTS( SELECT 1 FROM {$wpdb->posts} WHERE ID > %d AND post_type IN ('". implode("', '", $post_types ) ."') AND post_status = %s LIMIT 0, 1 )",  
  93. $latest_id,  
  94. 'publish' 
  95. ); 
  96.  
  97. if ( '1' != $is_not_newest ) { 
  98. return true; 
  99.  
  100. return false; 
  101.  
  102. /** 
  103. * Get Total Items Synched 
  104. */ 
  105. public function get_total_items_synched() { 
  106. global $wpdb; 
  107.  
  108. return $wpdb->get_var( "SELECT COUNT(post_id) FROM {$wpdb->ps_product_sku} " ); 
  109.  
  110. /** 
  111. * Get Total Items Need to Sync 
  112. */ 
  113. public function get_total_items_need_sync() { 
  114. global $wpdb; 
  115.  
  116. //return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(p.ID) FROM {$wpdb->posts} AS p INNER JOIN {$wpdb->postmeta} AS pm ON (p.ID=pm.post_id) WHERE p.post_type IN ('". implode("', '", array( 'product' ) ) ."') AND p.post_status = %s AND pm.meta_key = %s AND pm.meta_value NOT LIKE '' ", 'publish', '_sku' ) ); 
  117. return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(p.ID) FROM {$wpdb->posts} AS p WHERE p.post_type IN ('". implode("', '", array( 'product' ) ) ."') AND p.post_status = %s ", 'publish' ) ); 
  118.  
  119. /** 
  120. * Delete Predictive Search Product SKU 
  121. */ 
  122. public function delete_item( $post_id ) { 
  123. global $wpdb; 
  124. return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->ps_product_sku} WHERE post_id = %d ", $post_id ) ); 
  125.  
  126. /** 
  127. * Empty Predictive Search Product SKU 
  128. */ 
  129. public function empty_table() { 
  130. global $wpdb; 
  131. return $wpdb->query( "TRUNCATE {$wpdb->ps_product_sku}" );