renaud2263 Posted January 11, 2018 Share Posted January 11, 2018 (edited) Hi everybody, As said in the title, I want to create an order via webservice. These orders must be free at 0 € because they are exchange devices (after sale service). After looking for tutos and posts, I done : $id_product = 100; $product_name = "Test"; $quantity = '1'; $id_address = '6753'; $id_customer = '25717'; $id_carrier = '14'; $date_now = date('Y-m-d'); $order_payment = 'gratuit'; $id_status = '4'; $order_module = 'gratuit'; try { $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); if(!$id_cart){ // Getting the empty XML document to send back completed $xml = $webService->get( array( 'url' => PS_SHOP_PATH .'api/carts?schema=blank' ) ); // Adding dinamic and mandatory fields // Required $xml->cart->id_currency = $id_currency; $xml->cart->id_lang = $id_lang; $xml->cart->associations->cart_rows->cart_row[0]->id_product = $id_product; $xml->cart->associations->cart_rows->cart_row[0]->id_product_attribute = '0'; $xml->cart->associations->cart_rows->cart_row[0]->id_address_delivery = $id_address; $xml->cart->associations->cart_rows->cart_row[0]->quantity = $quantity; // Others $xml->cart->id_address_delivery = $id_address; $xml->cart->id_address_invoice = $id_address; $xml->cart->id_customer = $id_customer; $xml->cart->id_carrier = $id_carrier; $xml->cart->date_add = $date_now; $xml->cart->date_upd = $date_now; // Adding the new customer's cart $opt = array( 'resource' => 'carts' ); $opt['postXml'] = $xml->asXML(); $xml = $webService->add( $opt ); $id_cart = $xml->cart->id; } /* * 4. Create the order * */ // Getting the structure of an order $xml = $webService->get(array('url' => PS_SHOP_PATH .'api/orders/?schema=blank')); // Adding dinamic and required fields // Required $xml->order->id_address_delivery = $id_address; // Customer address $xml->order->id_address_invoice = $id_address; $xml->order->id_cart = $id_cart; $xml->order->id_currency = $id_currency; $xml->order->id_lang = $id_lang; $xml->order->id_customer = $id_customer; $xml->order->id_carrier = $id_carrier; $xml->order->module = $order_module; $xml->order->payment = $order_payment; $xml->order->total_paid = '0'; $xml->order->total_paid_real = '0'; $xml->order->total_products = '0'; $xml->order->total_products_wt = '0'; $xml->order->conversion_rate = '1'; // Others $xml->order->valid = '0'; $xml->order->current_state = $id_status; $xml->order->total_discounts = '0'; $xml->order->total_discounts_tax_incl = '0'; $xml->order->total_discounts_tax_excl = '0'; $xml->order->shipping_cost_tax_excl = '0'; $xml->order->shipping_cost_tax_incl = '0'; $xml->order->total_paid_tax_incl = '0'; $xml->order->total_paid_tax_excl = '0'; $xml->order->total_shipping = '0'; $xml->order->total_shipping_tax_incl = '0'; $xml->order->total_shipping_tax_excl = '0'; // Order Row. Required $xml->order->associations->order_rows->order_row[0]->product_id = $id_product; $xml->order->associations->order_rows->order_row[0]->product_attribute_id = '0'; $xml->order->associations->order_rows->order_row[0]->product_quantity = $quantity; // Order Row. Others $xml->order->associations->order_rows->order_row[0]->product_name = $product_name; $xml->order->associations->order_rows->order_row[0]->product_reference = $id_product; $xml->order->associations->order_rows->order_row[0]->product_price = '0'; $xml->order->associations->order_rows->order_row[0]->unit_price_tax_incl = '0'; $xml->order->associations->order_rows->order_row[0]->unit_price_tax_excl = '0'; // Creating the order $opt = array( 'resource' => 'orders' ); $opt['postXml'] = $xml->asXML(); $xml = $webService->add( $opt ); $id_order = $xml->order->id; } catch (PrestaShopWebserviceException $e) { // Here we are dealing with errors $trace = $e->getTrace(); if ($trace[0]['args'][0] == 404) echo 'Bad ID'; else if ($trace[0]['args'][0] == 401) echo 'Bad auth key'; else echo 'Other error<br />'.$e->getMessage(); } Then the new order is created but the parameters are not as the parameters sent. The carrier is not the 14 as I asked, then the freight cost is added (but I want a total free order). The freight cost is also added in the order_payment table even if, in my script, all the prices are set to 0. The current state is not correct. Not "4" as the $id_status. The order history also wrong (that means my free payment module is ignored). Note: in this code, the "valid" param is set to 0, but even with 1 is same result. Could you help me to create an order with the parameters I send ? Thanks a lot. Edited January 11, 2018 by renaud2263 (see edit history) Link to comment Share on other sites More sharing options...
Puskas Posted October 23, 2018 Share Posted October 23, 2018 +1 for this one, anyone can help? I am sorting a similar problem Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now