/WEBCRUD/controleur/R-CRUD_import_partie_order.php

https://gitlab.com/ptisky/API_prestashop · PHP · 242 lines · 61 code · 31 blank · 150 comment · 6 complexity · 911415a8de0ee8d5a7e00b291e0d133c MD5 · raw file

  1. <?php
  2. try{
  3. $bdd = new PDO('mysql:host=localhost;dbname=prestashop;charset=utf8', 'root', '');
  4. }
  5. catch (Exception $e)
  6. {
  7. die('Erreur : ' . $e->getMessage());
  8. }
  9. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. // ///////
  11. //-----------------------------------------------------------// PARTIE PRESTASHOP //-----------------------------------------------------------///////
  12. // ///////
  13. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  14. //connection de l'api au webservice
  15. include("connection.php");
  16. //on recupere le fichier xml
  17. $get_xml_orders = simplexml_load_file("orders.xml");
  18. $get_xml_carts = simplexml_load_file("carts.xml");
  19. //-----------------------------------------------// CUSTOMER //---------------------------------//
  20. foreach ($get_xml_orders->children()->children() as $ressources_cart)
  21. {
  22. try {
  23. $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); //connection
  24. $xml_cart = $webService->get(array('url' => PS_SHOP_PATH.'/api/carts?schema=synopsis'));//on recupere un shemas blanc xml
  25. $opt_customers['resource'] = 'customers';
  26. $xml_customers = $webService->get($opt_customers);
  27. $resources_customer_id = $xml_customers->children()->children()->id;
  28. $opt_addresses['resource'] = 'addresses';
  29. $xml_address = $webService->get($opt_addresses);
  30. $resources_address_id = $xml_address->children()->children()->id;
  31. $opt_currencies['resource'] = 'currencies';
  32. $xml_currency = $webService->get($opt_currencies);
  33. $resources_currency_id = $xml_currency->children()->children()->id;
  34. $opt_languages['resource'] = 'languages';
  35. $xml_lang = $webService->get($opt_languages);
  36. $resources_lang_id = $xml_lang->children()->children()->id;
  37. $opt_carriers['resource'] = 'carriers';
  38. $xml_carrier = $webService->get($opt_carriers);
  39. $resources_carrier_id = $xml_carrier->children()->children()->id;
  40. $opt_products['resource'] = 'products';
  41. $xml_product = $webService->get($opt_products);
  42. $resources_product_id = $xml_product->children()->children()->id;
  43. $resources_product_quantity = $xml_product->children()->children()->quantity;
  44. while($xml_customers->children()->children()->outstanding_allow_amount > 0)
  45. {
  46. $xml_cart->cart->id_customer = $resources_customer_id;
  47. $xml_cart->cart->id_address_delivery = $resources_address_id;
  48. $xml_cart->cart->id_address_invoice = $resources_address_id;
  49. $xml_cart->cart->id_currency = $resources_currency_id;
  50. $xml_cart->cart->id_lang = $resources_lang_id;
  51. $xml_cart->cart->id_carrier = $resources_carrier_id;
  52. $xml_cart->cart->associations->cart_rows->cart_row->id_product = $resources_product_id;
  53. $xml_cart->cart->associations->cart_rows->cart_row->quantity = $resources_product_quantity;
  54. $opt_orders = array('resource' => 'carts');
  55. $opt_orders['postXml'] = $xml_cart->asXML();
  56. // var_dump($opt);
  57. //envoie le xml a prestashop
  58. $xml_orders = $webService->add($opt_orders);
  59. $monid_orders = $xml_orders->customer->id;//récupere l'id inséré dans prestashop par auto increment
  60. $bdd->query('UPDATE `prestashop`.`ps_order` SET `id_order` = '.$id_orders.' WHERE `ps_order`.`id_order` = '.$monid_orders.'');//envoie la nouvelle id
  61. }
  62. }
  63. catch (PrestaShopWebserviceException $e)
  64. {
  65. // Here we are dealing with errors
  66. $trace = $e->getTrace();
  67. if ($trace[0]['args'][0] == 404) echo 'Bad ID';
  68. else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
  69. else echo 'Other error<br />'.$e->getMessage();
  70. }
  71. }
  72. // foreach ($get_xml_orders->children()->children() as $ressources_orders)
  73. // {
  74. // try {
  75. // $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); //connection
  76. // $xml_orders = $webService->get(array('url' => PS_SHOP_PATH.'/api/orders?schema=synopsis'));//on recupere un shemas blanc xml
  77. // données obligatoires dans mon xml
  78. // $id_orders = $ressources_orders->id;
  79. // $id_address_delivery_orders = $ressources_orders->id_address_delivery;
  80. // $id_address_invoice_orders = $ressources_orders->id_address_invoice;
  81. // $id_cart_orders = $ressources_orders->id_cart;
  82. // $id_currency_orders = $ressources_orders->id_currency;
  83. // $id_lang_orders = $ressources_orders->id_lang;
  84. // $id_customer_orders = $ressources_orders->id_customer;
  85. // $id_carrier_orders = $ressources_orders->id_carrier;
  86. // $current_state_orders = $ressources_orders->current_state;
  87. // $module_orders = $ressources_orders->module;
  88. // $invoice_number_orders = $ressources_orders->invoice_number;
  89. // $invoice_date_orders = $ressources_orders->invoice_date;
  90. // $delivery_number_orders = $ressources_orders->delivery_number;
  91. // $delivery_date_orders = $ressources_orders->delivery_date;
  92. // $valid_orders = $ressources_orders->valid;
  93. // $date_add_orders = $ressources_orders->date_add;
  94. // $date_upd_orders = $ressources_orders->date_upd;
  95. // $shipping_number_orders = $ressources_orders->shipping_number;
  96. // $id_shop_group_orders = $ressources_orders->id_shop_group;
  97. // $id_shop_orders = $ressources_orders->id_shop;
  98. // $secure_key_orders = $ressources_orders->secure_key;
  99. // $payment_orders = $ressources_orders->payment;
  100. // $recyclable_orders = $ressources_orders->recyclable;
  101. // $gift_orders = $ressources_orders->gift;
  102. // $gift_message_orders = $ressources_orders->gift_message;
  103. // $mobile_theme_orders = $ressources_orders->mobile_theme;
  104. // $total_discounts_orders = $ressources_orders->total_discounts;
  105. // $total_discounts_tax_incl_orders = $ressources_orders->total_discounts_tax_incl;
  106. // $total_discounts_tax_excl_orders = $ressources_orders->total_discounts_tax_excl;
  107. // $total_paid_orders = $ressources_orders->total_paid;
  108. // $total_paid_tax_incl_orders = $ressources_orders->total_paid_tax_incl;
  109. // $total_paid_tax_excl_orders = $ressources_orders->total_paid_tax_excl;
  110. // $total_paid_real_orders = $ressources_orders->total_paid_real;
  111. // $total_products_orders = $ressources_orders->total_products;
  112. // $total_products_wt_orders = $ressources_orders->total_products_wt;
  113. // $total_shipping_orders = $ressources_orders->total_shipping;
  114. // $total_shipping_tax_incl_orders = $ressources_orders->total_shipping_tax_incl;
  115. // $total_shipping_tax_excl_orders = $ressources_orders->total_shipping_tax_excl;
  116. // $carrier_tax_rate_orders = $ressources_orders->carrier_tax_rate;
  117. // $total_wrapping_orders = $ressources_orders->total_wrapping;
  118. // $total_wrapping_tax_incl_orders = $ressources_orders->total_wrapping_tax_incl;
  119. // $total_wrapping_tax_excl_orders = $ressources_orders->total_wrapping_tax_excl;
  120. // $round_mode_orders = $ressources_orders->round_mode;
  121. // $round_type_orders = $ressources_orders->round_type;
  122. // $conversion_rate_orders = $ressources_orders->conversion_rate;
  123. // $reference_orders = $ressources_orders->reference;
  124. // $xml_orders->order->id_address_delivery = $id_address_delivery_orders;
  125. // $xml_orders->order->id_address_invoice = $id_address_invoice_orders;
  126. // $xml_orders->order->id_cart = $id_cart_orders;
  127. // $xml_orders->order->id_currency = $id_currency_orders;
  128. // $xml_orders->order->id_lang = $id_lang_orders;
  129. // $xml_orders->order->id_customer = $id_customer_orders;
  130. // $xml_orders->order->id_carrier = $id_carrier_orders;
  131. // $xml_orders->order->current_state = $current_state_orders;
  132. // $xml_orders->order->module = $module_orders;
  133. // $xml_orders->order->invoice_number = $invoice_number_orders;
  134. // $xml_orders->order->invoice_date = $invoice_date_orders;
  135. // $xml_orders->order->delivery_number = $delivery_number_orders;
  136. // $xml_orders->order->delivery_date = $delivery_date_orders;
  137. // $xml_orders->order->valid = $valid_orders;
  138. // $xml_orders->order->date_add = $date_add_orders;
  139. // $xml_orders->order->date_upd = $date_upd_orders;
  140. // $xml_orders->order->shipping_number = $shipping_number_orders;
  141. // $xml_orders->order->id_shop_group = $id_shop_group_orders;
  142. // $xml_orders->order->id_shop = $id_shop_orders;
  143. // $xml_orders->order->secure_key = $secure_key_orders;
  144. // $xml_orders->order->payment = $payment_orders;
  145. // $xml_orders->order->recyclable = $recyclable_orders;
  146. // $xml_orders->order->gift = $gift_orders;
  147. // $xml_orders->order->gift_message = $gift_message_orders;
  148. // $xml_orders->order->mobile_theme = $mobile_theme_orders;
  149. // $xml_orders->order->total_discounts = $total_discounts_orders;
  150. // $xml_orders->order->total_discounts_tax_incl = $total_discounts_tax_incl_orders;
  151. // $xml_orders->order->total_discounts_tax_excl = $total_discounts_tax_excl_orders;
  152. // $xml_orders->order->total_paid = $total_paid_orders;
  153. // $xml_orders->order->total_paid_tax_incl = $total_paid_tax_incl_orders;
  154. // $xml_orders->order->total_paid_tax_excl = $total_paid_tax_excl_orders;
  155. // $xml_orders->order->total_paid_real = $total_paid_real_orders;
  156. // $xml_orders->order->total_products = $total_products_orders;
  157. // $xml_orders->order->total_products_wt = $total_products_wt_orders;
  158. // $xml_orders->order->total_shipping = $total_shipping_orders;
  159. // $xml_orders->order->total_shipping_tax_incl = $total_shipping_tax_incl_orders;
  160. // $xml_orders->order->total_shipping_tax_excl = $total_shipping_tax_excl_orders;
  161. // $xml_orders->order->carrier_tax_rate = $carrier_tax_rate_orders;
  162. // $xml_orders->order->total_wrapping = $total_wrapping_orders;
  163. // $xml_orders->order->total_wrapping_tax_incl = $total_wrapping_tax_incl_orders;
  164. // $xml_orders->order->total_wrapping_tax_excl = $total_wrapping_tax_excl_orders;
  165. // $xml_orders->order->round_mode = $round_mode_orders;
  166. // $xml_orders->order->round_type = $round_type_orders;
  167. // $xml_orders->order->conversion_rate = $conversion_rate_orders;
  168. // $xml_orders->order->reference = $reference_orders;
  169. // foreach ($ressources_orders->associations->order_rows->children() as $ressources_orders_assos)
  170. // {
  171. // $id_assos_orders = $ressources_orders_assos->id;
  172. // $product_id_assos_orders = $ressources_orders_assos->product_id;
  173. // $product_attribute_id_assos_orders = $ressources_orders_assos->product_attribute_id;
  174. // $product_quantity_assos_orders = $ressources_orders_assos->product_quantity;
  175. // $product_name_assos_orders = $ressources_orders_assos->product_name;
  176. // $product_reference_assos_orders = $ressources_orders_assos->product_reference;
  177. // $product_ean13_assos_orders = $ressources_orders_assos->product_ean13;
  178. // $product_upc_assos_orders = $ressources_orders_assos->product_upc;
  179. // $product_price_assos_orders = $ressources_orders_assos->product_price;
  180. // $unit_price_tax_incl_assos_orders = $ressources_orders_assos->unit_price_tax_incl;
  181. // $unit_price_tax_excl_assos_orders = $ressources_orders_assos->unit_price_tax_excl;
  182. // $xml_orders->order->associations->order_rows->order_row->id = $id_assos_orders;
  183. // $xml_orders->order->associations->order_rows->order_row->product_id = $product_id_assos_orders;
  184. // $xml_orders->order->associations->order_rows->order_row->product_attribute_id = $product_attribute_id_assos_orders;
  185. // $xml_orders->order->associations->order_rows->order_row->product_quantity = $product_quantity_assos_orders;
  186. // $xml_orders->order->associations->order_rows->order_row->product_name = $product_name_assos_orders;
  187. // $xml_orders->order->associations->order_rows->order_row->product_reference = $product_reference_assos_orders;
  188. // $xml_orders->order->associations->order_rows->order_row->product_ean13 = $product_ean13_assos_orders;
  189. // $xml_orders->order->associations->order_rows->order_row->product_upc = $product_upc_assos_orders;
  190. // $xml_orders->order->associations->order_rows->order_row->product_price = $product_price_assos_orders;
  191. // $xml_orders->order->associations->order_rows->order_row->unit_price_tax_incl = $unit_price_tax_incl_assos_orders;
  192. // $xml_orders->order->associations->order_rows->order_row->unit_price_tax_excl = $unit_price_tax_excl_assos_orders;
  193. // }
  194. // $opt_orders = array('resource' => 'orders');
  195. // $opt_orders['postXml'] = $xml_orders->asXML();
  196. // var_dump($opt);
  197. // envoie le xml a prestashop
  198. // $xml_orders = $webService->add($opt_orders);
  199. // $monid_orders = $xml_orders->customer->id;//récupere l'id inséré dans prestashop par auto increment
  200. // $bdd->query('UPDATE `prestashop`.`ps_order` SET `id_order` = '.$id_orders.' WHERE `ps_order`.`id_order` = '.$monid_orders.'');//envoie la nouvelle id
  201. // }
  202. // catch (PrestaShopWebserviceException $e)
  203. // {
  204. // Here we are dealing with errors
  205. // $trace = $e->getTrace();
  206. // if ($trace[0]['args'][0] == 404) echo 'Bad ID';
  207. // else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
  208. // else echo 'Other error<br />'.$e->getMessage();
  209. // }
  210. // }
  211. ?>