PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-shopping-cart/shipwire_functions.php

https://github.com/alx/barceloneta
PHP | 188 lines | 168 code | 14 blank | 6 comment | 70 complexity | 0d7937d09e7459d346163a767b90c468 MD5 | raw file
  1. <?php
  2. function shipwire_build_xml($log_id) {
  3. global $wpdb;
  4. $email = get_option("shipwireemail");
  5. $passwd = get_option("shipwirepassword");
  6. $server = "Production"; // or "Production"
  7. $warehouse = "00";
  8. $form_info = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."collect_data_forms", ARRAY_A);
  9. foreach ($form_info as $info) {
  10. if(($info['type'] == 'delivery_address') && ($info['active']=='1')) {
  11. $delivery_address=true;
  12. } else if(($info['type'] == 'delivery_city') && ($info['active']=='1')) {
  13. $delivery_city=true;
  14. } else if(($info['type'] == 'delivery_state') && ($info['active']=='1')) {
  15. $delivery_state=true;
  16. } else if(($info['type'] == 'delivery_country') && ($info['active']=='1')) {
  17. $delivery_country=true;
  18. }
  19. }
  20. foreach ($form_info as $info) {
  21. //echo "<pre>".print_r(array_flip($form_info),1)."</pre>";
  22. // exit (print_r(!array_search('delivery_address',$info),1));
  23. if ((($info['type'] == 'delivery_address') && ($info['active']=='1')) || (!$delivery_address && ($info['type'] == 'address') && ($info['active']=='1'))) {
  24. $address_key = $info['id'];
  25. } else if((($info['type'] == 'delivery_city') && ($info['active']=='1')) || (!$delivery_city && ($info['type'] == 'city') && ($info['active']=='1'))) {
  26. $city_key = $info['id'];
  27. } else if((($info['type'] == 'delivery_state') && ($info['active']=='1')) || (!$delivery_state && ($info['type'] == 'state') && ($info['active']=='1'))) {
  28. $state_key = $info['id'];
  29. } else if((($info['type'] == 'delivery_country') && ($info['active']=='1')) || (!$delivery_country && ($info['type'] == 'country') && ($info['active']=='1'))) {
  30. $country_key = $info['id'];
  31. } else if(($info['type'] == 'delivery_first_name') && ($info['active']=='1')) {
  32. $first_name_key = $info['id'];
  33. } else if(($info['type'] == 'delivery_last_name') && ($info['active']=='1')) {
  34. $last_name_key = $info['id'];
  35. }
  36. }
  37. $user_infos = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."submited_form_data WHERE log_id='".$log_id."'", ARRAY_A);
  38. //echo (print_r($user_infos,1));
  39. foreach ($user_infos as $user_info) {
  40. if ($user_info['form_id'] == $address_key) {
  41. //exit ($user_info['form_id']." ".$address_key);
  42. $address = $user_info['value'];
  43. }
  44. if ($user_info['form_id'] == $city_key) {
  45. $city = $user_info['value'];
  46. }
  47. if ($user_info['form_id'] == $state_key) {
  48. $state = $user_info['value'];
  49. }
  50. if ($user_info['form_id'] == $country_key) {
  51. $country = $user_info['value'];
  52. }
  53. if ($user_info['form_id'] == $first_name_key) {
  54. $first_name = $user_info['value'];
  55. }
  56. if ($user_info['form_id'] == $last_name_key) {
  57. $last_name = $user_info['value'];
  58. }
  59. }
  60. if (($first_name_key == '') || ($last_name_key == '')) {
  61. $log_info = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."purchase_logs WHERE id='".$log_id."'");
  62. $first_name = $log_info[0]['firstname'];
  63. $last_name = $log_info[0]['lastname'];
  64. }
  65. $full_name = $first_name." ".$last_name;
  66. $products = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."cart_contents WHERE purchaseid='".$log_id."'",ARRAY_A);
  67. //return $log_id;
  68. $xml = "<?xml version='1.0' encoding='utf-8'?>";
  69. $xml .= "<OrderList>";
  70. $xml .= "<EmailAddress>$email</EmailAddress>";
  71. $xml .= "<Password>$passwd</Password>";
  72. $xml .= "<Server>$server</Server>";
  73. $xml .= "<Referer>$server</Referer>";
  74. $xml .= "<Warehouse>$warehouse</Warehouse>";
  75. $xml .= "<Order id='".$log_id."'>";
  76. $xml .= "<AddressInfo type='ship'>";
  77. $xml .= "<Name>";
  78. $xml .= "<Full>".$full_name."</Full>";
  79. $xml .= "</Name>";
  80. $xml .= "<Address1>".$address."</Address1>";
  81. $xml .= "<Address2></Address2>";
  82. $xml .= "<City>".$city."</City>";
  83. $xml .= "<State>".$state."</State>";
  84. $xml .= "<Country>".$country."</Country>";
  85. $xml .= "<Zip>"."5011"."</Zip>";
  86. $xml .= "<Phone>"."3030303030"."</Phone>";
  87. $xml .= "<Email>"."hanzhimeng@gmail.com"."</Email>";
  88. $xml .= "</AddressInfo>";
  89. $xml .= "<Shipping>UPS Ground</Shipping>";//to be changed.
  90. //$xml
  91. foreach($products as $product) {
  92. $xml .= "<Item num='0'>";
  93. $xml .="<Code>"."Book1"."</Code>";
  94. $xml .= "<Quantity>".$product['quantity']."</Quantity>";
  95. $xml .= "<Description>Austin Powers World Ransom</Description>";
  96. $xml .= "<Length>3</Length>";
  97. $xml .= "<Width>1</Width>";
  98. $xml .= "<Height>1</Height>";
  99. $xml .= "<Weight>1</Weight>";
  100. $xml .= "<DeclaredValue>".$product['price']."</DeclaredValue>";
  101. $xml .= "</Item>";
  102. }
  103. $xml .="</Order>";
  104. $xml .="</OrderList>";
  105. return $xml;
  106. }
  107. function shipwire_built_sync_xml() {
  108. global $wpdb;
  109. $email = get_option("shipwireemail");
  110. $passwd = get_option("shipwirepassword");
  111. $server = "Production"; // or "Production"
  112. $warehouse = "00";
  113. $xml = "<?xml version='1.0' encoding='utf-8'?>";
  114. $xml .= "<InventoryUpdate>";
  115. $xml .= "<EmailAddress>".$email."</EmailAddress>";
  116. $xml .= "<Password>".$passwd."</Password>";
  117. $xml .= "<Server>".$server."</Server>";
  118. $xml .= "<Warehouse></Warehouse>";
  119. $xml .= "<ProductCode></ProductCode>";
  120. $xml .= "</InventoryUpdate>";
  121. return $xml;
  122. }
  123. function shipwire_built_tracking_xml() {
  124. global $wpdb;
  125. $email = get_option("shipwireemail");
  126. $passwd = get_option("shipwirepassword");
  127. $server = "Production";
  128. $warehouse = "00";
  129. $xml = "<?xml version='1.0' encoding='utf-8'?>";
  130. $xml .= "<TrackingUpdate>";
  131. $xml .= "<EmailAddress>".$email."</EmailAddress>";
  132. $xml .= "<Password>".$passwd."</Password>";
  133. $xml .= "<Server>".$server."</Server>";
  134. $xml .= "<Bookmark>1</Bookmark>";
  135. $xml .= "</TrackingUpdate>";
  136. return $xml;
  137. }
  138. function shipwire_send_sync_request($xml) {
  139. $OrderList = urlencode($xml);
  140. $shipwire_ch = curl_init("https://www.shipwire.com/exec/InventoryServices.php");
  141. curl_setopt ($shipwire_ch, CURLOPT_POST, 1);
  142. curl_setopt ($shipwire_ch, CURLOPT_HTTPHEADER, array('Accept: application/xml', "Content-type:application/x-www-form-urlencoded"));
  143. curl_setopt ($shipwire_ch, CURLOPT_POSTFIELDS, "InventoryUpdateXML=".$OrderList);
  144. ob_start();
  145. curl_exec($shipwire_ch);
  146. $orderSubmitted = ob_get_contents();
  147. ob_end_clean();
  148. return $orderSubmitted;
  149. }
  150. function shipwire_sent_request($xml) {
  151. $OrderList = urlencode($xml);
  152. $shipwire_ch = curl_init("https://www.shipwire.com/exec/FulfillmentServices.php");
  153. curl_setopt ($shipwire_ch, CURLOPT_POST, 1);
  154. curl_setopt ($shipwire_ch, CURLOPT_HTTPHEADER, "Content-type:"."application/x-www-form-urlencoded");
  155. curl_setopt ($shipwire_ch, CURLOPT_POSTFIELDS, "InventoryUpdateXML=".$OrderList);
  156. ob_start();
  157. curl_exec($shipwire_ch);
  158. $orderSubmitted = ob_get_contents();
  159. ob_end_clean();
  160. return $orderSubmitted;
  161. }
  162. function shipwire_send_tracking_request($xml) {
  163. $OrderList = urlencode($xml);
  164. $shipwire_ch = curl_init("https://www.shipwire.com/exec/TrackingServices.php");
  165. curl_setopt ($shipwire_ch, CURLOPT_POST, 1);
  166. curl_setopt ($shipwire_ch, CURLOPT_HTTPHEADER, "Content-type:"."application/x-www-form-urlencoded");
  167. curl_setopt ($shipwire_ch, CURLOPT_POSTFIELDS, "InventoryUpdateXML=".$OrderList);
  168. ob_start();
  169. curl_exec($shipwire_ch);
  170. $orderSubmitted = ob_get_contents();
  171. ob_end_clean();
  172. return $orderSubmitted;
  173. }
  174. ?>