Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. function post_integration($arr, $array) {
  2.  
  3. global $wpdb;
  4.  
  5. $cat = $array['category'];
  6. $manufacturer = $array['manufacturer'];
  7. $return_status = $array['return_status'];
  8. $markup = $array['markup'];
  9.  
  10.  
  11. for ( $i = 1, $j=0; $i < count($arr); $i++, $j++ )
  12. {
  13.  
  14. set_time_limit(0);
  15. $vendor_code = ( iconv ("CP1251", "UTF-8", $arr[$i][0]) );
  16. $vendor_code = substr($vendor_code, 1);
  17. $product_name = ( iconv ("CP1251", "UTF-8", $arr[$i][1]) );
  18. $price = ( iconv ("CP1251", "UTF-8", $arr[$i][2]) );
  19. $rabat_group = ( iconv ("CP1251", "UTF-8", $arr[$i][3]) );
  20. $product_desc = ( iconv ("CP1251", "UTF-8", $arr[$i][4]) );
  21. $mortgage_value = ( iconv ("CP1251", "UTF-8", $arr[$i][5]) );
  22. $netto_weight = ( iconv ("CP1251", "UTF-8", $arr[$i][6]) );
  23. $netto_weight = substr($netto_weight, 0, -1);
  24.  
  25. $price = str_replace(",",".",$price);
  26.  
  27. $this_price = ( ($markup / 100) * $price) + $price;
  28. $end_price = round($this_price, 2);
  29.  
  30.  
  31. $query="SELECT vendor_code.meta_value AS "vendor_code", p.ID AS "ID" FROM wp_posts p
  32. JOIN wp_postmeta vendor_code ON p.ID = vendor_code.post_id AND vendor_code.meta_key = 'vendor_code'
  33. WHERE post_status = 'publish' AND post_type = 'post' AND vendor_code.meta_value = $vendor_code";
  34.  
  35. $rabrt_id_query = "SELECT id FROM `wp_rabat_list` WHERE name_rabat = '$manufacturer'";
  36.  
  37. $result_data = $wpdb->get_results($query);
  38. $rabat_data = $wpdb->get_results($rabrt_id_query);
  39.  
  40. $rabat_id = $rabat_data[0]->id;
  41. $result_id = $result_data[0]->ID;
  42. $result_vendor = $result_data[0]->vendor_code;
  43.  
  44. if(isset($result_vendor)) {
  45.  
  46. $my_post = array();
  47. $my_post['ID'] = intval($result_id);
  48. $my_post['post_title'] = wp_strip_all_tags($product_name);
  49. $my_post['post_content'] = $product_desc;
  50. $my_post['post_category'] = array($cat);
  51.  
  52. wp_update_post($my_post);
  53.  
  54. update_post_meta($my_post['ID'], 'vendor_code', $vendor_code);
  55. update_post_meta($my_post['ID'], 'price', $end_price);
  56. update_post_meta($my_post['ID'], 'manufacturer', $manufacturer);
  57. update_post_meta($my_post['ID'], 'mortgage_value', $mortgage_value);
  58. update_post_meta($my_post['ID'], 'netto_weight', $netto_weight);
  59. // update_post_meta($my_post['ID'], 'availability', $article);
  60. update_post_meta($my_post['ID'], 'return_goods', $return_status);
  61. update_post_meta($my_post['ID'], 'discount_group_id', $rabat_id);
  62. update_post_meta($my_post['ID'], 'mark_up', $markup);
  63.  
  64. }
  65. else
  66. {
  67. $post_data = array(
  68. 'post_title' => wp_strip_all_tags( $product_name ),
  69. 'post_content' => $product_desc,
  70. 'post_status' => 'publish',
  71. 'post_author' => 1,
  72. 'post_category' => array($cat)
  73. );
  74. //Вставляем запись в базу данных
  75. $post_id = wp_insert_post( $post_data );
  76.  
  77. add_post_meta($post_id, 'vendor_code', $vendor_code);
  78. add_post_meta($post_id, 'price', $end_price);
  79. add_post_meta($post_id, 'manufacturer', $manufacturer);
  80. add_post_meta($post_id, 'mortgage_value', $mortgage_value);
  81. add_post_meta($post_id, 'netto_weight', $netto_weight);
  82. // add_post_meta($post_id, 'availability', $article);
  83. add_post_meta($post_id, 'return_goods', $return_status);
  84. add_post_meta($post_id, 'discount_group_id', $rabat_id);
  85. update_post_meta($my_post['ID'], 'mark_up', $markup);
  86.  
  87. }
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement